コード例 #1
0
    def test_negative_hours(self):
        self.valid_data['hours'] = -23
        form = TimesheetWithDateRangeForm(data=self.valid_data)

        self.assertFalse(form.is_valid())
        self.assertTrue(form.has_error('hours'))
        self.assertEqual(form.errors['hours'],
                         ['Please provide a positive number of hours to work'])
コード例 #2
0
    def test_working_days_range_not_in_same_year_and_month(self):
        self.valid_data['days_worked'] = '2018-12-15 to 2019-01-15'
        form = TimesheetWithDateRangeForm(data=self.valid_data)

        self.assertFalse(form.is_valid())
        self.assertTrue(form.has_error('days_worked'))
        self.assertEqual(
            form.errors['days_worked'],
            ['First day and last day are not within the same year'])
コード例 #3
0
    def test_too_many_hours_for_days_worked(self):
        self.valid_data['hours'] = 1000
        form = TimesheetWithDateRangeForm(data=self.valid_data)

        self.assertFalse(form.is_valid())
        non_form_errors = form.non_field_errors()
        self.assertTrue(len(non_form_errors))
        self.assertEqual(non_form_errors[0],
                         'Too many hours for specified range of month')
コード例 #4
0
    def test_no_first_name_provided(self):
        del self.valid_data['first_name']
        form = TimesheetWithDateRangeForm(data=self.valid_data)

        self.assertFalse(form.is_valid())
        self.assertTrue(form.has_error('first_name'))
コード例 #5
0
    def test_valid_input_data(self):
        form = TimesheetWithDateRangeForm(data=self.valid_data)

        self.assertTrue(form.is_valid())