From 273cf56a3b6d59ad47a1f92be76e4a778d7ce0cd Mon Sep 17 00:00:00 2001 From: Simon Weald Date: Tue, 11 Sep 2018 13:42:15 +0100 Subject: [PATCH] add some basic tests --- test_helpers.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/test_helpers.py b/test_helpers.py index 1aacdee..62c9412 100644 --- a/test_helpers.py +++ b/test_helpers.py @@ -1,37 +1,35 @@ #!/usr/bin/env python import unittest -from utils.helpers import (clean_base_url) +from utils.helpers import (sanitise_url) class TestUrls(unittest.TestCase): - base_url = "github.com" - 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')) - valid_urls = ["https://www.github.com", "http://www.github.com", - "github.com", "/some/url/", "index.html"] + 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_clean_base_url(self): + 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 = clean_base_url(url) + result = sanitise_url(url, base_url=True) self.assertEqual(result, target) - # def test_url_validation(self): - # ''' - # Passes when given a valid URL. A valid URL is qualified - # by being local to the domain to be crawled. - # ''' - # for url in self.valid_urls: - # result = url_validation(self.base_url, url) - # self.assertTrue(result) + 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__':