From fb6b976391cb7bca9f0076eb7c6ae24d9b469df4 Mon Sep 17 00:00:00 2001 From: Simon Weald Date: Mon, 27 Aug 2018 19:36:43 +0100 Subject: [PATCH] initial commit of utils tests --- test_helpers.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test_helpers.py diff --git a/test_helpers.py b/test_helpers.py new file mode 100644 index 0000000..670170d --- /dev/null +++ b/test_helpers.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import unittest +from utils.helpers import (url_validation, standardise_base_url) + +class TestUrls(unittest.TestCase): + + base_url = "github.com" + base_url_list = (('eu.httpbin.org', 'http://eu.httpbin.org'), + ('www.simonweald.com', 'https://www.simonweald.com'), + ('http://www.github.com', 'http://www.github.com')) + valid_urls = ["https://www.github.com", "http://www.github.com", + "github.com", "/some/url/", "index.html"] + + + def test_url_standardisation(self): + ''' + Tests whether a URL's protocol can be discovered if not provided. + ''' + for url, target in self.base_url_list: + result = standardise_base_url(url) + 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) + + +if __name__ == '__main__': + unittest.main()