# Path: performanceplatform/collector/ga/lib/helper.py
# def create_client(credentials):
#     if "CLIENT_SECRETS" in credentials and "STORAGE_PATH" in credentials:
#         return from_secrets_file(
#             credentials['CLIENT_SECRETS'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     elif "ACCOUNT_NAME" in credentials:
#         return from_private_key(
#             credentials['ACCOUNT_NAME'],
#             private_key_path=credentials['PRIVATE_KEY'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     else:
#         return from_credentials_db(
#             credentials['CLIENT_SECRETS']['installed'],
#             credentials['OAUTH2_CREDENTIALS'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )


from mock import Mock, patch, ANY
from performanceplatform.collector.ga.lib.helper import create_client
# encoding: utf-8



@patch("performanceplatform.collector.ga.lib.helper.from_credentials_db")
def test_create_client_handles_oauth2_credentials(mock_from_credentials_db):
    credentials = {
        "CLIENT_SECRETS": {
            "installed": {
                "auth_uri": "accounts.foo.com/o/oauth2/auth",
                "client_secret": "a client secret",
                "token_uri": "accounts.foo.com/o/oauth2/token",
                "client_email": "",
                "redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "oob"],
                "client_x509_cert_url": "",
                "client_id": "a client id",
                "auth_provider_x509_cert_url": "foo.com/oauth2/certs"
            },
        },
        "OAUTH2_CREDENTIALS": Mock()
    }
    client_secrets = credentials.get("CLIENT_SECRETS")["installed"]
    mock_storage_object = credentials.get("OAUTH2_CREDENTIALS")

# Path: performanceplatform/collector/ga/lib/helper.py
# def create_client(credentials):
#     if "CLIENT_SECRETS" in credentials and "STORAGE_PATH" in credentials:
#         return from_secrets_file(
#             credentials['CLIENT_SECRETS'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     elif "ACCOUNT_NAME" in credentials:
#         return from_private_key(
#             credentials['ACCOUNT_NAME'],
#             private_key_path=credentials['PRIVATE_KEY'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     else:
#         return from_credentials_db(
#             credentials['CLIENT_SECRETS']['installed'],
#             credentials['OAUTH2_CREDENTIALS'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )


# Path: tests/performanceplatform/collector/ga/lib/test_helper.py
from mock import Mock, patch, ANY
from performanceplatform.collector.ga.lib.helper import create_client

# encoding: utf-8



@patch("performanceplatform.collector.ga.lib.helper.from_credentials_db")
def test_create_client_handles_oauth2_credentials(mock_from_credentials_db):
    credentials = {
        "CLIENT_SECRETS": {
            "installed": {
                "auth_uri": "accounts.foo.com/o/oauth2/auth",
                "client_secret": "a client secret",
                "token_uri": "accounts.foo.com/o/oauth2/token",
                "client_email": "",
                "redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "oob"],
                "client_x509_cert_url": "",
                "client_id": "a client id",
                "auth_provider_x509_cert_url": "foo.com/oauth2/certs"
            },
        },
        "OAUTH2_CREDENTIALS": Mock()
    }
    client_secrets = credentials.get("CLIENT_SECRETS")["installed"]
    mock_storage_object = credentials.get("OAUTH2_CREDENTIALS")

    create_client(credentials)