In my project, FirebaseAuthentication is used and while running the test cases(pipenv run python manage.py test) I am getting the following error - ValueError: Invalid certificate argument: "None". Certificate argument must be a file path, or a dict containing the parsed file contents.
authentication.py
from firebase_admin import auth
from firebase_admin import credentials
cred = credentials.Certificate(os.getenv('FIREBASE_ADMIN_KEY_PATH'))
default_app = firebase_admin.initialize_app(cred)
tests.py(where I have not imported authentication file)
from django.test import TestCase
class A(TestCase):
....
I am trying to run specific app test case but somehow it is trying to import authentication.py. That is why cred = credentials.Certificate(os.getenv('FIREBASE_ADMIN_KEY_PATH'))
is getting executed. I have identified that cred and default_app are declared at global level. And I cannot move it to other function or classes for the same file. I have noticed that cred = credentials.Certificate(os.getenv('FIREBASE_ADMIN_KEY_PATH'))
returns the object and not specific data and also calls the Firebase API for authentication. How can I mock this two line at a global level?