Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nora-codecov committed Nov 12, 2024
1 parent 4d64741 commit d62cd64
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 5 additions & 2 deletions shared/django_apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,16 @@ def should_write_to_storage(self) -> bool:
_flare = models.JSONField(db_column="flare", null=True)
_flare_storage_path = models.URLField(db_column="flare_storage_path", null=True)
flare = ArchiveField(
should_write_to_storage_fn=should_write_to_storage, default_value_class=dict
should_write_to_storage_fn=should_write_to_storage,
default_value_class=dict,
)

def save(self, *args, **kwargs):
self.updatestamp = timezone.now()
if self.state != PullStates.OPEN.value and self.flare is not None:
if self.state != PullStates.OPEN.value and self.flare:
# flare is used to draw graphs, can be quite large, so dump it when it's no longer needed
# flare can be None or {} to indicate empty
# this gets set in the db as {} since that is the default value for the field
self.flare = None
super().save(*args, **kwargs)

Expand Down
30 changes: 28 additions & 2 deletions tests/unit/django_apps/core/test_core_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
from django.forms import ValidationError
from django.test import TestCase

from shared.django_apps.core.models import Commit
from shared.django_apps.core.tests.factories import CommitFactory, RepositoryFactory
from shared.django_apps.core.models import Commit, PullStates
from shared.django_apps.core.tests.factories import (
CommitFactory,
PullFactory,
RepositoryFactory,
)
from shared.django_apps.reports.tests.factories import CommitReportFactory
from shared.storage.exceptions import FileNotInStorageError

Expand All @@ -17,6 +21,28 @@ def test_clean_repo(self):
repo.clean()


class PullTests(TestCase):
def test_save_method(self):
test_value_for_flare = {"test": "test"}
pull = PullFactory(
state=PullStates.OPEN.value,
_flare=test_value_for_flare,
repository=RepositoryFactory(),
)
self.assertEqual(pull.flare, test_value_for_flare)

pull.title = "changing something on the pull while it is open"
pull.save()
pull.refresh_from_db()
self.assertEqual(pull.flare, test_value_for_flare)

pull.state = PullStates.MERGED.value
pull.save()
pull.refresh_from_db()
self.assertNotEqual(pull.flare, test_value_for_flare)
self.assertEqual(pull.flare, {})


class CommitTests(TestCase):
def test_commitreport_no_code(self):
commit = CommitFactory()
Expand Down

0 comments on commit d62cd64

Please sign in to comment.