def setUp(self): self.unicode_param = 'значение' # Python 2.6 requires bytes for quote self.urlencoded_param = quote(self.unicode_param.encode('utf8')) url = 'http://www.google.com/blog/article/1?q=' + self.urlencoded_param self.ascii_url = URL.from_string(url.encode('ascii')) # django request.get_full_path() returns url as unicode self.unicode_url = URL.from_string(url)
def setUp(self): self.unicode_param = 'значение' # Python 2.6 requires bytes for quote self.urlencoded_param = quote(self.unicode_param.encode('utf8')) url = 'http://www.google.com/blog/article/1?q=' + self.urlencoded_param self.ascii_url = URL.from_string(url.encode('ascii')) # django request.get_full_path() returns url as unicode self.unicode_url = URL.from_string(url)
def assertIsRedirect(self, response, expected_url=None): self.assertTrue( response.status_code in (http_client.FOUND, http_client.MOVED_PERMANENTLY)) if expected_url: location = URL.from_string(response['Location']) self.assertEqual(expected_url, location.path())
def perform_action(self): basket = Mock() basket.id = 1 basket.total_incl_tax = D('200') basket.all_lines = Mock(return_value=[]) methods = [Free()] url_str = get_paypal_url(basket, methods) self.url = URL.from_string(url_str)
def test_missing_shipping_address(self): from paypal.express.views import RedirectView with patch.object(RedirectView, 'as_payment_method') as as_payment_method: as_payment_method.return_value = True url = reverse('paypal-redirect') self.add_product_to_basket() response = self.client.get(url) self.assertEqual(reverse('checkout:shipping-address'), URL.from_string(response['Location']).path())
def perform_action(self): basket = Mock() basket.id = 1 basket.total_incl_tax = D('200') basket.all_lines = Mock(return_value=[]) basket.offer_discounts = [] basket.voucher_discounts = [] basket.shipping_discounts = [] methods = [Free()] url_str = get_paypal_url(basket, methods, paypal_params=self.paypal_params) self.url = URL.from_string(url_str)
def perform_action(self): basket = Mock() basket.id = 1 basket.total_incl_tax = D('200') basket.all_lines = Mock(return_value=[]) basket.offer_discounts = [] basket.voucher_discounts = [] basket.shipping_discounts = [] methods = [Free()] url_str = get_paypal_url(basket, methods) self.url = URL.from_string(url_str)
def test_missing_shipping_address(self): from paypal.express.views import RedirectView with patch.object(RedirectView, 'as_payment_method') as as_payment_method: as_payment_method.return_value = True url = reverse('paypal-redirect') self.add_product_to_basket() response = self.client.get(url) self.assertEqual( reverse('checkout:shipping-address'), URL.from_string(response['Location']).path() )
def process_url(link: str) -> Tuple: """Выводим мета-информацию о ссылке Args: link (str): Ссылка Returns: Tuple: Мета-информация: - Тип домена - Ссылка для сохранения в БД """ url = URL.from_string(link) if 'vk.com' in url.host(): if 'public' in url.path_segment(0): # id = url.path_segment(0).split('public')[1] # id = -1 * int(id) type = 'vk_owner' elif 'club' in url.path_segment(0): # id = url.path_segment(0).split('club')[1] # id = -1 * int(id) type = 'vk_owner' else: type = 'vk_domain' # id = url.path_segment(0) return type, link elif 'ok.ru' in url.host(): return 'odnoklassniki_domain', link elif 'twitter.com' in url.host(): return 'twi', link elif 'instagram.com' in url.host(): return 'insta', link elif 'youtube.com' in url.host(): return 'youtube', link elif 'facebook.com' in url.host(): return 'facebook', link else: return 'site', url.scheme() + '://' + url.host()
def test_set_query(self): url = URL.from_string('http://www.google.com/').query('q=testing') self.assertEqual('testing', url.query_param('q'))
def test_set_path(self): url = URL.from_string('http://www.google.com/').path('search') self.assertEqual('/search', url.path())
def test_set_scheme(self): url = URL.from_string('http://www.google.com/').scheme('https') self.assertEqual('https', url.scheme())
def test_set_fragment(self): url = URL.from_string('http://www.google.com/').fragment('hello') self.assertEqual('hello', url.fragment())
def test_list_extraction(self): url = URL.from_string('http://www.google.com/?q=1&q=2&q=3') self.assertEqual(['1', '2', '3'], url.query_param('q'))
def test_urls_are_hashable(self): u = URL.from_string('http://google.com') hash(u)
def test_negative_equality_comparison(self): self.assertNotEqual(URL.from_string('http://google.com'), URL.from_string('https://google.com'))
def test_set_query_params(self): url = URL.from_string('http://www.google.com/search').query_params({'q': 'testing'}) self.assertEqual('testing', url.query_param('q'))
def test_set_path_segment(self): url = URL.from_string('http://www.google.com/a/b/c/').path_segment(1, 'd') self.assertEqual('/a/d/c/', url.path())
def test_set_port(self): url = URL.from_string('http://www.google.com/').port(8000) self.assertEqual(8000, url.port())
def test_set_query(self): url = URL.from_string('http://www.google.com/').query('q=testing') self.assertEqual('testing', url.query_param('q'))
def test_set_path(self): url = URL.from_string('http://www.google.com/').path('search') self.assertEqual('/search', url.path())
def test_set_host(self): url = URL.from_string('http://www.google.com/').host('maps.google.com') self.assertEqual('maps.google.com', url.host())
def test_set_scheme(self): url = URL.from_string('http://www.google.com/').scheme('https') self.assertEqual('https', url.scheme())
def test_set_path_segment(self): url = URL.from_string('http://www.google.com/a/b/c/').path_segment( 1, 'd') self.assertEqual('/a/d/c/', url.path())
def test_set_subdomain(self): url = URL.from_string('http://www.google.com/search').subdomain( 0, 'www2') self.assertEqual('www2', url.subdomain(0))
def test_set_subdomain(self): url = URL.from_string('http://www.google.com/search').subdomain(0, 'www2') self.assertEqual('www2', url.subdomain(0))
def test_urls_can_be_pickled(self): u = URL.from_string('http://google.com') pickle.dumps(u)
def test_unicode_username_and_password(self): url = URL.from_string('postgres://jeść:niejeść@127.0.0.1:5432/db_name') self.assertEqual('jeść', url.username()) self.assertEqual('niejeść', url.password())
def setUp(self): self.url_str = 'http://www.google.com/search/?q=testing#fragment' self.url = URL.from_string(self.url_str)
def test_port_for_https_url(self): url = URL.from_string('https://github.com') self.assertEqual(None, url.port())
def setUp(self): self.url_str = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-6469953681606921P&AMT=200&CURRENCYCODE=GBP&RETURNURL=http%3A%2F%2Fexample.com%2Fcheckout%2Fpaypal%2Fresponse%2Fsuccess%2F&CANCELURL=http%3A%2F%2Fexample.com%2Fcheckout%2Fpaypal%2Fresponse%2Fcancel%2F' self.url = URL.from_string(self.url_str)
def test_setting_list_as_query_params(self): first = URL.from_string('?q=testing') second = URL().query_params(first.query_params()) self.assertEqual(first.query(), second.query())
def test_unicode_username_only(self): url = URL.from_string('postgres://jeść@127.0.0.1:5432/db_name') self.assertEqual('jeść', url.username()) self.assertTrue(url.password() is None)
def setUp(self): self.url_str = 'http://www.google.com/search/?q=testing#fragment' self.url = URL.from_string(self.url_str)
def setUp(self): self.url = URL.from_string( 'http://www.google.com/blog/article/1?q=testing')
def test_no_equals_sign_means_empty_string(self): url = URL.from_string('http://www.google.com/blog/article/1?q') self.assertEqual('', url.query_param('q'))
def test_set_fragment(self): url = URL.from_string('http://www.google.com/').fragment('hello') self.assertEqual('hello', url.fragment())
def test_list_extraction(self): url = URL.from_string('http://www.google.com/?q=1&q=2&q=3') self.assertEqual(['1', '2', '3'], url.query_param('q'))
def test_set_host(self): url = URL.from_string('http://www.google.com/').host('maps.google.com') self.assertEqual('maps.google.com', url.host())
def test_username_extraction(self): url = URL.from_string('ftp://*****:*****@ftp.host') self.assertEqual('user', url.username()) self.assertEqual('pw', url.password())
def test_set_path_with_special_chars(self): url = URL.from_string('http://www.google.com/').path( 'search something') self.assertEqual('/search%20something', url.path())
def test_username_in_unicode_repr(self): u = 'ftp://*****:*****@ftp.host' url = URL.from_string(u) self.assertEqual(u, str(url))
def test_set_port(self): url = URL.from_string('http://www.google.com/').port(8000) self.assertEqual(8000, url.port())
def test_auth_in_netloc(self): url = URL.from_string('ftp://*****:*****@ftp.host') self.assertEqual('user:[email protected]', url.netloc())
def test_set_query_params(self): url = URL.from_string('http://www.google.com/search').query_params( {'q': 'testing'}) self.assertEqual('testing', url.query_param('q'))
def test_port_for_https_url(self): url = URL.from_string('https://github.com') self.assertEqual(None, url.port())
def test_url_can_be_used_as_key_in_dict(self): u = URL.from_string('http://google.com') {u: 0}
def setUp(self): self.url = URL.from_string('http://www.google.com/blog/article/1?q=testing')
def test_urls_are_hashable(self): u = URL.from_string('http://google.com') hash(u)
def test_urls_can_be_pickled_and_restored(self): u = URL.from_string('http://google.com') pickled = pickle.dumps(u) v = pickle.loads(pickled) self.assertEqual(u, v)
def test_urls_can_be_pickled_and_restored(self): u = URL.from_string('http://google.com') pickled = pickle.dumps(u) v = pickle.loads(pickled) self.assertEqual(u, v)
def test_urls_can_be_pickled(self): u = URL.from_string('http://google.com') pickle.dumps(u)
def setUp(self): self.url_str = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-6469953681606921P&AMT=200&CURRENCYCODE=GBP&RETURNURL=http%3A%2F%2Fexample.com%2Fcheckout%2Fpaypal%2Fresponse%2Fsuccess%2F&CANCELURL=http%3A%2F%2Fexample.com%2Fcheckout%2Fpaypal%2Fresponse%2Fcancel%2F' self.url = URL.from_string(self.url_str)
def test_negative_equality_comparison(self): self.assertNotEqual(URL.from_string('http://google.com'), URL.from_string('https://google.com'))
def test_no_equals_sign_means_empty_string(self): url = URL.from_string('http://www.google.com/blog/article/1?q') self.assertEqual('', url.query_param('q'))
def perform_action(self): self.add_product_to_basket() response = self.client.get(reverse('paypal-redirect')) self.url = URL.from_string(response['Location'])
def test_username_extraction(self): url = URL.from_string('ftp://*****:*****@ftp.host') self.assertEqual('user', url.username()) self.assertEqual('pw', url.password())
def test_port_in_netloc(self): url = URL.from_string('http://localhost:5000') self.assertEqual('localhost', url.host()) self.assertEqual(5000, url.port())
def assertIsRedirect(self, response, expected_url=None): self.assertTrue(response.status_code in ( http_client.FOUND, http_client.MOVED_PERMANENTLY)) if expected_url: location = URL.from_string(response['Location']) self.assertEqual(expected_url, location.path())
def test_empty_basket_shows_error(self): url = reverse('paypal-redirect') response = self.client.get(url) self.assertEqual(reverse('basket:summary'), URL.from_string(response['Location']).path())