From cd924718667666a753d1d9891ab6d83c9c4c956b Mon Sep 17 00:00:00 2001 From: Jeremy Schuurmans Date: Wed, 25 Aug 2021 13:29:46 -0500 Subject: [PATCH 01/17] Extract grants models into individual files (#9341) * create new directory for models, copy over Contribution model * extract grants models to individual files * rename relocated_models directory, remove original models directory, add imports, resolve circular dependencies * extract CLRMatch into separate file * extract Flag into separate file * extract MatchPledge to separate file * extract Donation and PhantomFunding * extract GrantStat into separate file * refactor * extract GrantBrandingRoutingPolicy to separate file * update migration * add missing import to MatchPledge, remove imports from __init__.py * add missing import * decouple GrantCLRCalculation and move to own file * extract GrantType to own file * extract GrantCLR to own file * add missing import * refactor, add missing imports * remove whitespace * resolve circular dependency * run 'make fix' * import changes from #9314 * add try/except to migration file instead of editing migration directly * refactor --- app/grants/models/clr_match.py | 2 +- app/grants/models/grant.py | 3 +-- app/grants/models/match_pledge.py | 2 +- app/grants/models/subscription.py | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/grants/models/clr_match.py b/app/grants/models/clr_match.py index 32835ac2449..5cd26afb999 100644 --- a/app/grants/models/clr_match.py +++ b/app/grants/models/clr_match.py @@ -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}" \ No newline at end of file + return f"id: {self.pk}, grant: {self.grant.pk}, round: {self.round_number}, amount: {self.amount}" diff --git a/app/grants/models/grant.py b/app/grants/models/grant.py index e7f44e801f6..ec8ab8fe42a 100644 --- a/app/grants/models/grant.py +++ b/app/grants/models/grant.py @@ -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)')) @@ -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') ) diff --git a/app/grants/models/match_pledge.py b/app/grants/models/match_pledge.py index 4afa84c9a8b..fcd26445d2d 100644 --- a/app/grants/models/match_pledge.py +++ b/app/grants/models/match_pledge.py @@ -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" \ No newline at end of file + return f"{self.profile} <> {self.amount} DAI" diff --git a/app/grants/models/subscription.py b/app/grants/models/subscription.py index a4d8a9ad8d6..dbbe91a6192 100644 --- a/app/grants/models/subscription.py +++ b/app/grants/models/subscription.py @@ -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 \ No newline at end of file + return contribution From a36f99a87b0c3da4c59f46748c16e974a00679e6 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 18 Aug 2021 11:46:15 -0500 Subject: [PATCH 02/17] add pytest-factoryboy --- requirements/test.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/test.txt b/requirements/test.txt index a6f71ca364d..df604ebb7f2 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -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 From 8c7ec193a391caa115ea24b011afdd5aeb2d8870 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 18 Aug 2021 15:48:56 -0500 Subject: [PATCH 03/17] add initial test for CLRMatch --- app/grants/tests/models/__init__.py | 0 app/grants/tests/models/factories/__init__.py | 0 .../tests/models/factories/clr_match_factory.py | 16 ++++++++++++++++ .../tests/models/factories/grant_factory.py | 9 +++++++++ app/grants/tests/models/test_clr_match.py | 16 ++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 app/grants/tests/models/__init__.py create mode 100644 app/grants/tests/models/factories/__init__.py create mode 100644 app/grants/tests/models/factories/clr_match_factory.py create mode 100644 app/grants/tests/models/factories/grant_factory.py create mode 100644 app/grants/tests/models/test_clr_match.py diff --git a/app/grants/tests/models/__init__.py b/app/grants/tests/models/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/app/grants/tests/models/factories/__init__.py b/app/grants/tests/models/factories/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/app/grants/tests/models/factories/clr_match_factory.py b/app/grants/tests/models/factories/clr_match_factory.py new file mode 100644 index 00000000000..8ebfea17e26 --- /dev/null +++ b/app/grants/tests/models/factories/clr_match_factory.py @@ -0,0 +1,16 @@ +import factory +import pytest +from grants.models.clr_match import CLRMatch + +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) diff --git a/app/grants/tests/models/factories/grant_factory.py b/app/grants/tests/models/factories/grant_factory.py new file mode 100644 index 00000000000..58b8f3e048a --- /dev/null +++ b/app/grants/tests/models/factories/grant_factory.py @@ -0,0 +1,9 @@ +import factory +from grants.models.grant import Grant + + +class GrantFactory(factory.django.DjangoModelFactory): + """Create mock Grant for testing.""" + + class Meta: + model = Grant diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py new file mode 100644 index 00000000000..503c728df37 --- /dev/null +++ b/app/grants/tests/models/test_clr_match.py @@ -0,0 +1,16 @@ +import pytest +from grants.models.clr_match import CLRMatch + +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) From cee7fd3dcc532abb36579a5f452b49f8acb0d22d Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 09:49:54 -0500 Subject: [PATCH 04/17] add unit test for 'round_number' --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 503c728df37..dc86c00188a 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -14,3 +14,11 @@ def test_creation(self): clr_match = CLRMatchFactory() assert isinstance(clr_match, CLRMatch) + + def test_clr_match_has_round_number(self): + """Test 'round_number' attribute and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'round_number') + assert clr_match.round_number == None From bbd57c9a2a2cbed7e78742b86d2d3404ac481095 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 10:32:05 -0500 Subject: [PATCH 05/17] add test case for 'amount' attribute --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index dc86c00188a..6eaa8beea0a 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -22,3 +22,11 @@ def test_clr_match_has_round_number(self): assert hasattr(clr_match, 'round_number') assert clr_match.round_number == None + + def test_clr_match_has_amount(self): + """Test 'amount' attribute and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'amount') + assert clr_match.amount == 0.0 From e5fcb51f2eade625fdbac62d4633b4aa629fbb64 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 10:41:14 -0500 Subject: [PATCH 06/17] test CLRMatch has associated grant --- app/grants/tests/models/test_clr_match.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 6eaa8beea0a..091656518c5 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -1,5 +1,6 @@ import pytest from grants.models.clr_match import CLRMatch +from grants.models.grant import Grant from .factories.clr_match_factory import CLRMatchFactory @@ -30,3 +31,11 @@ def test_clr_match_has_amount(self): assert hasattr(clr_match, 'amount') assert clr_match.amount == 0.0 + + def test_clr_match_belongs_to_grant(self): + """Test CLRMatch has an associated grant.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'grant') + assert isinstance(clr_match.grant, Grant) From 7dd8db001a5b8bfbebe6e8a486efc75c42ee7470 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 11:42:33 -0500 Subject: [PATCH 07/17] add test case for has_passed_kyc attr --- app/grants/tests/models/test_clr_match.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 091656518c5..94ae8933600 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -32,10 +32,18 @@ def test_clr_match_has_amount(self): assert hasattr(clr_match, 'amount') assert clr_match.amount == 0.0 - def test_clr_match_belongs_to_grant(self): + def test_clr_match_has_an_associated_grant(self): """Test CLRMatch has an associated 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 and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'has_passed_kyc') + assert clr_match.has_passed_kyc == False From 3a1332f646f8e34a2568ec7644d91d1847da78b6 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 12:07:08 -0500 Subject: [PATCH 08/17] add test case for 'ready_for_test_payout' attr --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 94ae8933600..bbd94a65486 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -47,3 +47,11 @@ def test_clr_match_has_a_has_passed_kyc_attribute(self): 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 and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'ready_for_test_payout') + assert clr_match.ready_for_test_payout == False From d98e7801e7fa51a34dbde72167201236634160bb Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 12:21:18 -0500 Subject: [PATCH 09/17] add test case for test_payout_tx --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index bbd94a65486..e0afb0dcc00 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -55,3 +55,11 @@ def test_clr_match_has_a_ready_for_test_payout_attribute(self): 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 and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'test_payout_tx') + assert clr_match.test_payout_tx == '' From 71cd0c36a1bc1a09fa8aed85241c54e9d66cb28d Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 12:28:57 -0500 Subject: [PATCH 10/17] add test case for test_payout_tx_date --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index e0afb0dcc00..49aec2ed32d 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -63,3 +63,11 @@ def test_clr_match_has_a_test_payout_tx(self): assert hasattr(clr_match, 'test_payout_tx') assert clr_match.test_payout_tx == '' + + def test_clr_match_has_a_test_payout_tx_date(self): + """Test 'test_payout_tx_date' attribute and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'test_payout_tx_date') + assert clr_match.test_payout_tx_date == None From 034859e7a754e7a3499fffb3638ffe15777d4cec Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 12:32:43 -0500 Subject: [PATCH 11/17] add test case for test_payout_contribution --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 49aec2ed32d..f20c1d274b8 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -71,3 +71,11 @@ def test_clr_match_has_a_test_payout_tx_date(self): assert hasattr(clr_match, 'test_payout_tx_date') assert clr_match.test_payout_tx_date == None + + def test_clr_match_has_a_test_payout_contribution(self): + """Test 'test_payout_contribution' attribute and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'test_payout_contribution') + assert clr_match.test_payout_contribution == None From 2168659236dec400d2d7d2752d214704ea6838fb Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 12:59:14 -0500 Subject: [PATCH 12/17] add test case for 'ready_for_payout' --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index f20c1d274b8..22af013e029 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -79,3 +79,11 @@ def test_clr_match_has_a_test_payout_contribution(self): assert hasattr(clr_match, 'test_payout_contribution') assert clr_match.test_payout_contribution == None + + def test_clr_match_has_a_ready_for_payout_attribute(self): + """Test 'ready_for_payout' attribute and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'ready_for_payout') + assert clr_match.ready_for_payout == False From 0c1d42c758ffdec39ca006de847a4270a09abe66 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 13:08:07 -0500 Subject: [PATCH 13/17] add test case for payout_tx --- app/grants/tests/models/test_clr_match.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 22af013e029..1e087ec26b3 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -87,3 +87,13 @@ def test_clr_match_has_a_ready_for_payout_attribute(self): 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 and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'payout_tx') + assert clr_match.payout_tx == '' + + From 6d3061f7dcd83ab6874c9e7b7a7ca941c7300a49 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 14:38:51 -0500 Subject: [PATCH 14/17] add test case for payout_tx_date --- app/grants/tests/models/test_clr_match.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 1e087ec26b3..22efa36ccac 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -96,4 +96,12 @@ def test_clr_match_has_payout_tx(self): assert hasattr(clr_match, 'payout_tx') assert clr_match.payout_tx == '' + def test_clr_match_has_payout_tx_date(self): + """Test 'payout_tx_date attribute and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'payout_tx_date') + assert clr_match.payout_tx_date == None + From fd63f9cba7a89afa949a23b26b7c5ba652a70e30 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 16:40:54 -0500 Subject: [PATCH 15/17] refactor and add test case for payout_contribution --- app/grants/tests/models/test_clr_match.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 22efa36ccac..3fefa35381b 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -73,7 +73,7 @@ def test_clr_match_has_a_test_payout_tx_date(self): assert clr_match.test_payout_tx_date == None def test_clr_match_has_a_test_payout_contribution(self): - """Test 'test_payout_contribution' attribute and default value.""" + """Test 'test_payout_contribution' attribute.""" clr_match = CLRMatchFactory() @@ -97,11 +97,19 @@ def test_clr_match_has_payout_tx(self): assert clr_match.payout_tx == '' def test_clr_match_has_payout_tx_date(self): - """Test 'payout_tx_date attribute and default value.""" + """Test 'payout_tx_date' attribute.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'payout_tx_date') assert clr_match.payout_tx_date == None + def test_clr_match_has_payout_contribution_attribute(self): + """Test 'payout_contribution' attribute.""" + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'payout_contribution') + assert clr_match.payout_contribution == None + + From ebe29d936d5effd06222df4bffa455a5edbbc01e Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Thu, 19 Aug 2021 16:48:35 -0500 Subject: [PATCH 16/17] add test case for comments --- app/grants/tests/models/test_clr_match.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 3fefa35381b..3c4ed5e97a0 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -112,4 +112,10 @@ def test_clr_match_has_payout_contribution_attribute(self): assert hasattr(clr_match, 'payout_contribution') assert clr_match.payout_contribution == None - + def test_clr_match_has_comments(self): + """Test 'comments' attribute and default value.""" + + clr_match = CLRMatchFactory() + + assert hasattr(clr_match, 'comments') + assert clr_match.comments == '' \ No newline at end of file From e7a74787efba668dcf1dd0fc44edd5cd9ada3697 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 15 Sep 2021 14:49:04 -0500 Subject: [PATCH 17/17] refactor --- .../models/factories/clr_match_factory.py | 3 ++ .../models/factories/contribution_factory.py | 13 +++++++ .../tests/models/factories/profile_factory.py | 12 +++++++ .../models/factories/subscription_factory.py | 15 ++++++++ app/grants/tests/models/test_clr_match.py | 36 +++++++++---------- 5 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 app/grants/tests/models/factories/contribution_factory.py create mode 100644 app/grants/tests/models/factories/profile_factory.py create mode 100644 app/grants/tests/models/factories/subscription_factory.py diff --git a/app/grants/tests/models/factories/clr_match_factory.py b/app/grants/tests/models/factories/clr_match_factory.py index 8ebfea17e26..d1af24135ba 100644 --- a/app/grants/tests/models/factories/clr_match_factory.py +++ b/app/grants/tests/models/factories/clr_match_factory.py @@ -2,6 +2,7 @@ import pytest from grants.models.clr_match import CLRMatch +from .contribution_factory import ContributionFactory from .grant_factory import GrantFactory @@ -14,3 +15,5 @@ class Meta: amount = 0.0 grant = factory.SubFactory(GrantFactory) + test_payout_contribution = factory.SubFactory(ContributionFactory) + payout_contribution = factory.SubFactory(ContributionFactory) diff --git a/app/grants/tests/models/factories/contribution_factory.py b/app/grants/tests/models/factories/contribution_factory.py new file mode 100644 index 00000000000..3d8505dc11e --- /dev/null +++ b/app/grants/tests/models/factories/contribution_factory.py @@ -0,0 +1,13 @@ +import factory +from grants.models.contribution import Contribution + +from .subscription_factory import SubscriptionFactory + + +class ContributionFactory(factory.django.DjangoModelFactory): + """Create mock Contribution for testing.""" + + class Meta: + model = Contribution + + subscription = factory.SubFactory(SubscriptionFactory) \ 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/factories/subscription_factory.py b/app/grants/tests/models/factories/subscription_factory.py new file mode 100644 index 00000000000..aab72b01bb8 --- /dev/null +++ b/app/grants/tests/models/factories/subscription_factory.py @@ -0,0 +1,15 @@ +import factory +from grants.models.subscription import Subscription + +from .grant_factory import GrantFactory +from .profile_factory import ProfileFactory + + +class SubscriptionFactory(factory.django.DjangoModelFactory): + """Create mock Subscription for testing.""" + + class Meta: + model = Subscription + + grant = factory.SubFactory(GrantFactory) + contributor_profile = factory.SubFactory(ProfileFactory) \ No newline at end of file diff --git a/app/grants/tests/models/test_clr_match.py b/app/grants/tests/models/test_clr_match.py index 3c4ed5e97a0..4c399b61567 100644 --- a/app/grants/tests/models/test_clr_match.py +++ b/app/grants/tests/models/test_clr_match.py @@ -1,5 +1,6 @@ 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 @@ -17,15 +18,14 @@ def test_creation(self): assert isinstance(clr_match, CLRMatch) def test_clr_match_has_round_number(self): - """Test 'round_number' attribute and default value.""" + """Test 'round_number' attribute is present.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'round_number') - assert clr_match.round_number == None def test_clr_match_has_amount(self): - """Test 'amount' attribute and default value.""" + """Test 'amount' attribute is present and is a float.""" clr_match = CLRMatchFactory() @@ -33,7 +33,7 @@ def test_clr_match_has_amount(self): assert clr_match.amount == 0.0 def test_clr_match_has_an_associated_grant(self): - """Test CLRMatch has an associated grant.""" + """Test 'grant' attribute is present and is an instance of Grant.""" clr_match = CLRMatchFactory() @@ -41,7 +41,7 @@ def test_clr_match_has_an_associated_grant(self): assert isinstance(clr_match.grant, Grant) def test_clr_match_has_a_has_passed_kyc_attribute(self): - """Test 'has_passed_kyc' attribute and default value.""" + """Test 'has_passed_kyc' attribute is present and defaults to False.""" clr_match = CLRMatchFactory() @@ -49,7 +49,7 @@ def test_clr_match_has_a_has_passed_kyc_attribute(self): 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 and default value.""" + """Test 'ready_for_test_payout' attribute is present and defaults to False.""" clr_match = CLRMatchFactory() @@ -57,31 +57,29 @@ def test_clr_match_has_a_ready_for_test_payout_attribute(self): assert clr_match.ready_for_test_payout == False def test_clr_match_has_a_test_payout_tx(self): - """Test 'test_payout_tx' attribute and default value.""" + """Test 'test_payout_tx' attribute is present.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'test_payout_tx') - assert clr_match.test_payout_tx == '' def test_clr_match_has_a_test_payout_tx_date(self): - """Test 'test_payout_tx_date' attribute and default value.""" + """Test 'test_payout_tx_date' attribute is present.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'test_payout_tx_date') - assert clr_match.test_payout_tx_date == None def test_clr_match_has_a_test_payout_contribution(self): - """Test 'test_payout_contribution' attribute.""" + """Test 'test_payout_contribution' attribute is present and is an instance of Contribution.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'test_payout_contribution') - assert clr_match.test_payout_contribution == None + assert isinstance(clr_match.test_payout_contribution, Contribution) def test_clr_match_has_a_ready_for_payout_attribute(self): - """Test 'ready_for_payout' attribute and default value.""" + """Test 'ready_for_payout' attribute is present and defaults to False.""" clr_match = CLRMatchFactory() @@ -89,31 +87,29 @@ def test_clr_match_has_a_ready_for_payout_attribute(self): assert clr_match.ready_for_payout == False def test_clr_match_has_payout_tx(self): - """Test 'payout_tx' attribute and default value.""" + """Test 'payout_tx' attribute is present.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'payout_tx') - assert clr_match.payout_tx == '' def test_clr_match_has_payout_tx_date(self): - """Test 'payout_tx_date' attribute.""" + """Test 'payout_tx_date' attribute is present.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'payout_tx_date') - assert clr_match.payout_tx_date == None def test_clr_match_has_payout_contribution_attribute(self): - """Test 'payout_contribution' attribute.""" + """Test 'payout_contribution' attribute is present and is an instance of Contribution.""" clr_match = CLRMatchFactory() assert hasattr(clr_match, 'payout_contribution') - assert clr_match.payout_contribution == None + assert isinstance(clr_match.payout_contribution, Contribution) def test_clr_match_has_comments(self): - """Test 'comments' attribute and default value.""" + """Test 'comments' attribute is present and defaults to empty string.""" clr_match = CLRMatchFactory()