Project

General

Profile

0001-manager-check-time-period-start-end-are-in-correct-o.patch

Frédéric Péters, 14 Mar 2019 02:32 PM

Download (2.75 KB)

View differences:

Subject: [PATCH] manager: check time period start/end are in correct order
 (#31418)

 chrono/manager/forms.py | 10 ++++++++++
 tests/test_manager.py   | 14 ++++++++++++++
 2 files changed, 24 insertions(+)
chrono/manager/forms.py
99 99
    start_time = forms.TimeField(label=_('Start Time'), widget=widgets.TimeWidget())
100 100
    end_time = forms.TimeField(label=_('End Time'), widget=widgets.TimeWidget())
101 101

  
102
    def clean_end_time(self):
103
        if self.cleaned_data['end_time'] <= self.cleaned_data['start_time']:
104
            raise ValidationError(_('End time must come after start time.'))
105
        return self.cleaned_data['end_time']
106

  
102 107

  
103 108
class TimePeriodForm(forms.ModelForm):
104 109
    class Meta:
......
110 115
        }
111 116
        exclude = []
112 117

  
118
    def clean_end_time(self):
119
        if self.cleaned_data['end_time'] <= self.cleaned_data['start_time']:
120
            raise ValidationError(_('End time must come after start time.'))
121
        return self.cleaned_data['end_time']
122

  
113 123

  
114 124
class NewDeskForm(forms.ModelForm):
115 125
    class Meta:
tests/test_manager.py
676 676
    assert u'Wednesday / 10 a.m. → 5 p.m.' in resp.text
677 677
    assert resp.text.index('Monday') < resp.text.index('Wednesday')
678 678

  
679
    # invert start and end
680
    resp2 = resp.click('Add a time period', index=0)
681
    resp2.form['weekdays-0'].checked = True
682
    resp2.form['start_time'] = '13:00'
683
    resp2.form['end_time'] = '10:00'
684
    resp2 = resp2.form.submit()
685
    assert 'End time must come after start time.' in resp2.text
686

  
679 687
    # and edit
680 688
    resp = resp.click(u'Wednesday / 10 a.m. → 5 p.m.')
681 689
    assert 'Edit Time Period' in resp.text
......
684 692
    resp = resp.follow()
685 693
    assert TimePeriod.objects.get(desk=desk, weekday=2).start_time.hour == 9
686 694

  
695
    # and edit with inverted start/end
696
    resp2 = resp.click(u'Wednesday / 9 a.m. → 5 p.m.')
697
    resp2.form['start_time'] = '18:00'
698
    resp2 = resp2.form.submit()
699
    assert 'End time must come after start time.' in resp2.text
700

  
687 701
    # and add same time periods on multiple days
688 702
    resp = resp.click('Add a time period', index=0)
689 703
    resp.form['weekdays-4'].checked = True
690
-