def test_out_early(self): """ Test the instance when the student clocks in on time and clocks out early. """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 06, 23, 18, 00, 00), outtime=datetime.datetime(1927, 06, 23, 23, 40, 00), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-06-23' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "23:45:00", "In": "18:00:00", "Shift": 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [{'clock_in': '18:00:00', 'sched_out': '23:45:00', 'clock_out': '23:40:00', 'comm_out': u'OUT: ', 'sched_in': '18:00:00', 'netid': 'user1', 'diff_out_early': datetime.timedelta(0, 300), 'name': u'User 1', 'comm_in': u'IN: '}] expected_no_shows = [] expected_missing_netids = [] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_netids)) shift.delete()
def test_similar_shifts(self): """ This test does not currently pass becuas there is a bug in the code. In the process of fixing it. Supposed to test the instance that the student has two shifts in a 24 hour time span but only works one of the shifts. """ # This shift was worked the day before the day being examined--date = '1927-03-11' shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 11, 02, 18, 49, 20), outtime=datetime.datetime(1927, 11, 02, 22, 21, 25), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-11-03' service = 'dummy_service' # This shift was supposed to be worked on date being examined--'1927-11-03' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "22:15:00", "In": "20:45:00", "Shift": 1}]}}): request = c_utils.compare(date, service) expected_conflict = [] expected_no_show = [{'In': '20:45:00', 'Out': '22:15:00', 'Shift': 1, 'name': 'User 1', 'netid': 'user1'}] expected_missing_netids = [] self.assertEqual(request, (expected_no_show, expected_conflict, expected_missing_netids)) shift.delete()
def test_another_no_show_case(self): """ This test does not currently pass because of a bug in the code that I am working on fixing. Supposed to test when the shifts are more than 23 hours apart from each other but less than 24 hours. """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 03, 12, 14, 12, 41), outtime=datetime.datetime(1927, 03, 12, 19, 02, 06), shiftnote='IN: \n\nOUT:', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "14:45:00", "In": "11:30:00", "Shift": 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [] expected_no_show = [{'In': '11:30:00', 'Out': '14:45:00', 'Shift': 1, 'name': 'User 1', 'netid': 'user1'}] expected_missing_netids = [] self.assertEqual(results, (expected_no_show, expected_conflicts, expected_missing_netids)) shift.delete()
def test_24th_hour(self): """ Tests that time is set to 00:00:00 when time passed in is 24:00:00. This works but creates a bug. """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 03, 11, 18, 49, 20), outtime=datetime.datetime(1927, 03, 11, 23, 59, 06), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "24:00:00", "In": "18:50:00", "Shift": 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [{'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: '}] expected_no_show = [] expected_missing_netids = [] self.assertEqual(results, (expected_no_show, expected_conflicts, expected_missing_netids)) shift.delete()
def test_missing_netid(self): """ Tests the case that a user name returned from the api call that has a user who is not in the database. """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 03, 11, 11, 30, 56), outtime=datetime.datetime(1927, 03, 11, 14, 46, 03), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ 'Shifts': { 'user_none': [{ 'Out': '14:45:00', 'In': '11:30:00', 'Shift': 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [] expected_no_shows = [] expected_missing_netid = ['user_none'] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_netid)) shift.delete()
def test_shiftnote(self): """ Tests when the user deletes the auto filled 'IN: \n\nOUT: ' and putting their own """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 03, 11, 11, 30, 27), outtime=datetime.datetime(1927, 03, 11, 14, 46, 37), shiftnote='I deleted the auto filled stuff and put my own note', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "14:45:00", "In": "11:30:00", "Shift": 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [{'clock_in': '11:30:27', 'sched_out': '14:45:00', 'clock_out': '14:46:37', 'comm_out': u'', 'sched_in': '11:30:00', 'netid': 'user1', 'diff_out_late': datetime.timedelta(0, 97), 'name': u'User 1', 'comm_in': u'I deleted the auto filled stuff and put my own note'}] expected_no_shows = [] expected_missing_ids = [] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_ids)) shift.delete()
def test_no_show_and_conflict(self): """ Tests when the user is scheduled for two shifts in one day but only works one of the shifts. """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 12, 19, 9, 30, 35), outtime=datetime.datetime(1927, 12, 19, 11, 30, 20), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-12-19' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "11:30:00", "In": "09:30:00", "Shift": 1}, {"Out": "18:00:00", "In": "15:00:00", "Shift": 2}]}}): results = c_utils.compare(date, service) expected_conflicts = [{'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: '}] expected_no_shows = [{'In': '15:00:00', 'Out': '18:00:00', 'Shift': 2, 'name': u'User 1', 'netid': 'user1'}] expected_missing_ids = [] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_ids))
def test_no_show(self): """ Tests the instance when the student is scheduled to work a shift but does not work it. """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 02, 11, 11, 30, 27), outtime=datetime.datetime(1927, 02, 11, 14, 46, 37), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "14:45:00", "In": "11:30:00", "Shift": 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [] expected_no_shows = [{'In': '11:30:00', 'Out': '14:45:00', 'Shift': 1, 'name': 'User 1', 'netid': 'user1'}] expected_missing_netids = [] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_netids)) shift.delete()
def test_slightly_late(self): """ Tests the instance that the student clocks out slightly late and clocks in on time. """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 11, 03, 11, 30, 00), outtime=datetime.datetime(1927, 11, 03, 14, 46, 37), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-11-03' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "14:45:00", "In": "11:30:00", "Shift": 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [{'clock_in': '11:30:00', 'sched_in': '11:30:00', 'diff_out_late': datetime.timedelta(0, 97), 'comm_in': u'IN: ', 'clock_out': '14:46:37', 'netid': 'user1', 'name': u'User 1', 'sched_out': '14:45:00', 'comm_out': u'OUT: '}] expected_no_shows = [] expected_missing_netids = [] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_netids)) shift.delete()
def test_shiftnote(self): """ Tests when the user deletes the auto filled 'IN: \n\nOUT: ' and putting their own """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 03, 11, 11, 30, 27), outtime=datetime.datetime(1927, 03, 11, 14, 46, 37), shiftnote='I deleted the auto filled stuff and put my own note', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "14:45:00", "In": "11:30:00", "Shift": 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [{ 'clock_in': '11:30:27', 'sched_out': '14:45:00', 'clock_out': '14:46:37', 'comm_out': u'', 'sched_in': '11:30:00', 'netid': 'user1', 'diff_out_late': datetime.timedelta(0, 97), 'name': u'User 1', 'comm_in': u'I deleted the auto filled stuff and put my own note' }] expected_no_shows = [] expected_missing_ids = [] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_ids)) shift.delete()
def test_no_show_and_conflict(self): """ Tests when the user is scheduled for two shifts in one day but only works one of the shifts. """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 12, 19, 9, 30, 35), outtime=datetime.datetime(1927, 12, 19, 11, 30, 20), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-12-19' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "11:30:00", "In": "09:30:00", "Shift": 1 }, { "Out": "18:00:00", "In": "15:00:00", "Shift": 2 }] } }): results = c_utils.compare(date, service) expected_conflicts = [{ 'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: ' }] expected_no_shows = [{ 'In': '15:00:00', 'Out': '18:00:00', 'Shift': 2, 'name': u'User 1', 'netid': 'user1' }] expected_missing_ids = [] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_ids))
def test_similar_shifts(self): """ This test does not currently pass becuas there is a bug in the code. In the process of fixing it. Supposed to test the instance that the student has two shifts in a 24 hour time span but only works one of the shifts. """ # This shift was worked the day before the day being examined--date = '1927-03-11' shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 11, 02, 18, 49, 20), outtime=datetime.datetime(1927, 11, 02, 22, 21, 25), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-11-03' service = 'dummy_service' # This shift was supposed to be worked on date being examined--'1927-11-03' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "22:15:00", "In": "20:45:00", "Shift": 1 }] } }): request = c_utils.compare(date, service) expected_conflict = [] expected_no_show = [{ 'In': '20:45:00', 'Out': '22:15:00', 'Shift': 1, 'name': 'User 1', 'netid': 'user1' }] expected_missing_netids = [] self.assertEqual( request, (expected_no_show, expected_conflict, expected_missing_netids)) shift.delete()
def test_out_early(self): """ Test the instance when the student clocks in on time and clocks out early. """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 06, 23, 18, 00, 00), outtime=datetime.datetime(1927, 06, 23, 23, 40, 00), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-06-23' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "23:45:00", "In": "18:00:00", "Shift": 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [{ 'clock_in': '18:00:00', 'sched_out': '23:45:00', 'clock_out': '23:40:00', 'comm_out': u'OUT: ', 'sched_in': '18:00:00', 'netid': 'user1', 'diff_out_early': datetime.timedelta(0, 300), 'name': u'User 1', 'comm_in': u'IN: ' }] expected_no_shows = [] expected_missing_netids = [] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_netids)) shift.delete()
def test_slightly_late(self): """ Tests the instance that the student clocks out slightly late and clocks in on time. """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 11, 03, 11, 30, 00), outtime=datetime.datetime(1927, 11, 03, 14, 46, 37), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-11-03' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "14:45:00", "In": "11:30:00", "Shift": 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [{ 'clock_in': '11:30:00', 'sched_in': '11:30:00', 'diff_out_late': datetime.timedelta(0, 97), 'comm_in': u'IN: ', 'clock_out': '14:46:37', 'netid': 'user1', 'name': u'User 1', 'sched_out': '14:45:00', 'comm_out': u'OUT: ' }] expected_no_shows = [] expected_missing_netids = [] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_netids)) shift.delete()
def test_another_no_show_case(self): """ This test does not currently pass because of a bug in the code that I am working on fixing. Supposed to test when the shifts are more than 23 hours apart from each other but less than 24 hours. """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 03, 12, 14, 12, 41), outtime=datetime.datetime(1927, 03, 12, 19, 02, 06), shiftnote='IN: \n\nOUT:', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "14:45:00", "In": "11:30:00", "Shift": 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [] expected_no_show = [{ 'In': '11:30:00', 'Out': '14:45:00', 'Shift': 1, 'name': 'User 1', 'netid': 'user1' }] expected_missing_netids = [] self.assertEqual( results, (expected_no_show, expected_conflicts, expected_missing_netids)) shift.delete()
def test_no_show(self): """ Tests the instance when the student is scheduled to work a shift but does not work it. """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 02, 11, 11, 30, 27), outtime=datetime.datetime(1927, 02, 11, 14, 46, 37), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "14:45:00", "In": "11:30:00", "Shift": 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [] expected_no_shows = [{ 'In': '11:30:00', 'Out': '14:45:00', 'Shift': 1, 'name': 'User 1', 'netid': 'user1' }] expected_missing_netids = [] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_netids)) shift.delete()
def test_24th_hour(self): """ Tests that time is set to 00:00:00 when time passed in is 24:00:00. This works but creates a bug. """ shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 03, 11, 18, 49, 20), outtime=datetime.datetime(1927, 03, 11, 23, 59, 06), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "24:00:00", "In": "18:50:00", "Shift": 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [{ 'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: ' }] expected_no_show = [] expected_missing_netids = [] self.assertEqual( results, (expected_no_show, expected_conflicts, expected_missing_netids)) shift.delete()
def test_missing_netid(self): """ Tests the case that a user name returned from the api call that has a user who is not in the database. """ shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 03, 11, 11, 30, 56), outtime=datetime.datetime(1927, 03, 11, 14, 46, 03), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={'Shifts': {'user_none': [{'Out': '14:45:00', 'In': '11:30:00', 'Shift': 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [] expected_no_shows = [] expected_missing_netid = ['user_none'] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_netid)) shift.delete()
def test_no_show_and_conflicts_2(self): """ Tests when the user if scheduled for 3 shifts in one day but only shows up for two shifts. """ shift1 = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 12, 22, 8, 30, 35), outtime=datetime.datetime(1927, 12, 22, 10, 30, 11), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) shift2 = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 12, 22, 19, 30, 25), outtime=datetime.datetime(1927, 12, 22, 22, 30, 45), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-12-22' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "10:30:00", "In": "8:30:00", "Shift": 1}, {"Out": "15:30:00", "In": "13:30:00", "Shift": 2}, {"Out": "22:30:00", "In": "19:30:00", "Shift": 3}]}}): results = c_utils.compare(date, service) expected_conflicts = [{'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: '}, {'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: '}] expected_no_shows = [{'In': '13:30:00', 'Out': '15:30:00', 'Shift': 2, 'name': u'User 1', 'netid': 'user1'}] expected_missing_ids = [] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_ids)) shift1.delete() shift2.delete()
def test_overnight_shift(self): shift = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 03, 11, 22, 15, 00), outtime=datetime.datetime(1927, 03, 12, 2, 15, 00), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "02:15:00", "In": "22:15:00", "Shift": 1 }] } }): results = c_utils.compare(date, service) expected_conflicts = [{ 'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: ' }] expected_no_shows = [] expected_missing_ids = [] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_ids)) shift.delete()
def test_overnight_shift(self): shift = c_models.Shift.objects.create(person=self.user1, intime=datetime.datetime(1927, 03, 11, 22, 15, 00), outtime=datetime.datetime(1927, 03, 12, 2, 15, 00), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-03-11' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={"Shifts": {"user1": [{"Out": "02:15:00", "In": "22:15:00", "Shift": 1}]}}): results = c_utils.compare(date, service) expected_conflicts = [{'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: '}] expected_no_shows = [] expected_missing_ids = [] self.assertEqual(results, (expected_no_shows, expected_conflicts, expected_missing_ids)) shift.delete()
def test_no_show_and_conflicts_2(self): """ Tests when the user if scheduled for 3 shifts in one day but only shows up for two shifts. """ shift1 = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 12, 22, 8, 30, 35), outtime=datetime.datetime(1927, 12, 22, 10, 30, 11), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) shift2 = c_models.Shift.objects.create( person=self.user1, intime=datetime.datetime(1927, 12, 22, 19, 30, 25), outtime=datetime.datetime(1927, 12, 22, 22, 30, 45), shiftnote='IN: \n\nOUT: ', in_clock=self.pclock, out_clock=self.pclock) date = '1927-12-22' service = 'dummy_service' with patch.object(c_utils, 'read_api', return_value={ "Shifts": { "user1": [{ "Out": "10:30:00", "In": "8:30:00", "Shift": 1 }, { "Out": "15:30:00", "In": "13:30:00", "Shift": 2 }, { "Out": "22:30:00", "In": "19:30:00", "Shift": 3 }] } }): results = c_utils.compare(date, service) expected_conflicts = [{ 'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: ' }, { 'name': u'User 1', 'netid': 'user1', 'comm_in': u'IN: ', 'comm_out': u'OUT: ' }] expected_no_shows = [{ 'In': '13:30:00', 'Out': '15:30:00', 'Shift': 2, 'name': u'User 1', 'netid': 'user1' }] expected_missing_ids = [] self.assertEqual( results, (expected_no_shows, expected_conflicts, expected_missing_ids)) shift1.delete() shift2.delete()