2
2
from __future__ import absolute_import
3
3
import os
4
4
import unittest
5
+
6
+ import pytest
7
+ from six .moves .urllib .parse import urlparse
8
+
5
9
from w3lib .url import (is_url , safe_url_string , safe_download_url ,
6
10
url_query_parameter , add_or_replace_parameter , url_query_cleaner ,
7
11
file_uri_to_path , parse_data_uri , path_to_file_uri , any_to_uri ,
8
12
urljoin_rfc , canonicalize_url , parse_url , add_or_replace_parameters )
9
- from six .moves .urllib .parse import urlparse
10
13
11
14
12
15
class UrlTests (unittest .TestCase ):
@@ -76,17 +79,16 @@ def test_safe_url_string_remove_ascii_tab_and_newlines(self):
76
79
def test_safe_url_string_unsafe_chars (self ):
77
80
safeurl = safe_url_string (r"http://localhost:8001/unwise{,},|,\,^,[,],`?|=[]&[]=|" )
78
81
self .assertEqual (safeurl , r"http://localhost:8001/unwise%7B,%7D,|,%5C,%5E,[,],%60?|=[]&[]=|" )
79
-
82
+
80
83
def test_safe_url_string_quote_path (self ):
81
84
safeurl = safe_url_string (u'http://google.com/"hello"' , quote_path = True )
82
85
self .assertEqual (safeurl , u'http://google.com/%22hello%22' )
83
-
86
+
84
87
safeurl = safe_url_string (u'http://google.com/"hello"' , quote_path = False )
85
88
self .assertEqual (safeurl , u'http://google.com/"hello"' )
86
-
89
+
87
90
safeurl = safe_url_string (u'http://google.com/"hello"' )
88
91
self .assertEqual (safeurl , u'http://google.com/%22hello%22' )
89
-
90
92
91
93
def test_safe_url_string_with_query (self ):
92
94
safeurl = safe_url_string (u"http://www.example.com/£?unit=µ" )
@@ -310,10 +312,6 @@ def test_add_or_replace_parameter(self):
310
312
self .assertEqual (add_or_replace_parameter (url , 'arg3' , 'nv3' ),
311
313
'http://domain/test?arg1=v1&arg2=v2&arg3=nv3' )
312
314
313
- url = 'http://domain/test?arg1=v1;arg2=v2'
314
- self .assertEqual (add_or_replace_parameter (url , 'arg1' , 'v3' ),
315
- 'http://domain/test?arg1=v3&arg2=v2' )
316
-
317
315
self .assertEqual (add_or_replace_parameter ("http://domain/moreInfo.asp?prodID=" , 'prodID' , '20' ),
318
316
'http://domain/moreInfo.asp?prodID=20' )
319
317
url = 'http://rmc-offers.co.uk/productlist.asp?BCat=2%2C60&CatID=60'
@@ -338,6 +336,13 @@ def test_add_or_replace_parameter(self):
338
336
self .assertEqual (add_or_replace_parameter (url , 'arg1' , 'v3' ),
339
337
'http://domain/test?arg1=v3&arg2=v2' )
340
338
339
+ @pytest .mark .xfail (reason = "https://github.com/scrapy/w3lib/issues/164" )
340
+ def test_add_or_replace_parameter_fail (self ):
341
+ self .assertEqual (
342
+ add_or_replace_parameter ('http://domain/test?arg1=v1;arg2=v2' , 'arg1' , 'v3' ),
343
+ 'http://domain/test?arg1=v3&arg2=v2'
344
+ )
345
+
341
346
def test_add_or_replace_parameters (self ):
342
347
url = 'http://domain/test'
343
348
self .assertEqual (add_or_replace_parameters (url , {'arg' : 'v' }),
@@ -767,4 +772,3 @@ def test_scheme_case_insensitive(self):
767
772
768
773
if __name__ == "__main__" :
769
774
unittest .main ()
770
-
0 commit comments