diff --git a/app/grants/tests/models/factories/grant_api_key_factory.py b/app/grants/tests/models/factories/grant_api_key_factory.py index d027c02d9f5..3b25607e1d1 100644 --- a/app/grants/tests/models/factories/grant_api_key_factory.py +++ b/app/grants/tests/models/factories/grant_api_key_factory.py @@ -1,9 +1,13 @@ import factory from grants.models.grant_api_key import GrantAPIKey +from .profile_factory import ProfileFactory + class GrantAPIKeyFactory(factory.django.DjangoModelFactory): """Create mock GrantAPIKey for testing.""" class Meta: - model = GrantAPIKey \ No newline at end of file + model = GrantAPIKey + + profile = factory.SubFactory(ProfileFactory) \ No newline at end of file diff --git a/app/grants/tests/models/factories/profile_factory.py b/app/grants/tests/models/factories/profile_factory.py new file mode 100644 index 00000000000..f0d4a27423c --- /dev/null +++ b/app/grants/tests/models/factories/profile_factory.py @@ -0,0 +1,12 @@ +import factory +from dashboard.models import Profile + + +class ProfileFactory(factory.django.DjangoModelFactory): + """Create mock Profile for testing.""" + + class Meta: + model = Profile + + handle = factory.Sequence(lambda n: "Contributor_%03d" % n) + data = {} \ No newline at end of file diff --git a/app/grants/tests/models/test_grant_api_key.py b/app/grants/tests/models/test_grant_api_key.py index 7cfac067d9c..f95d765b42c 100644 --- a/app/grants/tests/models/test_grant_api_key.py +++ b/app/grants/tests/models/test_grant_api_key.py @@ -1,5 +1,6 @@ import pytest from grants.models.grant_api_key import GrantAPIKey +from dashboard.models import Profile from .factories.grant_api_key_factory import GrantAPIKeyFactory @@ -31,6 +32,12 @@ def test_grant_api_key_has_a_secret(self): assert hasattr(grant_api_key, 'secret') assert grant_api_key.secret == None - + def test_grant_api_key_belongs_to_a_profile(self): + """Test profile attribute is present.""" + + grant_api_key = GrantAPIKeyFactory() + + assert hasattr(grant_api_key, 'profile') + assert isinstance(grant_api_key.profile, Profile) \ No newline at end of file