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
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)
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