コード例 #1
0
    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()
コード例 #2
0
    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)
コード例 #3
0
 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)
コード例 #4
0
    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)
コード例 #5
0
    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()])
コード例 #6
0
    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),
        ])