Skip to content
Snippets Groups Projects
Commit 1a145087 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Add a test to ensure we can clean the object before save

parent 9646fa9e
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,15 @@ class Round(AbstractStreamForm):
Q(end_date__gte=self.start_date)
)
conflicting_rounds = Round.objects.child_of(self.parent_page).filter(
if hasattr(self, 'parent_page'):
# Check if the create hook has added the parent page, we aren't an object yet.
# Ensures we can access related objects during the clean phase instead of save.
base_query = Round.objects.child_of(self.parent_page)
else:
# don't need parent page, we are an actual object now.
base_query = Round.objects.sibling_of(self)
conflicting_rounds = base_query.filter(
conflict_query
).exclude(id=self.id)
......
......@@ -111,3 +111,14 @@ class TestRoundModel(TestCase):
overlapping_start = existing_round.end_date - timedelta(1)
with self.assertRaises(ValidationError):
self.make_round(start_date=overlapping_start, end_date=None)
def test_can_not_overlap_clean(self):
existing_round = self.make_round()
overlapping_start = existing_round.end_date - timedelta(1)
new_round = RoundFactory.build(start_date=overlapping_start, end_date=None)
# we add on the parent page which gets included from a pre_create_hook
new_round.parent_page = self.fund
with self.assertRaises(ValidationError):
new_round.clean()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment