From: "Vikraman Choudhury" <vikraman.choudhury@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoostats:master commit in: server/, server/tests/
Date: Wed, 29 Jun 2011 15:14:46 +0000 (UTC) [thread overview]
Message-ID: <bef09ea969572c33cba0127a22a23ecd92f80926.vikraman@gentoo> (raw)
commit: bef09ea969572c33cba0127a22a23ecd92f80926
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Wed Jun 29 15:14:26 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Wed Jun 29 15:14:26 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=bef09ea9
tests for server
---
server/runtests.py | 13 +++++++
server/tests/__init__.py | 1 +
server/tests/test_host.py | 81 ++++++++++++++++++++++++++++++++++++++++++++
server/tests/test_index.py | 26 ++++++++++++++
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
next reply other threads:[~2011-06-29 15:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-29 15:14 Vikraman Choudhury [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-08-21 14:42 [gentoo-commits] proj/gentoostats:master commit in: server/, server/tests/ Vikraman Choudhury
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bef09ea969572c33cba0127a22a23ecd92f80926.vikraman@gentoo \
--to=vikraman.choudhury@gmail.com \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox