From 409cf1e04a8347ff002deb97dd73f2120573fc60 Mon Sep 17 00:00:00 2001 From: michel Date: Wed, 17 Jan 2018 11:13:49 +0100 Subject: [PATCH] [TMP] Test if date_start date_end is required and vice-versa AND unit test --- golem_season/models/golem_season.py | 7 +++---- golem_season/tests/test_golem_season.py | 9 +++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/golem_season/models/golem_season.py b/golem_season/models/golem_season.py index f2d7aed..9b1dc6e 100644 --- a/golem_season/models/golem_season.py +++ b/golem_season/models/golem_season.py @@ -54,11 +54,10 @@ class GolemSeason(models.Model): """ Check if end date if after start date and if there is no conflict with existing periods """ for season in self: - if season.date_start: - if not season.date_end: + if season.date_start or season.date_end: + if season.date_start and not season.date_end: raise models.ValidationError(_('The date end is required')) - if season.date_end: - if not season.date_start: + elif season.date_end and not season.date_start: raise models.ValidationError(_('The date start is required')) if season.date_start > season.date_end: diff --git a/golem_season/tests/test_golem_season.py b/golem_season/tests/test_golem_season.py index 6d60925..0080c71 100644 --- a/golem_season/tests/test_golem_season.py +++ b/golem_season/tests/test_golem_season.py @@ -55,13 +55,18 @@ class TestGolemSeason(TransactionCase): 'date_start': '2009-11-01', 'date_end': '2011-12-31'}) + + self.assertTrue({'name': 'date_end and date_start is empty', + 'date_start': False, + 'date_end': False}) + with self.assertRaises(ValidationError): - self.season_model.create({'name': 'date_end is nul', + self.season_model.create({'name': 'date_end is empty', 'date_start': '2009-11-01', 'date_end': False}) with self.assertRaises(ValidationError): - self.season_model.create({'name': 'date_start is nul', + self.season_model.create({'name': 'date_start is empty', 'date_start' : False, 'date_end': '2009-11-01'})