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

5/Test GrantCLRCalculation model #9396

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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}"
1 change: 0 additions & 1 deletion app/grants/models/grant.py
Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import factory
import pytest
from grants.models.grant_clr_calculation import GrantCLRCalculation

from .grant_clr_factory import GrantCLRFactory
from .grant_factory import GrantFactory


@pytest.mark.django_db
class GrantCLRCalculationFactory(factory.django.DjangoModelFactory):
"""Create mock GrantCLRCalculation for testing."""

class Meta:
model = GrantCLRCalculation

grant = factory.SubFactory(GrantFactory)
grantclr = factory.SubFactory(GrantCLRFactory)
17 changes: 17 additions & 0 deletions app/grants/tests/models/factories/grant_clr_factory.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions app/grants/tests/models/factories/grant_factory.py
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
53 changes: 53 additions & 0 deletions app/grants/tests/models/test_grant_clr_calculation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest
from grants.models.grant import Grant, GrantCLR
from grants.models.grant_clr_calculation import GrantCLRCalculation

from .factories.grant_clr_calculation_factory import GrantCLRCalculationFactory


@pytest.mark.django_db
class TestGrantCLRCalculation:
"""Test GrantCLRCalculation model."""

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

grant_clr_calulation = GrantCLRCalculationFactory()

assert isinstance(grant_clr_calulation, GrantCLRCalculation)

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

grant_clr_calulation = GrantCLRCalculationFactory()

assert hasattr(grant_clr_calulation, 'latest')
assert grant_clr_calulation.latest == False

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

grant_clr_calculation = GrantCLRCalculationFactory()

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

def test_grant_clr_calculation_has_associated_grant_clr(self):
"""Test 'grantclr' attribute is present and is an instance of GrantCLR."""

grant_clr_calculation = GrantCLRCalculationFactory()

assert hasattr(grant_clr_calculation, 'grantclr')
assert isinstance(grant_clr_calculation.grantclr, GrantCLR)

def test_grant_clr_calculation_has_clr_prediction_curve(self):
"""Test 'clr_prediction_curve' attribute is present and defaults to an empty list."""

grant_clr_calculation = GrantCLRCalculationFactory()

assert hasattr(grant_clr_calculation, 'clr_prediction_curve')
assert grant_clr_calculation.clr_prediction_curve == []
assert len(grant_clr_calculation.clr_prediction_curve) == 0



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