|
2 | 2 | from __future__ import absolute_import |
3 | 3 | import os |
4 | 4 | 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, |
6 | 6 | url_query_parameter, add_or_replace_parameter, url_query_cleaner, |
7 | 7 | file_uri_to_path, path_to_file_uri, any_to_uri, urljoin_rfc) |
8 | 8 |
|
@@ -166,13 +166,22 @@ def test_safe_url_idna(self): |
166 | 166 | self.assertEqual(safeurl, safe_result) |
167 | 167 |
|
168 | 168 | def test_safe_download_url(self): |
| 169 | + self.assertEqual(safe_download_url('http://www.example.org'), |
| 170 | + 'http://www.example.org/') |
169 | 171 | self.assertEqual(safe_download_url('http://www.example.org/../'), |
170 | 172 | 'http://www.example.org/') |
171 | 173 | self.assertEqual(safe_download_url('http://www.example.org/../../images/../image'), |
172 | 174 | 'http://www.example.org/image') |
173 | 175 | self.assertEqual(safe_download_url('http://www.example.org/dir/'), |
174 | 176 | 'http://www.example.org/dir/') |
175 | 177 |
|
| 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 | + |
176 | 185 | def test_url_query_parameter(self): |
177 | 186 | self.assertEqual(url_query_parameter("product.html?id=200&foo=bar", "id"), |
178 | 187 | '200') |
@@ -256,6 +265,10 @@ def test_url_query_cleaner(self): |
256 | 265 | url_query_cleaner("product.html?id=200&foo=bar&name=wired", ['id', 'name'])) |
257 | 266 | self.assertEqual('product.html?id', |
258 | 267 | 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 |
259 | 272 | self.assertEqual('product.html?d=1&d=2&d=3', |
260 | 273 | url_query_cleaner("product.html?d=1&e=b&d=2&d=3&other=other", ['d'], unique=False)) |
261 | 274 | self.assertEqual('product.html?id=200&foo=bar', |
|
0 commit comments