class TestRequestFactory(unittest.TestCase): def setUp(self): self.request_factory = RequestFactory() @mock.patch('xcrawler.http.requests.request.Request') def test_create_request(self, mock_request_class): mock_method = "GET" mock_url = "http://example.com/path/to/mock_url.html" mock_request = mock.create_autospec(Request).return_value mock_request_class.return_value = mock_request result = self.request_factory.create_request(mock_method, mock_url) self.assertEquals(result, mock_request)
def __init__(self, url, page_scraper, request_factory=RequestFactory(), extractor_factory=ExtractorFactory(), url_joiner=UrlJoiner(), request_sender=RequestSender(), compatibility_factory=CompatibilityFactory()): self.url = url self.scraper = page_scraper self._content = None self.extractor = None self.request_factory = request_factory self.request = self.request_factory.create_request('GET', self.url) self.extractor_factory = extractor_factory self.url_joiner = url_joiner self.request_sender = request_sender self.string_converter = compatibility_factory.create_compatible_string_converter( )
def setUp(self): self.request_factory = RequestFactory()