Skip to content

Commit

Permalink
add test for profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jer-Sch committed Sep 8, 2021
1 parent 1bd981f commit e746f4e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/grants/tests/models/factories/grant_api_key_factory.py
Original file line number Diff line number Diff line change
@@ -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
model = GrantAPIKey

profile = factory.SubFactory(ProfileFactory)
12 changes: 12 additions & 0 deletions app/grants/tests/models/factories/profile_factory.py
Original file line number Diff line number Diff line change
@@ -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 = {}
9 changes: 8 additions & 1 deletion app/grants/tests/models/test_grant_api_key.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)


0 comments on commit e746f4e

Please sign in to comment.