From aca3d076dfef7f8e7b1eadaa331b93ca147013f2 Mon Sep 17 00:00:00 2001 From: Jeremy Schuurmans Date: Wed, 25 Aug 2021 13:29:46 -0500 Subject: [PATCH 01/15] 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 1b22323cb973761b03af23fedfab0f9c1ed79e3b Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 25 Aug 2021 15:45:43 -0500 Subject: [PATCH 02/15] 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 68563695aadb8bdd7ad48061c39490b508f94485 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 25 Aug 2021 16:06:31 -0500 Subject: [PATCH 03/15] add initial test --- app/grants/tests/models/__init__.py | 0 app/grants/tests/models/factories/__init__.py | 0 .../models/factories/match_pledge_factory.py | 9 +++++++++ app/grants/tests/models/test_match_pledge.py | 17 +++++++++++++++++ 4 files changed, 26 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/match_pledge_factory.py create mode 100644 app/grants/tests/models/test_match_pledge.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/match_pledge_factory.py b/app/grants/tests/models/factories/match_pledge_factory.py new file mode 100644 index 00000000000..2972ff39509 --- /dev/null +++ b/app/grants/tests/models/factories/match_pledge_factory.py @@ -0,0 +1,9 @@ +import factory +from grants.models.match_pledge import MatchPledge + + +class MatchPledgeFactory(factory.django.DjangoModelFactory): + """Create mock MatchPledge for testing.""" + + class Meta: + model = MatchPledge \ No newline at end of file diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py new file mode 100644 index 00000000000..2fb08fbf9af --- /dev/null +++ b/app/grants/tests/models/test_match_pledge.py @@ -0,0 +1,17 @@ +import pytest +from grants.models.match_pledge import MatchPledge + +from .factories.match_pledge_factory import MatchPledgeFactory + + +@pytest.mark.django_db +class TestMatchPledge: + """Test MatchPledge model.""" + + def test_creation(self): + """Test instance of MatchPledge returned by factory is valid.""" + + match_pledge = MatchPledgeFactory() + + assert isinstance(match_pledge, MatchPledge) + From 0d2c91cf7289381655bdac332a3a890fb39ce334 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 25 Aug 2021 16:08:36 -0500 Subject: [PATCH 04/15] add test case for 'active' attribute --- app/grants/tests/models/test_match_pledge.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 2fb08fbf9af..146e6dc4d0d 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -15,3 +15,11 @@ def test_creation(self): assert isinstance(match_pledge, MatchPledge) + def test_match_pledge_has_active_attribute(self): + """Test 'active' attribute and default value.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'active') + assert match_pledge.active == False + From 6f2ba9caffa2062c1ea9e4225eea150a2e904bbf Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 25 Aug 2021 16:15:42 -0500 Subject: [PATCH 05/15] add test for profile attribute --- app/grants/tests/models/test_match_pledge.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 146e6dc4d0d..aab744ad1e9 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -23,3 +23,10 @@ def test_match_pledge_has_active_attribute(self): assert hasattr(match_pledge, 'active') assert match_pledge.active == False + def test_match_pledge_has_profile_attribute(self): + """Test 'profile' attribute and default value.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'profile') + assert match_pledge.profile == None \ No newline at end of file From 375af3c6defd9799fece1486415e8d581a59dd01 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 25 Aug 2021 16:17:12 -0500 Subject: [PATCH 06/15] add test case for 'amount' --- app/grants/tests/models/test_match_pledge.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index aab744ad1e9..cc74a684ed7 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -29,4 +29,12 @@ def test_match_pledge_has_profile_attribute(self): match_pledge = MatchPledgeFactory() assert hasattr(match_pledge, 'profile') - assert match_pledge.profile == None \ No newline at end of file + assert match_pledge.profile == None + + def test_match_pledge_has_amount_attribute(self): + """Test 'amount' attribute and default value.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'amount') + assert match_pledge.amount == 1 \ No newline at end of file From 75433e9949a78e27396bfcce32fcf4640443acce Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 25 Aug 2021 16:19:18 -0500 Subject: [PATCH 07/15] add test for pledge_type attribute --- app/grants/tests/models/test_match_pledge.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index cc74a684ed7..6061e4331bb 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -37,4 +37,14 @@ def test_match_pledge_has_amount_attribute(self): match_pledge = MatchPledgeFactory() assert hasattr(match_pledge, 'amount') - assert match_pledge.amount == 1 \ No newline at end of file + assert match_pledge.amount == 1 + + def test_match_pledge_has_pledge_type_attribute(self): + """Test 'pledge_type' attribute.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'pledge_type') + assert match_pledge.pledge_type == None + + \ No newline at end of file From 4d98b51edcbcd5b55d23540099f342a626bbbcab Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 25 Aug 2021 16:26:52 -0500 Subject: [PATCH 08/15] add test case for comments --- app/grants/tests/models/test_match_pledge.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 6061e4331bb..f7e3dcd55fc 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -47,4 +47,12 @@ def test_match_pledge_has_pledge_type_attribute(self): assert hasattr(match_pledge, 'pledge_type') assert match_pledge.pledge_type == None + def test_match_pledge_has_comments(self): + """Test 'comments' attribute and default value.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'comments') + assert match_pledge.comments == '' + \ No newline at end of file From 6c01fab55ac48f4dec0979d8f13b16bca6914a12 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Fri, 27 Aug 2021 00:42:09 -0500 Subject: [PATCH 09/15] refactor --- .../tests/models/factories/match_pledge_factory.py | 6 +++++- app/grants/tests/models/factories/profile_factory.py | 12 ++++++++++++ app/grants/tests/models/test_match_pledge.py | 9 ++++----- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 app/grants/tests/models/factories/profile_factory.py diff --git a/app/grants/tests/models/factories/match_pledge_factory.py b/app/grants/tests/models/factories/match_pledge_factory.py index 2972ff39509..727283b3efc 100644 --- a/app/grants/tests/models/factories/match_pledge_factory.py +++ b/app/grants/tests/models/factories/match_pledge_factory.py @@ -1,9 +1,13 @@ import factory from grants.models.match_pledge import MatchPledge +from .profile_factory import ProfileFactory + class MatchPledgeFactory(factory.django.DjangoModelFactory): """Create mock MatchPledge for testing.""" class Meta: - model = MatchPledge \ No newline at end of file + model = MatchPledge + + profile = factory.SubFactory(ProfileFactory) 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_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index f7e3dcd55fc..8ae6b07be8d 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -1,4 +1,5 @@ import pytest +from dashboard.models import Profile from grants.models.match_pledge import MatchPledge from .factories.match_pledge_factory import MatchPledgeFactory @@ -23,13 +24,13 @@ def test_match_pledge_has_active_attribute(self): assert hasattr(match_pledge, 'active') assert match_pledge.active == False - def test_match_pledge_has_profile_attribute(self): - """Test 'profile' attribute and default value.""" + def test_match_pledge_belongs_to_profile(self): + """Test relation to Profile.""" match_pledge = MatchPledgeFactory() assert hasattr(match_pledge, 'profile') - assert match_pledge.profile == None + assert isinstance(match_pledge.profile, Profile) def test_match_pledge_has_amount_attribute(self): """Test 'amount' attribute and default value.""" @@ -54,5 +55,3 @@ def test_match_pledge_has_comments(self): assert hasattr(match_pledge, 'comments') assert match_pledge.comments == '' - - \ No newline at end of file From dea67e9a8d506f8ed0c9a164fdde89126441329d Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Fri, 27 Aug 2021 01:26:07 -0500 Subject: [PATCH 10/15] add test case for 'end_date' attribute --- .../tests/models/factories/profile_factory.py | 2 +- app/grants/tests/models/test_match_pledge.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/grants/tests/models/factories/profile_factory.py b/app/grants/tests/models/factories/profile_factory.py index f0d4a27423c..685ef0e3547 100644 --- a/app/grants/tests/models/factories/profile_factory.py +++ b/app/grants/tests/models/factories/profile_factory.py @@ -9,4 +9,4 @@ class Meta: model = Profile handle = factory.Sequence(lambda n: "Contributor_%03d" % n) - data = {} \ No newline at end of file + data = {} diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 8ae6b07be8d..259b4a30c35 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -1,3 +1,9 @@ +import time +from datetime import datetime, timedelta + +from django.utils import timezone +from django.utils.timezone import localtime + import pytest from dashboard.models import Profile from grants.models.match_pledge import MatchPledge @@ -55,3 +61,13 @@ def test_match_pledge_has_comments(self): assert hasattr(match_pledge, 'comments') assert match_pledge.comments == '' + + def test_match_pledge_has_end_date(self): + """Test 'end_date' attribute and that default value is 30 days from today's date.""" + + next_month = localtime(timezone.now() + timedelta(days=30)) + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'end_date') + assert isinstance(match_pledge.end_date, datetime) + assert match_pledge.end_date.replace(microsecond=0) == next_month.replace(microsecond=0) From f5bf1dc239eba00cc854c821705b9c2421f60bd7 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Fri, 27 Aug 2021 01:29:53 -0500 Subject: [PATCH 11/15] add test case for 'data' attribute --- app/grants/tests/models/test_match_pledge.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 259b4a30c35..7ecb9741d70 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -1,5 +1,6 @@ import time from datetime import datetime, timedelta +from typing import Match from django.utils import timezone from django.utils.timezone import localtime @@ -71,3 +72,11 @@ def test_match_pledge_has_end_date(self): assert hasattr(match_pledge, 'end_date') assert isinstance(match_pledge.end_date, datetime) assert match_pledge.end_date.replace(microsecond=0) == next_month.replace(microsecond=0) + + def test_match_pledge_has_data_attribute(self): + """Test 'data' attribute.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'data') + assert match_pledge.data == None From 4d65def8a54a290fb41e129c33f58f1ca79a24f6 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Fri, 27 Aug 2021 01:37:29 -0500 Subject: [PATCH 12/15] add test case for 'clr_round_num' --- .../tests/models/factories/grant_clr_factory.py | 17 +++++++++++++++++ .../models/factories/match_pledge_factory.py | 2 ++ app/grants/tests/models/test_match_pledge.py | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 app/grants/tests/models/factories/grant_clr_factory.py diff --git a/app/grants/tests/models/factories/grant_clr_factory.py b/app/grants/tests/models/factories/grant_clr_factory.py new file mode 100644 index 00000000000..344b9125982 --- /dev/null +++ b/app/grants/tests/models/factories/grant_clr_factory.py @@ -0,0 +1,17 @@ +from datetime import datetime, timedelta + +import factory +import pytest +from grants.models.grant import GrantCLR + + +@pytest.mark.django_db +class GrantCLRFactory(factory.django.DjangoModelFactory): + """Create mock GrantCLR for testing.""" + + class Meta: + model = GrantCLR + + round_num = 2 + start_date = datetime.now() + end_date = start_date + timedelta(weeks=2) diff --git a/app/grants/tests/models/factories/match_pledge_factory.py b/app/grants/tests/models/factories/match_pledge_factory.py index 727283b3efc..036808ac323 100644 --- a/app/grants/tests/models/factories/match_pledge_factory.py +++ b/app/grants/tests/models/factories/match_pledge_factory.py @@ -1,6 +1,7 @@ import factory from grants.models.match_pledge import MatchPledge +from .grant_clr_factory import GrantCLRFactory from .profile_factory import ProfileFactory @@ -11,3 +12,4 @@ class Meta: model = MatchPledge profile = factory.SubFactory(ProfileFactory) + clr_round_num = factory.SubFactory(GrantCLRFactory) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 7ecb9741d70..0040db93e35 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -7,6 +7,7 @@ import pytest from dashboard.models import Profile +from grants.models.grant import GrantCLR from grants.models.match_pledge import MatchPledge from .factories.match_pledge_factory import MatchPledgeFactory @@ -80,3 +81,11 @@ def test_match_pledge_has_data_attribute(self): assert hasattr(match_pledge, 'data') assert match_pledge.data == None + + def test_match_pledge_has_clr_round_num_attribute(self): + """Test 'clr_round_num' attribute.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'clr_round_num') + assert isinstance(match_pledge.clr_round_num, GrantCLR) From b8ae945139542ecd9baa939ba697429f35aad335 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Fri, 27 Aug 2021 02:08:12 -0500 Subject: [PATCH 13/15] add test case for data_json property --- .../tests/models/factories/match_pledge_factory.py | 3 +++ app/grants/tests/models/test_match_pledge.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/grants/tests/models/factories/match_pledge_factory.py b/app/grants/tests/models/factories/match_pledge_factory.py index 036808ac323..7dd4d535466 100644 --- a/app/grants/tests/models/factories/match_pledge_factory.py +++ b/app/grants/tests/models/factories/match_pledge_factory.py @@ -1,3 +1,5 @@ +import json + import factory from grants.models.match_pledge import MatchPledge @@ -12,4 +14,5 @@ class Meta: model = MatchPledge profile = factory.SubFactory(ProfileFactory) + data = json.dumps('test string') clr_round_num = factory.SubFactory(GrantCLRFactory) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 0040db93e35..66f34a1869c 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -1,6 +1,5 @@ -import time +import json from datetime import datetime, timedelta -from typing import Match from django.utils import timezone from django.utils.timezone import localtime @@ -80,7 +79,7 @@ def test_match_pledge_has_data_attribute(self): match_pledge = MatchPledgeFactory() assert hasattr(match_pledge, 'data') - assert match_pledge.data == None + assert match_pledge.data == '"test string"' def test_match_pledge_has_clr_round_num_attribute(self): """Test 'clr_round_num' attribute.""" @@ -89,3 +88,11 @@ def test_match_pledge_has_clr_round_num_attribute(self): assert hasattr(match_pledge, 'clr_round_num') assert isinstance(match_pledge.clr_round_num, GrantCLR) + + def test_data_json(self): + """Test 'data_json' property returns data attribute as valid JSON.""" + + match_pledge = MatchPledgeFactory() + + assert hasattr(match_pledge, 'data_json') + assert match_pledge.data_json == 'test string' From f2c316c052707d01b207fe484bf6f0083d897df1 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Fri, 27 Aug 2021 02:08:46 -0500 Subject: [PATCH 14/15] remove unnecessary import --- app/grants/tests/models/test_match_pledge.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index 66f34a1869c..b68a305aec6 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -1,4 +1,3 @@ -import json from datetime import datetime, timedelta from django.utils import timezone From 2c24f235ea0909d252ea4e7115f50d558a7cad72 Mon Sep 17 00:00:00 2001 From: Jer-Sch Date: Wed, 15 Sep 2021 16:39:21 -0500 Subject: [PATCH 15/15] refactor --- app/grants/tests/models/test_match_pledge.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/grants/tests/models/test_match_pledge.py b/app/grants/tests/models/test_match_pledge.py index b68a305aec6..8647db62b46 100644 --- a/app/grants/tests/models/test_match_pledge.py +++ b/app/grants/tests/models/test_match_pledge.py @@ -23,15 +23,15 @@ def test_creation(self): assert isinstance(match_pledge, MatchPledge) def test_match_pledge_has_active_attribute(self): - """Test 'active' attribute and default value.""" + """Test 'active' attribute is present and defaults to False.""" match_pledge = MatchPledgeFactory() assert hasattr(match_pledge, 'active') assert match_pledge.active == False - def test_match_pledge_belongs_to_profile(self): - """Test relation to Profile.""" + def test_match_pledge_has_associated_profile(self): + """Test 'profile' attribute is present and is an instance of Profile.""" match_pledge = MatchPledgeFactory() @@ -39,7 +39,7 @@ def test_match_pledge_belongs_to_profile(self): assert isinstance(match_pledge.profile, Profile) def test_match_pledge_has_amount_attribute(self): - """Test 'amount' attribute and default value.""" + """Test 'amount' attribute is present defaults to 1.""" match_pledge = MatchPledgeFactory() @@ -47,15 +47,14 @@ def test_match_pledge_has_amount_attribute(self): assert match_pledge.amount == 1 def test_match_pledge_has_pledge_type_attribute(self): - """Test 'pledge_type' attribute.""" + """Test 'pledge_type' attribute is present.""" match_pledge = MatchPledgeFactory() assert hasattr(match_pledge, 'pledge_type') - assert match_pledge.pledge_type == None def test_match_pledge_has_comments(self): - """Test 'comments' attribute and default value.""" + """Test 'comments' attribute is present and defaults to empty string.""" match_pledge = MatchPledgeFactory() @@ -63,7 +62,7 @@ def test_match_pledge_has_comments(self): assert match_pledge.comments == '' def test_match_pledge_has_end_date(self): - """Test 'end_date' attribute and that default value is 30 days from today's date.""" + """Test 'end_date' attribute is present and that default value is 30 days from today's date.""" next_month = localtime(timezone.now() + timedelta(days=30)) match_pledge = MatchPledgeFactory() @@ -78,10 +77,9 @@ def test_match_pledge_has_data_attribute(self): match_pledge = MatchPledgeFactory() assert hasattr(match_pledge, 'data') - assert match_pledge.data == '"test string"' def test_match_pledge_has_clr_round_num_attribute(self): - """Test 'clr_round_num' attribute.""" + """Test 'clr_round_num' attribute is present and is an instance of GrantCLR.""" match_pledge = MatchPledgeFactory()