agendas: add handling for 0 minute meeting type (#49688)

This commit is contained in:
Valentin Deniaud 2020-12-23 10:56:49 +01:00
parent 1d6bf6767b
commit be7df7e07c
3 changed files with 16 additions and 2 deletions

View File

@ -294,6 +294,8 @@ class Agenda(models.Model):
gcd = durations[0]
for duration in durations[1:]:
gcd = math.gcd(duration, gcd)
if gcd == 0:
raise ValueError()
return gcd
def export_json(self):
@ -789,7 +791,7 @@ class MeetingType(models.Model):
agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE)
label = models.CharField(_('Label'), max_length=150)
slug = models.SlugField(_('Identifier'), max_length=160)
duration = models.IntegerField(_('Duration (in minutes)'), default=30)
duration = models.IntegerField(_('Duration (in minutes)'), default=30, validators=[MinValueValidator(1)])
deleted = models.BooleanField(_('Deleted'), default=False)
class Meta:

View File

@ -600,6 +600,12 @@ def test_base_meeting_duration():
agenda = Agenda(label='Meeting', kind='meetings')
agenda.save()
with pytest.raises(ValueError):
agenda.get_base_meeting_duration()
meeting_type = MeetingType(agenda=agenda, label='Foo', duration=0)
meeting_type.save()
with pytest.raises(ValueError):
agenda.get_base_meeting_duration()

View File

@ -1847,9 +1847,15 @@ def test_meetings_agenda_add_meeting_type(app, admin_user):
assert "This agenda doesn't have any meeting type yet." in resp.text
resp = resp.click('New Meeting Type')
resp.form['label'] = 'Blah'
resp.form['duration'] = '60'
resp.form['duration'] = '0'
assert 'deleted' not in resp.form.fields
resp = resp.form.submit()
assert 'Ensure this value is greater than or equal to 1.' in resp.text
assert not MeetingType.objects.exists()
resp.form['duration'] = '60'
resp = resp.form.submit()
meeeting_type = MeetingType.objects.get(agenda=agenda)
assert meeeting_type.label == 'Blah'
assert meeeting_type.duration == 60