def test_from_crawler(self, mocked_hsref):
     crawler_mock = mock.Mock()
     crawler_mock.settings = Settings()
     self.assertRaises(NotConfigured, PageStorageMiddleware.from_crawler,
                       crawler_mock)
     # test creating an instance for all other cases
     crawler_mock.settings = mock.Mock()
     mocked_values = [(True, False), (False, True), (True, True)]
     crawler_mock.settings.side_effect = mocked_values
     for _ in range(len(mocked_values)):
         assert isinstance(PageStorageMiddleware.from_crawler(crawler_mock),
                           PageStorageMiddleware)
 def test_from_crawler(self, mocked_hsref):
     crawler_mock = mock.Mock()
     crawler_mock.settings = Settings()
     self.assertRaises(NotConfigured,
                       PageStorageMiddleware.from_crawler,
                       crawler_mock)
     # test creating an instance for all other cases
     crawler_mock.settings = mock.Mock()
     mocked_values = [(True, False), (False, True), (True, True)]
     crawler_mock.settings.side_effect = mocked_values
     for _ in range(len(mocked_values)):
         assert isinstance(PageStorageMiddleware.from_crawler(crawler_mock),
                           PageStorageMiddleware)
Example #3
0
 def setUp(self):
     self.spider = Spider('default')
     self.mocked_hsref = mock.Mock()
     self.patch = mock.patch('sh_scrapy.hsref.hsref', self.mocked_hsref)
     self.crawler_mock = mock.Mock()
     self.crawler_mock.settings = Settings(
         {'PAGE_STORAGE_ENABLED': True,
          'PAGE_STORAGE_MODE': 'VERSIONED_CACHE',
          'PAGE_STORAGE_LIMIT': 10,
          'PAGE_STORAGE_ON_ERROR_LIMIT': 5})
     self.mocked_hsref.project.collections.url = '/test/url'
     self.patch.start()
     self.instance = PageStorageMiddleware.from_crawler(self.crawler_mock)
 def setUp(self):
     self.spider = Spider('default')
     self.mocked_hsref = mock.Mock()
     self.patch = mock.patch('sh_scrapy.hsref.hsref', self.mocked_hsref)
     crawler_mock = mock.Mock()
     crawler_mock.settings = Settings(
         {'PAGE_STORAGE_ENABLED': True,
          'PAGE_STORAGE_MODE': 'VERSIONED_CACHE',
          'PAGE_STORAGE_LIMIT': 10,
          'PAGE_STORAGE_ON_ERROR_LIMIT': 5})
     self.mocked_hsref.project.collections.url = '/test/url'
     self.patch.start()
     self.instance = PageStorageMiddleware.from_crawler(crawler_mock)