# Path: firebase_admin/credentials.py
# class Base:
# class Certificate(Base):
# class ApplicationDefault(Base):
# class RefreshToken(Base):
#     def get_access_token(self):
#     def get_credential(self):
#     def __init__(self, cert):
#     def project_id(self):
#     def signer(self):
#     def service_account_email(self):
#     def get_credential(self):
#     def __init__(self):
#     def get_credential(self):
#     def project_id(self):
#     def _load_credential(self):
#     def __init__(self, refresh_token):
#     def client_id(self):
#     def client_secret(self):
#     def refresh_token(self):
#     def get_credential(self):
# def _is_file_path(path):
#     _CREDENTIAL_TYPE = 'service_account'
#     _CREDENTIAL_TYPE = 'authorized_user'
# 
# Path: tests/testutils.py
# def resource_filename(filename):
# def resource(filename):
# def cleanup_apps():
# def run_without_project_id(func):
# def new_monkeypatch():
#     def __init__(self, status, response):
#     def status(self):
#     def headers(self):
#     def data(self):
#     def __init__(self, status, response):
#     def __call__(self, *args, **kwargs): # pylint: disable=arguments-differ
#     def __init__(self, error):
#     def __call__(self, *args, **kwargs): # pylint: disable=arguments-differ
#     def refresh(self, request):
#     def __init__(self):
#     def get_credential(self):
#     def __init__(self, responses, statuses, recorder):
#     def send(self, request, **kwargs): # pylint: disable=arguments-differ
#     def __init__(self, data, status, recorder):
#     def status(self):
#     def data(self):
# class MockResponse(transport.Response):
# class MockRequest(transport.Request):
# class MockFailedRequest(transport.Request):
# class MockGoogleCredential(credentials.Credentials):
# class MockCredential(firebase_admin.credentials.Base):
# class MockMultiRequestAdapter(adapters.HTTPAdapter):
# class MockAdapter(MockMultiRequestAdapter):


import datetime
import json
import os
import pathlib
import google.auth
import pytest
from google.auth import crypt
from google.auth import exceptions
from google.oauth2 import credentials as gcredentials
from google.oauth2 import service_account
from firebase_admin import credentials
from tests import testutils


class TestCertificate:

    invalid_certs = {
        'NonExistingFile': ('non_existing.json', IOError),
        'RefreskToken': ('refresh_token.json', ValueError),
        'MalformedPrivateKey': ('malformed_key.json', ValueError),
        'MissingClientId': ('no_client_email_service_account.json', ValueError),
    }

    def test_init_from_file(self):
        credential = credentials.Certificate(
            testutils.resource_filename('service_account.json'))
        self._verify_credential(credential)

    def test_init_from_path_like(self):
        path = pathlib.Path(testutils.resource_filename('service_account.json'))
        credential = credentials.Certificate(path)
        self._verify_credential(credential)


    def test_init_from_dict(self):
        parsed_json = json.loads(testutils.resource('service_account.json'))
        credential = credentials.Certificate(parsed_json)
        self._verify_credential(credential)

    @pytest.mark.parametrize('file_name,error', invalid_certs.values(), ids=list(invalid_certs))
    def test_init_from_invalid_certificate(self, file_name, error):
        with pytest.raises(error):

# Path: firebase_admin/credentials.py
# class Base:
# class Certificate(Base):
# class ApplicationDefault(Base):
# class RefreshToken(Base):
#     def get_access_token(self):
#     def get_credential(self):
#     def __init__(self, cert):
#     def project_id(self):
#     def signer(self):
#     def service_account_email(self):
#     def get_credential(self):
#     def __init__(self):
#     def get_credential(self):
#     def project_id(self):
#     def _load_credential(self):
#     def __init__(self, refresh_token):
#     def client_id(self):
#     def client_secret(self):
#     def refresh_token(self):
#     def get_credential(self):
# def _is_file_path(path):
#     _CREDENTIAL_TYPE = 'service_account'
#     _CREDENTIAL_TYPE = 'authorized_user'
# 
# Path: tests/testutils.py
# def resource_filename(filename):
# def resource(filename):
# def cleanup_apps():
# def run_without_project_id(func):
# def new_monkeypatch():
#     def __init__(self, status, response):
#     def status(self):
#     def headers(self):
#     def data(self):
#     def __init__(self, status, response):
#     def __call__(self, *args, **kwargs): # pylint: disable=arguments-differ
#     def __init__(self, error):
#     def __call__(self, *args, **kwargs): # pylint: disable=arguments-differ
#     def refresh(self, request):
#     def __init__(self):
#     def get_credential(self):
#     def __init__(self, responses, statuses, recorder):
#     def send(self, request, **kwargs): # pylint: disable=arguments-differ
#     def __init__(self, data, status, recorder):
#     def status(self):
#     def data(self):
# class MockResponse(transport.Response):
# class MockRequest(transport.Request):
# class MockFailedRequest(transport.Request):
# class MockGoogleCredential(credentials.Credentials):
# class MockCredential(firebase_admin.credentials.Base):
# class MockMultiRequestAdapter(adapters.HTTPAdapter):
# class MockAdapter(MockMultiRequestAdapter):


# Path: tests/test_credentials.py
import datetime
import json
import os
import pathlib
import google.auth
import pytest
from google.auth import crypt
from google.auth import exceptions
from google.oauth2 import credentials as gcredentials
from google.oauth2 import service_account
from firebase_admin import credentials
from tests import testutils



class TestCertificate:

    invalid_certs = {
        'NonExistingFile': ('non_existing.json', IOError),
        'RefreskToken': ('refresh_token.json', ValueError),
        'MalformedPrivateKey': ('malformed_key.json', ValueError),
        'MissingClientId': ('no_client_email_service_account.json', ValueError),
    }

    def test_init_from_file(self):
        credential = credentials.Certificate(
            testutils.resource_filename('service_account.json'))
        self._verify_credential(credential)

    def test_init_from_path_like(self):
        path = pathlib.Path(testutils.resource_filename('service_account.json'))
        credential = credentials.Certificate(path)
        self._verify_credential(credential)


    def test_init_from_dict(self):
        parsed_json = json.loads(testutils.resource('service_account.json'))
        credential = credentials.Certificate(parsed_json)
        self._verify_credential(credential)

    @pytest.mark.parametrize('file_name,error', invalid_certs.values(), ids=list(invalid_certs))
    def test_init_from_invalid_certificate(self, file_name, error):
        with pytest.raises(error):

            credentials.Certificate(testutils.resource_filename(file_name))