def test_get_headers_with_user_specific_headers(self): translator = GoogleTranslator() # This should overwrite the default Host header translator._user_specific_headers = {"Host": "test.com"} expected_headers = dict(translator._default_headers) expected_headers["Host"] = "test.com" self.assertListEqual(translator._get_headers(), expected_headers.items())
def test_get_headers_with_user_specific_headers_and_uaselector(self): mock_ua_selector = mock.MagicMock() translator = GoogleTranslator(ua_selector=mock_ua_selector) # This should overwrite both the default user-agent and the uaselector translator._user_specific_headers = {"User-Agent": "user_spec_ua"} expected_headers = dict(translator._default_headers) expected_headers["User-Agent"] = "user_spec_ua" self.assertListEqual(translator._get_headers(), expected_headers.items())
def test_get_headers_default_with_uaselector(self): mock_ua_selector = mock.MagicMock() translator = GoogleTranslator(ua_selector=mock_ua_selector) # Test get_useragent retvalue is not None mock_ua_selector.get_useragent.return_value = "user-agent1" expected_headers = dict(translator._default_headers) expected_headers[ "User-Agent"] = mock_ua_selector.get_useragent.return_value self.assertListEqual(translator._get_headers(), expected_headers.items()) mock_ua_selector.get_useragent.assert_called_once() mock_ua_selector.reset_mock() # Test get_useragent retvalue is None mock_ua_selector.get_useragent.return_value = None self.assertListEqual(translator._get_headers(), translator._default_headers.items()) mock_ua_selector.get_useragent.assert_called_once()
def test_get_headers_default(self): translator = GoogleTranslator() self.assertListEqual(translator._get_headers(), translator._default_headers.items())