[Kimchi-devel] [PATCH] [Wok 3/3] Add test cases for user logs
Lucio Correia
luciojhc at linux.vnet.ibm.com
Thu Jun 9 18:24:15 UTC 2016
Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
tests/test_api.py | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/tests/test_api.py b/tests/test_api.py
index e9c8714..79f9af5 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -55,3 +55,37 @@ class APITests(unittest.TestCase):
conf = json.loads(resp)
keys = ["auth", "ssl_port", "websockets_port", "version"]
self.assertEquals(sorted(keys), sorted(conf.keys()))
+
+ def test_user_log(self):
+ # Login and logout to make sure there there are entries in user log
+ hdrs = {'AUTHORIZATION': '',
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json'}
+
+ user, pw = utils.fake_user.items()[0]
+ req = json.dumps({'username': user, 'password': pw})
+ resp = self.request('/login', req, 'POST', hdrs)
+
+ resp = self.request('/logout', '{}', 'POST', hdrs)
+ self.assertEquals(200, resp.status)
+
+ # Test user logs JSON response
+ resp = self.request('/logs?app=wok&download=True').read()
+ conf = json.loads(resp)
+ self.assertIn('records', conf)
+ self.assertIn('uri', conf)
+
+ # Test download URL
+ uri = conf.get('uri')
+ self.assertTrue(len(uri) > 0)
+
+ # Test each record key
+ records = conf.get('records', [])
+ self.assertGreaterEqual(records, 1)
+ for record in records:
+ keys = [u'zone', u'ip', u'app', u'req', u'user', u'time', u'date',
+ u'message']
+ self.assertEquals(sorted(keys), sorted(record.keys()))
+
+ # Test search by app
+ self.assertEquals(record['app'], 'wok')
--
1.9.1
More information about the Kimchi-devel
mailing list