Пример #1
0
 def test_no_zero_hours_saved(self):
     """Tests that TimecardObject's with None or 0 hours are not entered
     into the database on form submission."""
     form_data = {
         'timecardobjects-TOTAL_FORMS': '1',
         'timecardobjects-INITIAL_FORMS': '0',
         'timecardobjects-MIN_NUM_FORMS': '',
         'timecardobjects-MAX_NUM_FORMS': '',
         'timecardobjects-0-project': '4',
         'timecardobjects-0-hours_spent': ''
     }
     formset = TimecardFormSet(form_data)
     formset.is_valid()
     self.assertTrue(formset[0].cleaned_data['DELETE'])
Пример #2
0
 def test_one_project_with_notes_and_one_without_notes_is_invalid(self):
     """ Test the timecard form when one entry requires notes and another
     entry does not, and the notes are not filled in"""
     form_data = self.form_data()
     form_data['timecardobject_set-0-project'] = '2'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #3
0
 def test_one_project_with_notes_and_one_without_notes_is_invalid(self):
     """ Test the timecard form when one entry requires notes and another
     entry does not, and the notes are not filled in"""
     form_data = self.form_data()
     form_data['timecardobjects-0-project'] = '2'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #4
0
 def test_timecard_is_not_100(self):
   form_data = self.form_data()
   form_data['timecardobject_set-2-project'] = '6'
   form_data['timecardobject_set-2-hours_spent'] = '20'
   form_data['timecardobject_set-TOTAL_FORMS'] = '3'
   formset = TimecardFormSet(form_data)
   self.assertFalse(formset.is_valid())
Пример #5
0
 def test_timecard_is_too_big(self):
     """ Test timecard form data that exceeds the maximum hours allowed """
     form_data = self.form_data()
     form_data['timecardobjects-2-project'] = '6'
     form_data['timecardobjects-2-hours_spent'] = '50'
     form_data['timecardobjects-TOTAL_FORMS'] = '3'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #6
0
 def test_timecard_is_too_small(self):
     """ Test timecard form data that is smaller than the minimum
     allowable hours """
     form_data = self.form_data()
     form_data['timecardobjects-1-project'] = '6'
     form_data['timecardobjects-1-hours_spent'] = '10'
     form_data['timecardobjects-TOTAL_FORMS'] = '2'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #7
0
 def test_reporting_period_with_less_than_min_hours_failure(self):
     """ Test the timecard form when the reporting period requires at least
     16 hours to be reported and the hours entered are less than 16"""
     form_data = self.form_data()
     form_data['timecardobjects-0-hours_spent'] = '5'
     form_data['timecardobjects-1-hours_spent'] = '5'
     formset = TimecardFormSet(form_data)
     formset.set_min_working_hours(16)
     self.assertFalse(formset.is_valid())
Пример #8
0
 def test_timecard_is_not_100(self):
     """ Test timecard form data that doesn't total the set working
     hours """
     form_data = self.form_data()
     form_data['timecardobject_set-2-project'] = '6'
     form_data['timecardobject_set-2-hours_spent'] = '20'
     form_data['timecardobject_set-TOTAL_FORMS'] = '3'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #9
0
 def test_timecard_has_0_hours_for_project(self):
     """ Test timecard form data has an 0 hours spent value for
     a project """
     form_data = self.form_data()
     form_data['timecardobject_set-2-project'] = '6'
     form_data['timecardobject_set-2-hours_spent'] = 0
     form_data['timecardobject_set-TOTAL_FORMS'] = '3'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #10
0
 def test_reporting_period_with_less_than_40_hours_failure(self):
     """ Test the timecard form when the reporting period is less than
     40 hours a week and the hours entered do not match the working hours"""
     form_data = self.form_data()
     form_data['timecardobject_set-0-hours_spent'] = '5'
     form_data['timecardobject_set-1-hours_spent'] = '5'
     formset = TimecardFormSet(form_data)
     formset.set_working_hours(16)
     self.assertFalse(formset.is_valid())
Пример #11
0
 def test_reporting_period_with_less_than_40_hours_failure(self):
     """ Test the timecard form when the reporting period is less than
     40 hours a week and the hours entered do not match the working hours"""
     form_data = self.form_data()
     form_data['timecardobject_set-0-hours_spent'] = '5'
     form_data['timecardobject_set-1-hours_spent'] = '5'
     formset = TimecardFormSet(form_data)
     formset.set_working_hours(16)
     self.assertFalse(formset.is_valid())
Пример #12
0
 def test_reporting_period_with_more_than_max_hours_failure(self):
     """ Test the timecard form when the reporting period requires no more
     than 60 hours to be reported and the hours entered are more than 60"""
     form_data = self.form_data()
     form_data['timecardobjects-0-hours_spent'] = '50'
     form_data['timecardobjects-1-hours_spent'] = '20'
     formset = TimecardFormSet(form_data)
     formset.set_max_working_hours(60)
     self.assertFalse(formset.is_valid())
Пример #13
0
 def test_timecard_is_not_100(self):
     """ Test timecard form data that doesn't total the set working
     hours """
     form_data = self.form_data()
     form_data['timecardobject_set-2-project'] = '6'
     form_data['timecardobject_set-2-hours_spent'] = '20'
     form_data['timecardobject_set-TOTAL_FORMS'] = '3'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #14
0
 def test_timecard_has_empty_project(self):
     """ Test timecard form data has an empty hours spent value for
     a project """
     form_data = self.form_data()
     form_data['timecardobject_set-2-project'] = '6'
     form_data['timecardobject_set-2-hours_spent'] = None
     form_data['timecardobject_set-TOTAL_FORMS'] = '3'
     formset = TimecardFormSet(form_data)
     self.assertFalse(formset.is_valid())
Пример #15
0
 def test_timecard_has_0_hours_for_project(self):
     """ Test timecard form data has an 0 hours spent value for
     a project """
     form_data = self.form_data()
     form_data['timecardobjects-2-project'] = '6'
     form_data['timecardobjects-2-hours_spent'] = 0
     form_data['timecardobjects-TOTAL_FORMS'] = '3'
     formset = TimecardFormSet(form_data)
     self.assertTrue(formset.is_valid())
Пример #16
0
 def test_reporting_period_with_less_than_40_hours_success_save_mode(self):
     """ Test the timecard form when the reporting period is less than
     40 hours a week and you save (not submit) """
     form_data = self.form_data()
     form_data['timecardobject_set-0-hours_spent'] = '5'
     form_data['timecardobject_set-1-hours_spent'] = '5'
     formset = TimecardFormSet(form_data)
     formset.set_working_hours(16)
     formset.save_only = True
     self.assertTrue(formset.is_valid())
Пример #17
0
 def test_reporting_period_with_less_than_min_hours_success_save_mode(self):
     """ Test the timecard form when the reporting period is less than
     minimum required hours a period and you save (not submit) """
     form_data = self.form_data()
     form_data['timecardobjects-0-hours_spent'] = '5'
     form_data['timecardobjects-1-hours_spent'] = '5'
     formset = TimecardFormSet(form_data)
     formset.set_min_working_hours(16)
     formset.save_only = True
     self.assertTrue(formset.is_valid())
Пример #18
0
 def test_aws_timecard_is_wrong_size(self):
     """ Test timecard form data does not abide by min/max hours if
     user is alternative work schedule eligible. """
     # Too small.
     form_data = self.form_data()
     form_data['timecardobjects-1-project'] = '6'
     form_data['timecardobjects-1-hours_spent'] = '10'
     form_data['timecardobjects-TOTAL_FORMS'] = '2'
     formset = TimecardFormSet(form_data)
     formset.aws_eligible = True
     self.assertTrue(formset.is_valid())
     # Too large
     form_data = self.form_data()
     form_data['timecardobjects-1-project'] = '6'
     form_data['timecardobjects-1-hours_spent'] = '50'
     form_data['timecardobjects-TOTAL_FORMS'] = '2'
     formset = TimecardFormSet(form_data)
     formset.aws_eligible = True
     self.assertTrue(formset.is_valid())
Пример #19
0
    def test_timecard_inline_formset_modify_saved(self):
        """Users can swap project IDs between TimeCardObjects """
        form_data = self.initial_form_data
        formset = TimecardFormSet(form_data, instance=self.timecard)
        # Save these timecard entries for later modification
        formset.save_only = True
        formset.is_valid()
        formset.save()

        # We've got a saved timecard, lets try to edit it by swapping the projects
        project5 = self.timecard.timecardobjects.get(project_id=5)
        project4 = self.timecard.timecardobjects.get(project_id=4)
        form_data.update({
            'timecardobjects-0-id': project4.id,
            'timecardobjects-1-id': project5.id,
            'timecardobjects-0-project': '5',
            'timecardobjects-1-project': '4',
            'timecardobjects-INITIAL_FORMS': '2'
        })
        formset = TimecardFormSet(form_data, instance=self.timecard)
        formset.is_valid()
        formset.save()
Пример #20
0
 def test_timecard_inline_formset_valid(self):
     """ Test valid timecard data """
     form_data = self.form_data()
     formset = TimecardFormSet(form_data)
     self.assertTrue(formset.is_valid())
Пример #21
0
 def test_timecard_inline_formset_valid(self):
     """ Test valid timecard data """
     form_data = self.form_data()
     formset = TimecardFormSet(form_data)
     self.assertTrue(formset.is_valid())