37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
|
|
import unittest
|
|
from utils.helpers import (sanitise_url)
|
|
|
|
class TestUrls(unittest.TestCase):
|
|
|
|
base_url_list = (('eu.httpbin.org', 'http://eu.httpbin.org'),
|
|
('www.simonweald.com', 'http://www.simonweald.com'),
|
|
('http://www.github.com/', 'http://www.github.com'),
|
|
('https://www.github.com', 'https://www.github.com'))
|
|
|
|
urls_to_clean = (('https://www.github.com/', 'https://www.github.com/'),
|
|
('https://github.com/?foo=bar', 'https://github.com/'),
|
|
('https://github.com/#anchor', 'https://github.com/'))
|
|
|
|
|
|
def test_sanitise_base_url(self):
|
|
'''
|
|
Tests whether a URL's protocol can be discovered if not provided.
|
|
'''
|
|
for url, target in self.base_url_list:
|
|
result = sanitise_url(url, base_url=True)
|
|
self.assertEqual(result, target)
|
|
|
|
def test_sanitise_url(self):
|
|
'''
|
|
Tests whether a URL's protocol can be discovered if not provided.
|
|
'''
|
|
for url, target in self.urls_to_clean:
|
|
result = sanitise_url(url)
|
|
self.assertEqual(result, target)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|