def test_scraper_object_created(self, wait_till_next_session, datetime, wait_till_start_time, Scraper, *args, **kwargs): wait_till_next_session.side_effect = ErrorAfter(0) command = Command() try: command.handle(**{'start': None, 'frequency': 86400, 'log': 'scraper.log'}) except CallableExhausted: pass Scraper.assert_called_once_with()
def test_handle_calls_convert_start_time(self, wait_till_next_session, datetime, wait_till_start_time, Scraper, convert_start_to_datetime, timezone): wait_till_next_session.side_effect = ErrorAfter(0) command = Command() try: command.handle(**{'start': None, 'frequency': 86400, 'log': 'scraper.log'}) except CallableExhausted: pass convert_start_to_datetime.assert_called_once_with(start=None)
def test_waits_till_next_session(self, wait_till_next_session, datetime, wait_till_start_time, Scraper, convert_start_to_datetime, timezone): wait_till_next_session.side_effect = ErrorAfter(2) command = Command() try: command.handle(**{'start': None, 'frequency': 86400, 'log': 'scraper.log'}) except CallableExhausted: pass self.assertEqual(wait_till_next_session.call_count, 3)
def test_get_previous_session_called(self, Session, wait_till_next_session, datetime, wait_till_start_time, Scraper, convert_start_to_datetime, timezone): wait_till_next_session.side_effect = ErrorAfter(2) command = Command() try: command.handle(**{'start': None, 'frequency': 86400, 'log': 'scraper.log'}) except CallableExhausted: pass Session.get_previous_session.assert_has_calls([mock.call(), mock.call(), mock.call()], any_order=True)
def test_scraper_calls_scrape(self, wait_till_next_session, datetime, wait_till_start_time, Scraper, convert_start_to_datetime, timezone): wait_till_next_session.side_effect = ErrorAfter(2) command = Command() try: command.handle(**{'start': None, 'frequency': 86400, 'log': 'scraper.log'}) except CallableExhausted: pass Scraper().scrape.assert_has_calls([ mock.call(), mock.call(), mock.call()])
def test_scraper_calls_configure(self, Session, wait_till_next_session, datetime, wait_till_start_time, Scraper, convert_start_to_datetime, timezone): wait_till_next_session.side_effect = ErrorAfter(2) timezone.now.return_value.__gt__.return_value = False command = Command() try: command.handle(**{'start': None, 'frequency': 86400, 'log': 'scraper.log'}) except CallableExhausted: pass Scraper().configure.assert_has_calls([ mock.call(convert_start_to_datetime.return_value, Session.get_previous_session.return_value), ])