def test_is_late(self): """ Check if the user is late when no Timecard is present """ userdata = UserData.objects.get(user=self.regular_user) reporting_period = ReportingPeriod(start_date=datetime.date( 2015, 1, 1), end_date=datetime.date(2015, 1, 7), exact_working_hours=40, min_working_hours=40, max_working_hours=60, message='This is not a vacation') reporting_period.save() self.assertEqual(userdata.is_late, True)
class ReportingPeriodTests(TestCase): def setUp(self): self.reporting_period = ReportingPeriod( start_date=datetime.date(2015, 1, 1), end_date=datetime.date(2015, 1, 7), exact_working_hours=40, min_working_hours=40, max_working_hours=60, message='This is not a vacation') self.reporting_period.save() def test_reporting_period_save(self): """Ensure that data was saved properly.""" reporting_period = ReportingPeriod.objects.first() self.assertEqual(40, reporting_period.exact_working_hours) self.assertEqual(datetime.date(2015, 1, 1), reporting_period.start_date) self.assertEqual(datetime.date(2015, 1, 7), reporting_period.end_date) self.assertEqual('This is not a vacation', reporting_period.message) self.assertEqual(40, reporting_period.min_working_hours) self.assertEqual(60, reporting_period.max_working_hours) def test_unique_constraint(self): """ Check that unique constrains work for reporting period.""" with self.assertRaises(ValidationError): ReportingPeriod(start_date=datetime.date(2015, 1, 1), end_date=datetime.date(2015, 1, 7), exact_working_hours=40).save() def test_get_fiscal_year(self): """Check to ensure the proper fiscal year is returned.""" self.assertEqual(2015, self.reporting_period.get_fiscal_year()) reporting_period_2 = ReportingPeriod( start_date=datetime.date(2015, 10, 31), end_date=datetime.date(2015, 11, 7), exact_working_hours=32) self.assertEqual(2016, reporting_period_2.get_fiscal_year())
class ReportingPeriodTests(TestCase): def setUp(self): self.reporting_period = ReportingPeriod( start_date=datetime.date(2015, 1, 1), end_date=datetime.date(2015, 1, 7), exact_working_hours=40, min_working_hours=40, max_working_hours=60, message='This is not a vacation') self.reporting_period.save() def test_reporting_period_save(self): """Ensure that data was saved properly.""" reporting_period = ReportingPeriod.objects.first() self.assertEqual(40, reporting_period.exact_working_hours) self.assertEqual( datetime.date(2015, 1, 1), reporting_period.start_date) self.assertEqual(datetime.date(2015, 1, 7), reporting_period.end_date) self.assertEqual('This is not a vacation', reporting_period.message) self.assertEqual(40, reporting_period.min_working_hours) self.assertEqual(60, reporting_period.max_working_hours) def test_unique_constraint(self): """ Check that unique constrains work for reporting period.""" with self.assertRaises(ValidationError): ReportingPeriod( start_date=datetime.date(2015, 1, 1), end_date=datetime.date(2015, 1, 7), exact_working_hours=40).save() def test_get_fiscal_year(self): """Check to ensure the proper fiscal year is returned.""" self.assertEqual(2015, self.reporting_period.get_fiscal_year()) reporting_period_2 = ReportingPeriod( start_date=datetime.date(2015, 10, 31), end_date=datetime.date(2015, 11, 7), exact_working_hours=32) self.assertEqual(2016, reporting_period_2.get_fiscal_year()) # Testing the week that spans two FYs reporting_period_3 = ReportingPeriod( start_date=datetime.date(2014, 9, 28), end_date=datetime.date(2014, 10, 4), exact_working_hours=32) self.assertEqual(2015, reporting_period_3.get_fiscal_year()) reporting_period_4 = ReportingPeriod( start_date=datetime.date(2015, 9, 27), end_date=datetime.date(2015, 10, 3), exact_working_hours=32) self.assertEqual(2015, reporting_period_4.get_fiscal_year()) def test_get_fiscal_year_start_date(self): # test more October date than September date self.assertEqual(datetime.date(2014, 9, 28), ReportingPeriod.get_fiscal_year_start_date(2015)) # test more September date than October date self.assertEqual(datetime.date(2015, 10, 4), ReportingPeriod.get_fiscal_year_start_date(2016)) # test fiscal year starts right on 10/1 self.assertEqual(datetime.date(2017, 10, 1), ReportingPeriod.get_fiscal_year_start_date(2018)) def test_get_fiscal_year_end_date(self): # test more October date than September date self.assertEqual(datetime.date(2014, 9, 27), ReportingPeriod.get_fiscal_year_end_date(2014)) # test more September date than October date self.assertEqual(datetime.date(2015, 10, 3), ReportingPeriod.get_fiscal_year_end_date(2015)) # test fiscal year ends right on 9/30 self.assertEqual(datetime.date(2017, 9, 30), ReportingPeriod.get_fiscal_year_end_date(2017))