[TMP] Test if date_start date_end is required and vice-versa AND unit test

This commit is contained in:
michel 2018-01-17 11:13:49 +01:00
parent 6bc231fd1e
commit 409cf1e04a
2 changed files with 10 additions and 6 deletions

View File

@ -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:

View File

@ -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'})