class TimecardNoteTests(TestCase): def setUp(self): self.timecard_note_enabled = TimecardNote( title='Enabled test note', body='This is a test note that is enabled.') self.timecard_note_enabled.save() self.timecard_note_disabled = TimecardNote( title='Disabled test note', body='This is a test note that is disabled.', enabled=False) self.timecard_note_disabled.save() def test_get_only_enabled_timecard_notes(self): """Ensure that we are only returning enabled timecard notes.""" # NOTE: There is a migration for an initial timecard note that is # enabled, so we must account for its presence. enabled_timecard_notes = TimecardNote.objects.enabled() self.assertEqual(enabled_timecard_notes.count(), 2) self.assertEqual(enabled_timecard_notes.last(), self.timecard_note_enabled) def test_get_only_disabled_timecard_notes(self): """Ensure that we are only returning disabled timecard notes.""" disabled_timecard_notes = TimecardNote.objects.disabled() self.assertEqual(disabled_timecard_notes.count(), 1) self.assertEqual(disabled_timecard_notes.first(), self.timecard_note_disabled)
def setUp(self): self.timecard_note_enabled = TimecardNote( title='Enabled test note', body='This is a test note that is enabled.') self.timecard_note_enabled.save() self.timecard_note_disabled = TimecardNote( title='Disabled test note', body='This is a test note that is disabled.', enabled=False) self.timecard_note_disabled.save()
def setUp(self): # Ensure that we are dealing with just the two timecard note objects # that we plan on testing. TimecardNote.objects.all().delete() self.timecard_note_enabled = TimecardNote( title='Enabled test note', body='This is a test note that is enabled.') self.timecard_note_enabled.save() self.timecard_note_disabled = TimecardNote( title='Disabled test note', body='This is a test note that is disabled.', enabled=False) self.timecard_note_disabled.save()
def setUp(self): # Ensure that we are dealing with just the timecard note objects # that we plan on testing. TimecardNote.objects.all().delete() self.now = timezone.now() self.timecard_note_enabled = TimecardNote( title='Enabled test note', body='This is a test note that is enabled.' ) self.timecard_note_enabled.save() self.timecard_note_disabled = TimecardNote( title='Disabled test note', body='This is a test note that is disabled.', enabled=False ) self.timecard_note_disabled.save() self.timecard_note_disabled_active_date_range = TimecardNote( title='Disabled active date range note', body='This is a test note that is disabled but has an active date range', enabled=False, display_period_start=self.now - datetime.timedelta(days=5), display_period_end=self.now + datetime.timedelta(days=5) ) self.timecard_note_disabled_active_date_range.save() self.timecard_note_disabled_elapsed_date_range = TimecardNote( title='Disabled elapsed date range note', body='This is a test note that is disabled and has an elapsed date range', enabled=False, display_period_start=self.now - datetime.timedelta(days=5), display_period_end=self.now - datetime.timedelta(days=1) ) self.timecard_note_disabled_elapsed_date_range.save() self.timecard_note_disabled_upcoming_date_range = TimecardNote( title='Disabled upcoming date range note', body='This is a test note that is disabled an has an upcoming date range', enabled=False, display_period_start=self.now + datetime.timedelta(days=5), display_period_end=self.now + datetime.timedelta(days=10) ) self.timecard_note_disabled_upcoming_date_range.save()
def test_end_date_needs_start_date(self): """Tests that during cleaning, we ensure end dates are paired with start dates""" with self.assertRaises(ValidationError): TimecardNote( title='Only has an end date', body='Test note with an end date and no start date', enabled=False, display_period_end=self.now ).full_clean()
class TimecardNoteTests(TestCase): def setUp(self): # Ensure that we are dealing with just the two timecard note objects # that we plan on testing. TimecardNote.objects.all().delete() self.timecard_note_enabled = TimecardNote( title='Enabled test note', body='This is a test note that is enabled.') self.timecard_note_enabled.save() self.timecard_note_disabled = TimecardNote( title='Disabled test note', body='This is a test note that is disabled.', enabled=False) self.timecard_note_disabled.save() def test_get_only_enabled_timecard_notes(self): """Ensure that we are only returning enabled timecard notes.""" enabled_timecard_notes = TimecardNote.objects.enabled() self.assertEqual(enabled_timecard_notes.count(), 1) self.assertEqual(enabled_timecard_notes.last(), self.timecard_note_enabled) def test_get_only_disabled_timecard_notes(self): """Ensure that we are only returning disabled timecard notes.""" disabled_timecard_notes = TimecardNote.objects.disabled() self.assertEqual(disabled_timecard_notes.count(), 1) self.assertEqual(disabled_timecard_notes.first(), self.timecard_note_disabled) def test_timecard_note_default_order(self): """Tests the default ordering of the timecard notes.""" timecard_notes = TimecardNote.objects.all() self.assertEqual(timecard_notes[0].position, self.timecard_note_enabled.position) self.assertEqual(timecard_notes[1].position, self.timecard_note_disabled.position) def test_timecard_note_changed_order(self): """Tests the changed ordering of the timecard notes.""" self.timecard_note_enabled.position = 2 self.timecard_note_enabled.save() self.timecard_note_disabled.position = 1 self.timecard_note_disabled.save() timecard_notes = TimecardNote.objects.all() self.assertEqual(timecard_notes[0].position, self.timecard_note_disabled.position) self.assertEqual(timecard_notes[1].position, self.timecard_note_enabled.position)
def test_start_date_must_precede_end_date(self): """Tests that during cleaning, we only allow start dates that precend end dates""" with self.assertRaises(ValidationError): TimecardNote( title='End date precedes start date', body='Test note with an end date preceding its start date', enabled=False, display_period_start=self.now + datetime.timedelta(days=1), display_period_end=self.now ).full_clean()
class TimecardNoteTests(TestCase): def setUp(self): # Ensure that we are dealing with just the timecard note objects # that we plan on testing. TimecardNote.objects.all().delete() self.now = timezone.now() self.timecard_note_enabled = TimecardNote( title='Enabled test note', body='This is a test note that is enabled.' ) self.timecard_note_enabled.save() self.timecard_note_disabled = TimecardNote( title='Disabled test note', body='This is a test note that is disabled.', enabled=False ) self.timecard_note_disabled.save() self.timecard_note_disabled_active_date_range = TimecardNote( title='Disabled active date range note', body='This is a test note that is disabled but has an active date range', enabled=False, display_period_start=self.now - datetime.timedelta(days=5), display_period_end=self.now + datetime.timedelta(days=5) ) self.timecard_note_disabled_active_date_range.save() self.timecard_note_disabled_elapsed_date_range = TimecardNote( title='Disabled elapsed date range note', body='This is a test note that is disabled and has an elapsed date range', enabled=False, display_period_start=self.now - datetime.timedelta(days=5), display_period_end=self.now - datetime.timedelta(days=1) ) self.timecard_note_disabled_elapsed_date_range.save() self.timecard_note_disabled_upcoming_date_range = TimecardNote( title='Disabled upcoming date range note', body='This is a test note that is disabled an has an upcoming date range', enabled=False, display_period_start=self.now + datetime.timedelta(days=5), display_period_end=self.now + datetime.timedelta(days=10) ) self.timecard_note_disabled_upcoming_date_range.save() def test_get_only_enabled_timecard_notes(self): """Ensure that we are only returning enabled timecard notes.""" enabled_timecard_notes = TimecardNote.objects.enabled() self.assertEqual(enabled_timecard_notes.count(), 1) self.assertEqual( enabled_timecard_notes.last(), self.timecard_note_enabled ) def test_get_only_disabled_timecard_notes(self): """Ensure that we are only returning disabled timecard notes.""" disabled_timecard_notes = TimecardNote.objects.disabled() self.assertEqual(disabled_timecard_notes.count(), 4) self.assertEqual( disabled_timecard_notes[0], self.timecard_note_disabled ) self.assertEqual( disabled_timecard_notes[1], self.timecard_note_disabled_active_date_range ) self.assertEqual( disabled_timecard_notes[2], self.timecard_note_disabled_elapsed_date_range ) self.assertEqual( disabled_timecard_notes[3], self.timecard_note_disabled_upcoming_date_range ) def test_get_only_active_timecard_notes(self): """Ensure that we are only returning active timecard notes.""" active_timecard_notes = TimecardNote.objects.active() self.assertEqual(active_timecard_notes.count(), 2) self.assertEqual( active_timecard_notes[0], self.timecard_note_enabled ) self.assertEqual( active_timecard_notes[1], self.timecard_note_disabled_active_date_range ) def test_start_date_needs_end_date(self): """Tests that during cleaning, we ensure that start dates are paired with end dates""" with self.assertRaises(ValidationError): TimecardNote( title='Only has a start date', body='Test note with a start date and no end date', enabled=False, display_period_start=self.now ).full_clean() def test_end_date_needs_start_date(self): """Tests that during cleaning, we ensure end dates are paired with start dates""" with self.assertRaises(ValidationError): TimecardNote( title='Only has an end date', body='Test note with an end date and no start date', enabled=False, display_period_end=self.now ).full_clean() def test_start_date_must_precede_end_date(self): """Tests that during cleaning, we only allow start dates that precend end dates""" with self.assertRaises(ValidationError): TimecardNote( title='End date precedes start date', body='Test note with an end date preceding its start date', enabled=False, display_period_start=self.now + datetime.timedelta(days=1), display_period_end=self.now ).full_clean() def test_timecard_note_default_order(self): """Tests the default ordering of the timecard notes.""" timecard_notes = TimecardNote.objects.all() self.assertEqual( timecard_notes[0].position, self.timecard_note_enabled.position ) self.assertEqual( timecard_notes[1].position, self.timecard_note_disabled.position ) def test_timecard_note_changed_order(self): """Tests the changed ordering of the timecard notes.""" self.timecard_note_enabled.position = 2 self.timecard_note_enabled.save() self.timecard_note_disabled.position = 1 self.timecard_note_disabled.save() timecard_notes = TimecardNote.objects.all() self.assertEqual( timecard_notes[0].position, self.timecard_note_disabled.position ) self.assertEqual( timecard_notes[1].position, self.timecard_note_enabled.position )