Skip to content

Commit

Permalink
3/Test GrantBrandingRoutingPolicy model (#9394)
Browse files Browse the repository at this point in the history
* 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 directory structure for models testing and factories

* add initial test

* stub out test cases

* add docstrings and factories

* add assertions for policy_name attribute

* add assertions for url_pattern

* refactor and add assertions for banner_image

* add assertions for priority, background_image, inline_css

* fix typo

* refactor

* Update grant.py

Co-authored-by: Aditya Anand M C <aditya.anandmc@gmail.com>
  • Loading branch information
Jeremy Schuurmans and thelostone-mc authored Sep 29, 2021
1 parent 638832b commit 6911ea5
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import factory
from grants.models.grant_branding_routing_policy import GrantBrandingRoutingPolicy


class GrantBrandingRoutingPolicyFactory(factory.django.DjangoModelFactory):
"""Create mock GrantBrandingRoutingPolicy for testing."""

class Meta:
model = GrantBrandingRoutingPolicy

priority = 1
62 changes: 62 additions & 0 deletions app/grants/tests/models/test_grant_branding_routing_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from django.db.models.fields.files import ImageFieldFile

import pytest
from grants.models.grant_branding_routing_policy import GrantBrandingRoutingPolicy

from .factories.grant_branding_routing_policy_factory import GrantBrandingRoutingPolicyFactory


@pytest.mark.django_db
class TestGrantBrandingRoutingPolicy:
"""Test GrantBrandingRoutingPolicy model."""

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

grant_branding_routing_policy = GrantBrandingRoutingPolicyFactory()

assert isinstance(grant_branding_routing_policy, GrantBrandingRoutingPolicy)

def test_grant_branding_routing_policy_has_a_policy_name(self):
"""Test policy_name attribute is present."""

grant_branding_routing_policy = GrantBrandingRoutingPolicyFactory()

assert hasattr(grant_branding_routing_policy, 'policy_name')

def test_grant_branding_routing_policy_has_a_url_pattern(self):
"""Test url_pattern attribute is present."""

grant_branding_routing_policy = GrantBrandingRoutingPolicyFactory()

assert hasattr(grant_branding_routing_policy, 'url_pattern')

def test_grant_branding_routing_policy_has_a_banner_image(self):
"""Test banner_image attribute is present."""

grant_branding_routing_policy = GrantBrandingRoutingPolicyFactory()

assert hasattr(grant_branding_routing_policy, 'banner_image')
assert isinstance(grant_branding_routing_policy.banner_image, ImageFieldFile)

def test_grant_branding_routing_policy_has_a_priority_attribute(self):
"""Test priority attribute is present."""

grant_branding_routing_policy = GrantBrandingRoutingPolicyFactory()

assert hasattr(grant_branding_routing_policy, 'priority')

def test_grant_branding_routing_policy_has_a_background_image(self):
"""Test background_image attribute is present."""

grant_branding_routing_policy = GrantBrandingRoutingPolicyFactory()

assert hasattr(grant_branding_routing_policy, 'background_image')

def test_grant_branding_routing_policy_has_a_inline_css_attribute(self):
"""Test inline_css attribute is present and defaults to empty string."""

grant_branding_routing_policy = GrantBrandingRoutingPolicyFactory()

assert hasattr(grant_branding_routing_policy, 'inline_css')
assert grant_branding_routing_policy.inline_css == ''
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pytest==6.2.4
pytest-cov==2.12.0
pytest-factoryboy==2.1.0
pytest-isort==2.0.0
pytest-factoryboy==2.1.0
pytest-django==4.3.0
pytest-sugar==0.9.4
coverage==5.5
Expand Down

0 comments on commit 6911ea5

Please sign in to comment.