22from __future__ import absolute_import
33import os
44import unittest
5+
6+ import pytest
7+ from six .moves .urllib .parse import urlparse
8+
59from w3lib .url import (is_url , safe_url_string , safe_download_url ,
610 url_query_parameter , add_or_replace_parameter , url_query_cleaner ,
711 file_uri_to_path , parse_data_uri , path_to_file_uri , any_to_uri ,
812 urljoin_rfc , canonicalize_url , parse_url , add_or_replace_parameters )
9- from six .moves .urllib .parse import urlparse
1013
1114
1215class UrlTests (unittest .TestCase ):
@@ -76,17 +79,16 @@ def test_safe_url_string_remove_ascii_tab_and_newlines(self):
7679 def test_safe_url_string_unsafe_chars (self ):
7780 safeurl = safe_url_string (r"http://localhost:8001/unwise{,},|,\,^,[,],`?|=[]&[]=|" )
7881 self .assertEqual (safeurl , r"http://localhost:8001/unwise%7B,%7D,|,%5C,%5E,[,],%60?|=[]&[]=|" )
79-
82+
8083 def test_safe_url_string_quote_path (self ):
8184 safeurl = safe_url_string (u'http://google.com/"hello"' , quote_path = True )
8285 self .assertEqual (safeurl , u'http://google.com/%22hello%22' )
83-
86+
8487 safeurl = safe_url_string (u'http://google.com/"hello"' , quote_path = False )
8588 self .assertEqual (safeurl , u'http://google.com/"hello"' )
86-
89+
8790 safeurl = safe_url_string (u'http://google.com/"hello"' )
8891 self .assertEqual (safeurl , u'http://google.com/%22hello%22' )
89-
9092
9193 def test_safe_url_string_with_query (self ):
9294 safeurl = safe_url_string (u"http://www.example.com/£?unit=µ" )
@@ -310,10 +312,6 @@ def test_add_or_replace_parameter(self):
310312 self .assertEqual (add_or_replace_parameter (url , 'arg3' , 'nv3' ),
311313 'http://domain/test?arg1=v1&arg2=v2&arg3=nv3' )
312314
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-
317315 self .assertEqual (add_or_replace_parameter ("http://domain/moreInfo.asp?prodID=" , 'prodID' , '20' ),
318316 'http://domain/moreInfo.asp?prodID=20' )
319317 url = 'http://rmc-offers.co.uk/productlist.asp?BCat=2%2C60&CatID=60'
@@ -338,6 +336,13 @@ def test_add_or_replace_parameter(self):
338336 self .assertEqual (add_or_replace_parameter (url , 'arg1' , 'v3' ),
339337 'http://domain/test?arg1=v3&arg2=v2' )
340338
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+
341346 def test_add_or_replace_parameters (self ):
342347 url = 'http://domain/test'
343348 self .assertEqual (add_or_replace_parameters (url , {'arg' : 'v' }),
@@ -767,4 +772,3 @@ def test_scheme_case_insensitive(self):
767772
768773if __name__ == "__main__" :
769774 unittest .main ()
770-
0 commit comments