aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVikraman Choudhury <vikraman.choudhury@gmail.com>2011-06-29 20:44:26 +0530
committerVikraman Choudhury <vikraman.choudhury@gmail.com>2011-06-29 20:44:26 +0530
commitbef09ea969572c33cba0127a22a23ecd92f80926 (patch)
tree1188d074ff0bc5560cc75dc44c9fe28aaa8079a9
parentadd dev-python/argparse to rdepend (diff)
downloadgentoostats-bef09ea969572c33cba0127a22a23ecd92f80926.tar.gz
gentoostats-bef09ea969572c33cba0127a22a23ecd92f80926.tar.bz2
gentoostats-bef09ea969572c33cba0127a22a23ecd92f80926.zip
tests for server
-rwxr-xr-xserver/runtests.py13
-rw-r--r--server/tests/__init__.py1
-rw-r--r--server/tests/test_host.py81
-rw-r--r--server/tests/test_index.py26
4 files changed, 121 insertions, 0 deletions
diff --git a/server/runtests.py b/server/runtests.py
new file mode 100755
index 0000000..8c0cbb0
--- /dev/null
+++ b/server/runtests.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+import unittest
+
+from tests.test_index import TestIndex
+from tests.test_host import TestHost
+
+testCases = [TestIndex, TestHost]
+
+if __name__ == '__main__':
+ suites = [ unittest.TestLoader().loadTestsFromTestCase(testCase) for testCase in testCases]
+ for suite in suites:
+ unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/server/tests/__init__.py b/server/tests/__init__.py
new file mode 100644
index 0000000..3c6cfa2
--- /dev/null
+++ b/server/tests/__init__.py
@@ -0,0 +1 @@
+# Make this a python package
diff --git a/server/tests/test_host.py b/server/tests/test_host.py
new file mode 100644
index 0000000..b5b6ebe
--- /dev/null
+++ b/server/tests/test_host.py
@@ -0,0 +1,81 @@
+
+import uuid
+import json
+import unittest
+from main import app
+
+class TestHost(unittest.TestCase):
+
+ def setUp(self):
+ self.b = app.browser()
+
+ def test_basic(self):
+ self.b.open('/host')
+ self.assertEqual(self.b.path, '/host')
+ self.assertEqual(self.b.status, 404)
+
+ def test_get(self):
+ uri = '/host/' + str(uuid.uuid4())
+ self.b.open(uri)
+ self.assertEqual(self.b.path, uri)
+
+ # This has a probability of failing of
+ # 1 - exp(-((n+1)**2)/2**123)
+ # where n is the no. of uuids already in the db
+ self.assertEqual(self.b.status, 404)
+
+ def test_post_empty(self):
+ str_uuid = str(uuid.uuid4())
+ uri = '/host/' + str_uuid
+ # post with empty string
+ self.b.open(uri, '')
+ self.assertEqual(self.b.path, uri)
+ self.assertEqual(self.b.status, 500)
+ # post with empty json string
+ data = json.JSONEncoder().encode('')
+ self.b.open(uri, data)
+ self.assertEqual(self.b.path, uri)
+ self.assertEqual(self.b.status, 500)
+ # post with empty payload
+ payload = {
+ 'AUTH':{'UUID':str_uuid,'PASSWD':'test'},
+ 'PROTOCOL':1
+ }
+ data = json.JSONEncoder().encode(payload)
+ self.b.open(uri, data)
+ self.assertEqual(self.b.path, uri)
+ self.assertEqual(self.b.status, 500)
+
+ def test_post_bad(self):
+ str_uuid = str(uuid.uuid4())
+ uri = '/host/' + str_uuid
+ # different uuid in payload
+ payload = {
+ 'AUTH':{'UUID':str(uuid.uuid4()),'PASSWD':'test'},
+ 'PROTOCOL':1
+ }
+ data = json.JSONEncoder().encode(payload)
+ self.b.open(uri,data)
+ self.assertEqual(self.b.path, uri)
+ self.assertEqual(self.b.status, 200)
+ self.assertTrue('Invalid uuid' in self.b.data)
+
+ def test_post_get(self):
+ str_uuid = str(uuid.uuid4())
+ uri = '/host/' + str_uuid
+ payload = {
+ 'AUTH':{'UUID':str_uuid,'PASSWD':'test'},
+ 'PROTOCOL':1
+ }
+ for var in ['PLATFORM','PROFILE','LASTSYNC']:
+ payload[var] = 'Unknown'
+ for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']:
+ payload[var] = None
+ for var in ['ACCEPT_KEYWORDS','LANG','GENTOO_MIRRORS','FEATURES','USE']:
+ payload[var] = []
+ payload['PACKAGES'] = {}
+ data = json.JSONEncoder().encode(payload)
+ self.b.open(uri,data)
+ self.assertEqual(self.b.path, uri)
+ self.assertEqual(self.b.status, 200)
+ self.assertTrue('POST for ' + str_uuid + ' successful' in self.b.data)
diff --git a/server/tests/test_index.py b/server/tests/test_index.py
new file mode 100644
index 0000000..63614ab
--- /dev/null
+++ b/server/tests/test_index.py
@@ -0,0 +1,26 @@
+
+import unittest
+from main import app
+
+class TestIndex(unittest.TestCase):
+
+ def setUp(self):
+ self.b = app.browser()
+ self.b.open('/')
+
+ def test_basic(self):
+ self.assertEqual(self.b.path, '/')
+ self.assertEqual(self.b.status, 200)
+
+ def test_content(self):
+ self.assertTrue('Welcome to the gentoostats webapp' in self.b.data)
+
+ def test_hosts(self):
+ self.assertTrue('Number of hosts' in self.b.data)
+ lines = self.b.data.split('\n')
+ for line in lines:
+ if line.startswith('Number of hosts'):
+ words = line.split()
+ count = int(words[-1].strip('</br>'))
+ self.assertGreaterEqual(count,0)
+ break