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

4/Test GrantStat model #9395

Merged
merged 10 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions app/grants/tests/models/factories/grant_stat_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import factory
from grants.models.grant_stat import GrantStat

from .grant_factory import GrantFactory


class GrantStatFactory(factory.django.DjangoModelFactory):
"""Create mock GrantStat for testing."""

class Meta:
model = GrantStat

grant = factory.SubFactory(GrantFactory)
43 changes: 43 additions & 0 deletions app/grants/tests/models/test_grant_stat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest
from grants.models.grant import Grant
from grants.models.grant_stat import GrantStat

from .factories.grant_stat_factory import GrantStatFactory


@pytest.mark.django_db
class TestGrantStat:
"""Test GrantStat model."""

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

grant_stat = GrantStatFactory()

assert isinstance(grant_stat, GrantStat)

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

grant_stat = GrantStatFactory()

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

def test_grant_stat_has_data_attribute(self):
"""Test 'data' attribute is present and defaults to empty dictionary."""

grant_stat = GrantStatFactory()

assert hasattr(grant_stat, 'data')
assert grant_stat.data == {}
assert len(grant_stat.data) == 0

def test_grant_stat_has_snapshot_type(self):
"""Test 'snapshot_type' attribute is present."""

grant_stat = GrantStatFactory()

assert hasattr(grant_stat, 'snapshot_type')