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

2/Test CLRMatch model #9393

Merged
merged 18 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/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
19 changes: 19 additions & 0 deletions app/grants/tests/models/factories/clr_match_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import factory
import pytest
from grants.models.clr_match import CLRMatch

from .contribution_factory import ContributionFactory
from .grant_factory import GrantFactory


@pytest.mark.django_db
class CLRMatchFactory(factory.django.DjangoModelFactory):
"""Create a mock CLRMatch for testing."""

class Meta:
model = CLRMatch

amount = 0.0
grant = factory.SubFactory(GrantFactory)
test_payout_contribution = factory.SubFactory(ContributionFactory)
payout_contribution = factory.SubFactory(ContributionFactory)
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class ContributionFactory(factory.django.DjangoModelFactory):
class Meta:
model = Contribution

subscription = factory.SubFactory(SubscriptionFactory)
subscription = factory.SubFactory(SubscriptionFactory)
2 changes: 1 addition & 1 deletion app/grants/tests/models/factories/profile_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class Meta:
model = Profile

handle = factory.Sequence(lambda n: "Contributor_%03d" % n)
data = {}
data = {}
117 changes: 117 additions & 0 deletions app/grants/tests/models/test_clr_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import pytest
from grants.models.clr_match import CLRMatch
from grants.models.contribution import Contribution
from grants.models.grant import Grant

from .factories.clr_match_factory import CLRMatchFactory


@pytest.mark.django_db
class TestCLRMatch:
"""Test CLRMatch model."""

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

clr_match = CLRMatchFactory()

assert isinstance(clr_match, CLRMatch)

def test_clr_match_has_round_number(self):
"""Test 'round_number' attribute is present."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'round_number')

def test_clr_match_has_amount(self):
"""Test 'amount' attribute is present and is a float."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'amount')
assert clr_match.amount == 0.0

def test_clr_match_has_an_associated_grant(self):
"""Test 'grant' attribute is present and is an instance of Grant."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'grant')
assert isinstance(clr_match.grant, Grant)

def test_clr_match_has_a_has_passed_kyc_attribute(self):
"""Test 'has_passed_kyc' attribute is present and defaults to False."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'has_passed_kyc')
assert clr_match.has_passed_kyc == False

def test_clr_match_has_a_ready_for_test_payout_attribute(self):
"""Test 'ready_for_test_payout' attribute is present and defaults to False."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'ready_for_test_payout')
assert clr_match.ready_for_test_payout == False

def test_clr_match_has_a_test_payout_tx(self):
"""Test 'test_payout_tx' attribute is present."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'test_payout_tx')

def test_clr_match_has_a_test_payout_tx_date(self):
"""Test 'test_payout_tx_date' attribute is present."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'test_payout_tx_date')

def test_clr_match_has_a_test_payout_contribution(self):
"""Test 'test_payout_contribution' attribute is present and is an instance of Contribution."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'test_payout_contribution')
assert isinstance(clr_match.test_payout_contribution, Contribution)

def test_clr_match_has_a_ready_for_payout_attribute(self):
"""Test 'ready_for_payout' attribute is present and defaults to False."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'ready_for_payout')
assert clr_match.ready_for_payout == False

def test_clr_match_has_payout_tx(self):
"""Test 'payout_tx' attribute is present."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'payout_tx')

def test_clr_match_has_payout_tx_date(self):
"""Test 'payout_tx_date' attribute is present."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'payout_tx_date')

def test_clr_match_has_payout_contribution_attribute(self):
"""Test 'payout_contribution' attribute is present and is an instance of Contribution."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'payout_contribution')
assert isinstance(clr_match.payout_contribution, Contribution)

def test_clr_match_has_comments(self):
"""Test 'comments' attribute is present and defaults to empty string."""

clr_match = CLRMatchFactory()

assert hasattr(clr_match, 'comments')
assert clr_match.comments == ''