Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10/Test GrantAPIKey model #9452

Merged
merged 10 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/grants/models/clr_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ class CLRMatch(SuperModel):

def __str__(self):
"""Return the string representation of a Grant."""
return f"id: {self.pk}, grant: {self.grant.pk}, round: {self.round_number}, amount: {self.amount}"
return f"id: {self.pk}, grant: {self.grant.pk}, round: {self.round_number}, amount: {self.amount}"
3 changes: 1 addition & 2 deletions app/grants/models/grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class Meta:
)

in_active_clrs = models.ManyToManyField(
GrantCLR,
"GrantCLR",
help_text="Active Grants CLR Round"
)
is_clr_active = models.BooleanField(default=False, help_text=_('CLR Round active or not? (auto computed)'))
Expand Down Expand Up @@ -885,7 +885,6 @@ def save(self, update=True, *args, **kwargs):

self.clr_prediction_curve = self.calc_clr_prediction_curve
self.clr_round_num = self.calc_clr_round_label

self.search_vector = (
SearchVector('title', weight='A') + SearchVector('description', weight='B')
)
Expand Down
2 changes: 1 addition & 1 deletion app/grants/models/match_pledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def data_json(self):

def __str__(self):
"""Return the string representation of this object."""
return f"{self.profile} <> {self.amount} DAI"
return f"{self.profile} <> {self.amount} DAI"
2 changes: 1 addition & 1 deletion app/grants/models/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,4 @@ def create_contribution(self, tx_id, is_successful_contribution=True):
successful_contribution(self.grant, self, contribution)

update_grant_metadata.delay(self.pk)
return contribution
return contribution
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions app/grants/tests/models/factories/grant_api_key_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +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

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 = {}
39 changes: 39 additions & 0 deletions app/grants/tests/models/test_grant_api_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
from dashboard.models import Profile
from grants.models.grant_api_key import GrantAPIKey

from .factories.grant_api_key_factory import GrantAPIKeyFactory


@pytest.mark.django_db
class TestGrantAPIKey:
"""Test GrantAPIKey model."""

def test_creation(self):
"""Test GrantAPIKey returned by factory is valid."""

grant_api_key = GrantAPIKeyFactory()

assert isinstance(grant_api_key, GrantAPIKey)

def test_grant_api_key_has_a_key(self):
"""Test 'key' attribute is present."""

grant_api_key = GrantAPIKeyFactory()

assert hasattr(grant_api_key, 'key')

def test_grant_api_key_has_a_secret(self):
"""Test secret attribute is present."""

grant_api_key = GrantAPIKeyFactory()

assert hasattr(grant_api_key, 'secret')

def test_grant_api_key_has_associated_profile(self):
"""Test profile attribute is present and is an instance of Profile."""

grant_api_key = GrantAPIKeyFactory()

assert hasattr(grant_api_key, 'profile')
assert isinstance(grant_api_key.profile, Profile)
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-r base.txt
pytest==6.2.4
pytest-cov==2.12.0
pytest-factoryboy==2.1.0
pytest-isort==2.0.0
pytest-django==4.3.0
pytest-sugar==0.9.4
Expand Down