-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_urlParser.py
52 lines (35 loc) · 1.65 KB
/
test_urlParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import unittest
from urlParser import urlParser
class basicProtocolParsing(unittest.TestCase):
def assertProtocol(self, url, expected_protocol):
purl = urlParser(url)
self.assertEqual(purl.protocol, expected_protocol)
def test_html_protocol(self):
self.assertProtocol('http://www.essex.ac.uk', 'http')
def test_ftp_protocol(self):
self.assertProtocol('ftp://ftp.essex.ac.uk', 'ftp')
def test_other_protocol(self):
self.assertProtocol('w61xw://some.site.com', 'w61xw')
class basicSiteParsing(unittest.TestCase):
def assertSite(self, url, expected_site):
purl = urlParser(url)
self.assertEqual(purl.site, expected_site)
def test_site_without_path(self):
self.assertSite('http://www.essex.ac.uk', 'www.essex.ac.uk')
def test_site_with_simple_path(self):
self.assertSite('http://www.essex.ac.uk/home.html', 'www.essex.ac.uk')
def test_site_with_complex_path(self):
self.assertSite('http://www.essex.ac.uk/csee/home.html', 'www.essex.ac.uk')
class basicPathParsing(unittest.TestCase):
def assertPath(self, url, expected_path):
purl = urlParser(url)
self.assertEqual(purl.path, expected_path)
def test_empty_path(self):
self.assertPath('http://www.essex.ac.uk', '')
def test_empty_path_with_a_slash(self):
self.assertPath('http://www.essex.ac.uk/', '')
def test_empty_path_with_one_word(self):
self.assertPath('http://www.essex.ac.uk/homework', 'homework')
def test_empty_path_with_sub_folders(self):
self.assertPath('http://www.essex.com/homework/joy.txt',
'homework/joy.txt')