Skip to content

Commit 3bc99d6

Browse files
authored
Merge pull request #58 from redapple/url-tests
Add more tests for w3lib.url
2 parents 8aa0790 + d270029 commit 3bc99d6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/test_url.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import absolute_import
33
import os
44
import unittest
5-
from w3lib.url import (safe_url_string, safe_download_url,
5+
from w3lib.url import (is_url, safe_url_string, safe_download_url,
66
url_query_parameter, add_or_replace_parameter, url_query_cleaner,
77
file_uri_to_path, path_to_file_uri, any_to_uri, urljoin_rfc)
88

@@ -166,13 +166,22 @@ def test_safe_url_idna(self):
166166
self.assertEqual(safeurl, safe_result)
167167

168168
def test_safe_download_url(self):
169+
self.assertEqual(safe_download_url('http://www.example.org'),
170+
'http://www.example.org/')
169171
self.assertEqual(safe_download_url('http://www.example.org/../'),
170172
'http://www.example.org/')
171173
self.assertEqual(safe_download_url('http://www.example.org/../../images/../image'),
172174
'http://www.example.org/image')
173175
self.assertEqual(safe_download_url('http://www.example.org/dir/'),
174176
'http://www.example.org/dir/')
175177

178+
def test_is_url(self):
179+
self.assertTrue(is_url('http://www.example.org'))
180+
self.assertTrue(is_url('https://www.example.org'))
181+
self.assertTrue(is_url('file:///some/path'))
182+
self.assertFalse(is_url('foo://bar'))
183+
self.assertFalse(is_url('foo--bar'))
184+
176185
def test_url_query_parameter(self):
177186
self.assertEqual(url_query_parameter("product.html?id=200&foo=bar", "id"),
178187
'200')
@@ -256,6 +265,10 @@ def test_url_query_cleaner(self):
256265
url_query_cleaner("product.html?id=200&foo=bar&name=wired", ['id', 'name']))
257266
self.assertEqual('product.html?id',
258267
url_query_cleaner("product.html?id&other=3&novalue=", ['id']))
268+
# default is to remove duplicate keys
269+
self.assertEqual('product.html?d=1',
270+
url_query_cleaner("product.html?d=1&e=b&d=2&d=3&other=other", ['d']))
271+
# unique=False disables duplicate keys filtering
259272
self.assertEqual('product.html?d=1&d=2&d=3',
260273
url_query_cleaner("product.html?d=1&e=b&d=2&d=3&other=other", ['d'], unique=False))
261274
self.assertEqual('product.html?id=200&foo=bar',

0 commit comments

Comments
 (0)