-
-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 * add pytest-factoryboy * add test directory for models and directory for factories * add initial test for donation model * add test case for from_address * test donation has a to_address * add test case for relation to profile * add test case for token_address * add test case for donation.token_symbol * add test case for donation.token_amount * add test case for donation.token_amount_usdt * add test case for donation.tx_id * add test case for donation.network * add test cases for donation_percentage and subscription * add test case for relation to contribution * remove some whitespace * refactor and add docstrings * refactor * refactor
- Loading branch information
Jeremy Schuurmans
authored
Sep 29, 2021
1 parent
65aea9b
commit 5a5a5bf
Showing
13 changed files
with
187 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import factory | ||
import pytest | ||
from grants.models.donation import Donation | ||
|
||
from .contribution_factory import ContributionFactory | ||
from .profile_factory import ProfileFactory | ||
from .subscription_factory import SubscriptionFactory | ||
|
||
|
||
@pytest.mark.django_db | ||
class DonationFactory(factory.django.DjangoModelFactory): | ||
"""Create a mock Donation for testing.""" | ||
|
||
class Meta: | ||
model = Donation | ||
|
||
profile = factory.SubFactory(ProfileFactory) | ||
subscription = factory.SubFactory(SubscriptionFactory) | ||
contribution = factory.SubFactory(ContributionFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import pytest | ||
from dashboard.models import Profile | ||
from grants.models.contribution import Contribution | ||
from grants.models.donation import Donation | ||
from grants.models.subscription import Subscription | ||
|
||
from .factories.donation_factory import DonationFactory | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestDonation: | ||
"""Test Donation model.""" | ||
|
||
def test_creation(self): | ||
"""Test instance of Donation returned by factory is valid.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert isinstance(donation, Donation) | ||
|
||
def test_donation_has_a_from_address(self): | ||
"""Test from_address attribute is present and defaults to '0x0'.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'from_address') | ||
assert donation.from_address == '0x0' | ||
|
||
def test_donation_has_a_to_address(self): | ||
"""Test to_address attribute is present and defaults to '0x0'.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'to_address') | ||
assert donation.to_address == '0x0' | ||
|
||
def test_donation_belongs_to_profile(self): | ||
"""Test profile attribute is present and is an instance of Profile.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'profile') | ||
assert isinstance(donation.profile, Profile) | ||
|
||
def test_donation_has_a_token_address(self): | ||
"""Test token_address attribute is present and defaults to '0x0'.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'token_address') | ||
assert donation.token_address == '0x0' | ||
|
||
def test_donation_has_a_token_symbol(self): | ||
"""Test token_symbol attribute is present and defaults to empty string.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'token_symbol') | ||
assert donation.token_symbol == '' | ||
|
||
def test_donation_has_a_token_amount(self): | ||
"""Test token_amount attribute is present and defaults to 0.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'token_amount') | ||
assert donation.token_amount == 0 | ||
|
||
def test_donation_has_a_token_amount_usdt(self): | ||
"""Test token_amount_usdt attribute is present and defaults to 0.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'token_amount_usdt') | ||
assert donation.token_amount_usdt == 0 | ||
|
||
def test_donation_has_a_tx_id(self): | ||
"""Test tx_id attribute is present and defaults to '0x0'.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'tx_id') | ||
assert donation.tx_id == '0x0' | ||
|
||
def test_donation_has_a_network(self): | ||
"""Test network attribute is present and defaults to 'mainnet'.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'network') | ||
assert donation.network == 'mainnet' | ||
|
||
def test_donation_has_a_donation_percentage(self): | ||
"""Test donation_percentage attribute is present and defaults to 0.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'donation_percentage') | ||
assert donation.donation_percentage == 0 | ||
|
||
def test_donation_has_related_subscription(self): | ||
"""Test subscription attribute is present and is an instance of Subscription.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'subscription') | ||
assert isinstance(donation.subscription, Subscription) | ||
|
||
def test_donation_has_related_contribution(self): | ||
"""Test contribution attribute is present and is an instance of Contribution.""" | ||
|
||
donation = DonationFactory() | ||
|
||
assert hasattr(donation, 'contribution') | ||
assert isinstance(donation.contribution, Contribution) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters