From e746f4e6518b5738cbbbf2acd3cd94bf5658f670 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 8 Sep 2021 10:49:41 -0500 Subject: [PATCH] add test for profile --- .../tests/models/factories/grant_api_key_factory.py | 6 +++++- app/grants/tests/models/factories/profile_factory.py | 12 ++++++++++++ app/grants/tests/models/test_grant_api_key.py | 9 ++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 app/grants/tests/models/factories/profile_factory.py 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