def test_validate_url_string_caches_tls_support(clear_tls_cache, monkeypatch): url_string = 'commons.wikimedia.org/wiki/User:potato' with patch.object(urls.requests, 'get', return_value=requests.Response()) as mock_get: actual_validated_url_1 = urls.validate_url_string(url_string) actual_validated_url_2 = urls.validate_url_string(url_string) expect_validated_url = 'https://commons.wikimedia.org/wiki/User:potato' assert actual_validated_url_1 == expect_validated_url assert actual_validated_url_2 == expect_validated_url mock_get.assert_called_once()
def prepare_string(self, value): """ Returns input unchanged, as long as it is a valid URL string. Also enforces the character limit of the column. If the input value fails a validation, returns None. """ if self._Column__sanitize_string(value) != value: return None else: return self._Column__enforce_char_limit( urls.validate_url_string(value), self.SIZE, False)
def test_validate_url_string_handles_wmc_type_scheme(clear_tls_cache, get_good): url_string = '//commons.wikimedia.org/wiki/User:potato' actual_validated_url = urls.validate_url_string(url_string) expect_validated_url = 'https://commons.wikimedia.org/wiki/User:potato' assert actual_validated_url == expect_validated_url
def test_validate_url_string_adds_to_ip_address(clear_tls_cache, get_good): url_string = '8.8.8.8' actual_validated_url = urls.validate_url_string(url_string) expect_validated_url = 'https://8.8.8.8' assert actual_validated_url == expect_validated_url
def test_validate_url_string_upgrades_scheme(clear_tls_cache, get_good): url_string = 'http://abcd.com' actual_validated_url = urls.validate_url_string(url_string) expect_validated_url = 'https://abcd.com' assert actual_validated_url == expect_validated_url
def test_validate_url_string_nones_with_invalid_structure_domain( clear_tls_cache, get_bad): url_string = 'https:/abcd' actual_validated_url = urls.validate_url_string(url_string) assert actual_validated_url is None
def test_validate_url_string_adds_http_without_scheme(clear_tls_cache, get_bad): url_string = 'creativecomons.org' actual_validated_url = urls.validate_url_string(url_string) expect_validated_url = 'http://creativecomons.org' assert actual_validated_url == expect_validated_url