Example #1
0
 def test_all_from_month_with_in_memory_repo(self):
     events_repo = EventsRepo(EventsInMemoryRepo())
     events = events_repo.all()
     self.assertEqual(
         str(events),
         'asdf 2019-10-01 07:20:00 entrada\nqwer 2019-10-01 14:35:00 salida\nzxcv 2019-10-15 07:05:30 entrada\nzxcv 2019-10-15 08:05:30 salida\nzxcv 2019-10-15 09:05:30 entrada\nzxcv 2019-10-15 09:15:30 salida\nzxcv 2019-10-15 10:05:30 entrada\nzxcv 2019-10-16 07:05:30 entrada'
     )
Example #2
0
 def test_save_with_error(self):
     persistence_mock = Mock()
     event_mock = Mock()
     persistence_mock.save.return_value = False
     events_repo = EventsRepo(persistence=persistence_mock)
     saved = events_repo.save(event_mock)
     persistence_mock.save.assert_called_once_with(event_mock)
     self.assertFalse(saved)
Example #3
0
 def test_get_month(self, datetime_mock):
     datetime_mock.today.return_value = datetime(2019, 9, 1)
     datetime_mock.strptime = datetime.strptime
     persistence_mock = Mock()
     events_repo = EventsRepo(persistence=persistence_mock)
     events_repo.get_month()
     persistence_mock.get_from_interval\
         .assert_called_once_with(init='2019-09-01', end='2019-09-30')
Example #4
0
 def test_get_from_today_with_in_memory_repo(self):
     event_to_save = Event('asdf', datetime.today().date().isoformat(), \
         datetime.today().time().isoformat('seconds'), 'entrada')
     event_in_memory_repo = EventsInMemoryRepo()
     event_in_memory_repo.save(event_to_save)
     events_repo = EventsRepo(event_in_memory_repo)
     events = events_repo.get_from_today()
     self.assertListEqual(events.events, [event_to_save])
Example #5
0
 def test_save(self):
     event_to_save = Event('asdf', datetime.today().date().isoformat(), \
         datetime.today().time().isoformat('seconds'), 'entrada')
     events_repo = EventsRepo(EventsInMemoryRepo())
     events = events_repo.get_from_today()
     self.assertListEqual(events.events, [])
     saved = events_repo.save(event_to_save)
     self.assertTrue(saved)
     events = events_repo.get_from_today()
     self.assertListEqual(events.events, [event_to_save])
Example #6
0
 def test_with_command_get_events_from_this_month(self):
     command = GetEventsFromThisMonth(EventsRepo(EventsInMemoryRepo()))
     console_events_result = ConsoleEventsResult(command, self.resource)
     console_events = console_events_result.get()
     self.assertEqual(console_events, ({
         '2019-10-01': [{
             'event_type': 'entrada',
             'time': '07:20:00'
         }, {
             'event_type': 'salida',
             'time': '14:35:00'
         }],
         '2019-10-15': [{
             'event_type': 'entrada',
             'time': '07:05:30'
         }, {
             'event_type': 'salida',
             'time': '08:05:30'
         }, {
             'event_type': 'entrada',
             'time': '09:05:30'
         }, {
             'event_type': 'salida',
             'time': '09:15:30'
         }, {
             'event_type': 'entrada',
             'time': '10:05:30'
         }],
         '2019-10-16': [{
             'event_type': 'entrada',
             'time': '07:05:30'
         }]
     }, 0))
Example #7
0
 def test_with_exception_no_resource(self):
     command = GetEventsFromToday(EventsRepo(EventsInMemoryRepo()))
     console_events_result = ConsoleEventsResult(None, None)
     console_events_result.set_command(command)
     console_events = console_events_result.get()
     self.assertEqual(console_events, ({
         'message': 'Result needs resource.'
     }, 1))
Example #8
0
 def test_with_command_get_events_from_today_setting_command_and_resource_after(
         self):
     command = GetEventsFromToday(EventsRepo(EventsInMemoryRepo()))
     console_events_result = ConsoleEventsResult(None, None)
     console_events_result.set_command(command)
     console_events_result.set_resource(self.resource)
     console_events = console_events_result.get()
     self.assertEqual(console_events, ({}, 0))
 def setUpClass(cls):
     super(GetEventsFromThisMonthTestCase, cls).setUpClass()
     cls._repo = EventsRepo(EventsInMemoryRepo())
     cls._events = Events([
         Event('asdf', '2019-10-01', '07:20:00', 'entrada'),
         Event('qwer', '2019-10-01', '14:35:00', 'salida'),
         Event('zxcv', '2019-10-15', '07:05:30', 'entrada'),
         Event('zxcv', '2019-10-15', '08:05:30', 'salida'),
         Event('zxcv', '2019-10-15', '09:05:30', 'entrada'),
         Event('zxcv', '2019-10-15', '09:15:30', 'salida'),
         Event('zxcv', '2019-10-15', '10:05:30', 'entrada'),
         Event('zxcv', '2019-10-16', '07:05:30', 'entrada'),
     ])
Example #10
0
 def test_get_from_today(self, datetime_mock):
     datetime_mock.today.return_value = datetime(2019, 10, 1)
     persistence_mock = Mock()
     events_repo = EventsRepo(persistence=persistence_mock)
     events_repo.get_from_today()
     persistence_mock.get_from_date.assert_called_once_with('2019-10-01')
Example #11
0
 def test_all(self):
     persistence_mock = Mock()
     events_repo = EventsRepo(persistence=persistence_mock)
     events_repo.all()
     persistence_mock.find_all.assert_called_once()
Example #12
0
 def test_get_from_date(self):
     persistence_mock = Mock()
     events_repo = EventsRepo(persistence=persistence_mock)
     events_repo.get_from_date('2019-10-01')
     persistence_mock.get_from_date.assert_called_once_with('2019-10-01')
Example #13
0
 def test_get_from_date_with_in_memory_repo(self):
     events_repo = EventsRepo(EventsInMemoryRepo())
     events = events_repo.get_from_date('2019-10-16')
     self.assertEqual(str(events), 'zxcv 2019-10-16 07:05:30 entrada')
Example #14
0
 def test_with_command_get_events_from_today(self):
     command = GetEventsFromToday(EventsRepo(EventsInMemoryRepo()))
     html_events_result = HtmlEventsResult(command, self.resource)
     html_events = html_events_result.get()
     self.assertEqual(html_events, ({'events': {}}, 200))
Example #15
0
 def test_with_command_get_events_from_today(self):
     command = GetEventsFromToday(EventsRepo(EventsInMemoryRepo()))
     console_events_result = ConsoleEventsResult(command, self.resource)
     console_events = console_events_result.get()
     self.assertEqual(console_events, ({}, 0))