1 |
commit: bef09ea969572c33cba0127a22a23ecd92f80926 |
2 |
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com> |
3 |
AuthorDate: Wed Jun 29 15:14:26 2011 +0000 |
4 |
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com> |
5 |
CommitDate: Wed Jun 29 15:14:26 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=bef09ea9 |
7 |
|
8 |
tests for server |
9 |
|
10 |
--- |
11 |
server/runtests.py | 13 +++++++ |
12 |
server/tests/__init__.py | 1 + |
13 |
server/tests/test_host.py | 81 ++++++++++++++++++++++++++++++++++++++++++++ |
14 |
server/tests/test_index.py | 26 ++++++++++++++ |
15 |
4 files changed, 121 insertions(+), 0 deletions(-) |
16 |
|
17 |
diff --git a/server/runtests.py b/server/runtests.py |
18 |
new file mode 100755 |
19 |
index 0000000..8c0cbb0 |
20 |
--- /dev/null |
21 |
+++ b/server/runtests.py |
22 |
@@ -0,0 +1,13 @@ |
23 |
+#!/usr/bin/env python |
24 |
+ |
25 |
+import unittest |
26 |
+ |
27 |
+from tests.test_index import TestIndex |
28 |
+from tests.test_host import TestHost |
29 |
+ |
30 |
+testCases = [TestIndex, TestHost] |
31 |
+ |
32 |
+if __name__ == '__main__': |
33 |
+ suites = [ unittest.TestLoader().loadTestsFromTestCase(testCase) for testCase in testCases] |
34 |
+ for suite in suites: |
35 |
+ unittest.TextTestRunner(verbosity=2).run(suite) |
36 |
|
37 |
diff --git a/server/tests/__init__.py b/server/tests/__init__.py |
38 |
new file mode 100644 |
39 |
index 0000000..3c6cfa2 |
40 |
--- /dev/null |
41 |
+++ b/server/tests/__init__.py |
42 |
@@ -0,0 +1 @@ |
43 |
+# Make this a python package |
44 |
|
45 |
diff --git a/server/tests/test_host.py b/server/tests/test_host.py |
46 |
new file mode 100644 |
47 |
index 0000000..b5b6ebe |
48 |
--- /dev/null |
49 |
+++ b/server/tests/test_host.py |
50 |
@@ -0,0 +1,81 @@ |
51 |
+ |
52 |
+import uuid |
53 |
+import json |
54 |
+import unittest |
55 |
+from main import app |
56 |
+ |
57 |
+class TestHost(unittest.TestCase): |
58 |
+ |
59 |
+ def setUp(self): |
60 |
+ self.b = app.browser() |
61 |
+ |
62 |
+ def test_basic(self): |
63 |
+ self.b.open('/host') |
64 |
+ self.assertEqual(self.b.path, '/host') |
65 |
+ self.assertEqual(self.b.status, 404) |
66 |
+ |
67 |
+ def test_get(self): |
68 |
+ uri = '/host/' + str(uuid.uuid4()) |
69 |
+ self.b.open(uri) |
70 |
+ self.assertEqual(self.b.path, uri) |
71 |
+ |
72 |
+ # This has a probability of failing of |
73 |
+ # 1 - exp(-((n+1)**2)/2**123) |
74 |
+ # where n is the no. of uuids already in the db |
75 |
+ self.assertEqual(self.b.status, 404) |
76 |
+ |
77 |
+ def test_post_empty(self): |
78 |
+ str_uuid = str(uuid.uuid4()) |
79 |
+ uri = '/host/' + str_uuid |
80 |
+ # post with empty string |
81 |
+ self.b.open(uri, '') |
82 |
+ self.assertEqual(self.b.path, uri) |
83 |
+ self.assertEqual(self.b.status, 500) |
84 |
+ # post with empty json string |
85 |
+ data = json.JSONEncoder().encode('') |
86 |
+ self.b.open(uri, data) |
87 |
+ self.assertEqual(self.b.path, uri) |
88 |
+ self.assertEqual(self.b.status, 500) |
89 |
+ # post with empty payload |
90 |
+ payload = { |
91 |
+ 'AUTH':{'UUID':str_uuid,'PASSWD':'test'}, |
92 |
+ 'PROTOCOL':1 |
93 |
+ } |
94 |
+ data = json.JSONEncoder().encode(payload) |
95 |
+ self.b.open(uri, data) |
96 |
+ self.assertEqual(self.b.path, uri) |
97 |
+ self.assertEqual(self.b.status, 500) |
98 |
+ |
99 |
+ def test_post_bad(self): |
100 |
+ str_uuid = str(uuid.uuid4()) |
101 |
+ uri = '/host/' + str_uuid |
102 |
+ # different uuid in payload |
103 |
+ payload = { |
104 |
+ 'AUTH':{'UUID':str(uuid.uuid4()),'PASSWD':'test'}, |
105 |
+ 'PROTOCOL':1 |
106 |
+ } |
107 |
+ data = json.JSONEncoder().encode(payload) |
108 |
+ self.b.open(uri,data) |
109 |
+ self.assertEqual(self.b.path, uri) |
110 |
+ self.assertEqual(self.b.status, 200) |
111 |
+ self.assertTrue('Invalid uuid' in self.b.data) |
112 |
+ |
113 |
+ def test_post_get(self): |
114 |
+ str_uuid = str(uuid.uuid4()) |
115 |
+ uri = '/host/' + str_uuid |
116 |
+ payload = { |
117 |
+ 'AUTH':{'UUID':str_uuid,'PASSWD':'test'}, |
118 |
+ 'PROTOCOL':1 |
119 |
+ } |
120 |
+ for var in ['PLATFORM','PROFILE','LASTSYNC']: |
121 |
+ payload[var] = 'Unknown' |
122 |
+ for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']: |
123 |
+ payload[var] = None |
124 |
+ for var in ['ACCEPT_KEYWORDS','LANG','GENTOO_MIRRORS','FEATURES','USE']: |
125 |
+ payload[var] = [] |
126 |
+ payload['PACKAGES'] = {} |
127 |
+ data = json.JSONEncoder().encode(payload) |
128 |
+ self.b.open(uri,data) |
129 |
+ self.assertEqual(self.b.path, uri) |
130 |
+ self.assertEqual(self.b.status, 200) |
131 |
+ self.assertTrue('POST for ' + str_uuid + ' successful' in self.b.data) |
132 |
|
133 |
diff --git a/server/tests/test_index.py b/server/tests/test_index.py |
134 |
new file mode 100644 |
135 |
index 0000000..63614ab |
136 |
--- /dev/null |
137 |
+++ b/server/tests/test_index.py |
138 |
@@ -0,0 +1,26 @@ |
139 |
+ |
140 |
+import unittest |
141 |
+from main import app |
142 |
+ |
143 |
+class TestIndex(unittest.TestCase): |
144 |
+ |
145 |
+ def setUp(self): |
146 |
+ self.b = app.browser() |
147 |
+ self.b.open('/') |
148 |
+ |
149 |
+ def test_basic(self): |
150 |
+ self.assertEqual(self.b.path, '/') |
151 |
+ self.assertEqual(self.b.status, 200) |
152 |
+ |
153 |
+ def test_content(self): |
154 |
+ self.assertTrue('Welcome to the gentoostats webapp' in self.b.data) |
155 |
+ |
156 |
+ def test_hosts(self): |
157 |
+ self.assertTrue('Number of hosts' in self.b.data) |
158 |
+ lines = self.b.data.split('\n') |
159 |
+ for line in lines: |
160 |
+ if line.startswith('Number of hosts'): |
161 |
+ words = line.split() |
162 |
+ count = int(words[-1].strip('</br>')) |
163 |
+ self.assertGreaterEqual(count,0) |
164 |
+ break |