This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
survey_tests.py
135 lines (108 loc) · 4.76 KB
/
survey_tests.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import unittest
from survey import core
import cssutils
class UriCheckTests(unittest.TestCase):
"""Tests for Uris"""
def testHttpURI(self):
gooduri = core.UriCheck()
httpuristart = 'http://www.opera.com/'
self.assertTrue(gooduri.ishttpURI(httpuristart))
def testHttpsURI(self):
gooduri = core.UriCheck()
httpuristart = 'https://www.opera.com/'
self.assertTrue(gooduri.ishttpURI(httpuristart))
def testUpperCaseHttpURI(self):
gooduri = core.UriCheck()
httpuristart = 'HTTP://www.opera.com/'
self.assertTrue(gooduri.ishttpURI(httpuristart))
def testHttpURIWrong(self):
gooduri = core.UriCheck()
httpurifalse = 'mailto:foo@example.org'
self.assertFalse(gooduri.ishttpURI(httpurifalse))
def testLeadingSpaceHttpURI(self):
gooduri = core.UriCheck()
httpuristart = ' http://www.opera.com/'
self.assertTrue(gooduri.ishttpURI(httpuristart))
def testTrailingSpaceHttpURI(self):
gooduri = core.UriCheck()
httpuristart = 'http://www.opera.com/ '
self.assertTrue(gooduri.ishttpURI(httpuristart))
class CssTests(unittest.TestCase):
"""Tests for CSS requests"""
def setUp(self):
self.css = core.Css()
self.req = core.HttpRequests()
def tearDown(self):
self.css = None
self.req = None
def testUriCssList(self):
"For a given html page, check if we get the right list of linked stylesheets"
WebSiteUri = "http://example.org/"
content_input = """<!doctype html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="/css/style1.css">
<link rel="stylesheet" href="http://example.org/css/style2.css">
</head>
<body>
</body>
</html>"""
expected = ['http://example.org/css/style1.css', 'http://example.org/css/style2.css']
actual = self.css.getCssUriList(content_input, WebSiteUri)
# we need to compare ordered list.
actual.sort()
expected.sort()
self.assertListEqual(expected, actual)
def testHasStyleElement(self):
"for a given URI, there a style element. return True."
content = "<!doctype><html><head><title>foo</title><style>.foo {color: #fff;}</style></head><body>foo</body></html>"
self.assertTrue(self.css.hasStyleElement(content))
def testNoStyleElement(self):
"for a given URI, there is no style element. return False"
content = "<!doctype><html><head><title>foo</title></head><body>foo</body></html>"
self.assertFalse(self.css.hasStyleElement(content))
def testStyleElementRules(self):
"When there is a style element, do we get the expected rules?"
# we might need to normalize to cope for spaces in the test.
content = """<!doctype><html><head><title>foo</title>
<style>.foo {/*comment*/
color: #fff;}</style>
<!-- foo -->
<style> .bar {margin: 10px;}</style>
</head><body>foo</body></html>"""
expected = u'.foo {color: #fff;}.bar {margin: 10px;}'
actual = self.css.getStyleElementRules(content).cssText
self.assertEqual(expected, actual)
def testhasVendorProperty(self):
"For a list of CSS declarations, is there a property -vendor-property?"
declarationslist = cssutils.css.CSSStyleDeclaration(cssText='color: red;-o-color:red;')
vendorname = "o"
propertyname = "color"
actual = self.css.hasVendorProperty(vendorname, propertyname, declarationslist)
self.assertTrue(actual)
# def testisPartofPropertyFamily(self):
# "A list of CSS Declaration with properties such as -o-transition-delay part of transition family."
# declarationslist = cssutils.css.CSSStyleDeclaration(cssText='-o-transition-delay: 1s;')
# vendorname = "o"
# propertyname = "transition"
# actual = self.css.hasVendorProperty(vendorname, propertyname, declarationslist)
# self.assertTrue(actual)
def testhasNotVendorProperty(self):
"For a list of CSS declarations, -vendor-property is not here, return False"
declarationslist = cssutils.css.CSSStyleDeclaration(cssText='color: red;-webkit-color:red;-moz-color:red;')
vendorname = "o"
propertyname = "color"
actual = self.css.hasVendorProperty(vendorname, propertyname, declarationslist)
self.assertFalse(actual)
class SurveyTests(unittest.TestCase):
"""Tests for survey Stats"""
def setUp(self):
self.survey = core.Survey()
self.css = core.Css()
def tearDown(self):
self.survey = None
def main():
unittest.main()
if __name__ == '__main__':
main()