-
Notifications
You must be signed in to change notification settings - Fork 0
/
testSimple.py
executable file
·43 lines (35 loc) · 1.7 KB
/
testSimple.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
"""
Each file that starts with test... in this directory is scanned for subclasses of unittest.TestCase or testLib.RestTestCase
"""
import unittest
import os
import testLib
class TestUnit(testLib.RestTestCase):
"""Issue a REST API request to run the unit tests, and analyze the result"""
def testUnit(self):
respData = self.makeRequest("/TESTAPI/unitTests", method="POST")
self.assertTrue('output' in respData)
print ("Unit tests output:\n"+
"\n***** ".join(respData['output'].split("\n")))
self.assertTrue('totalTests' in respData)
print "***** Reported "+str(respData['totalTests'])+" unit tests"
# When we test the actual project, we require at least 10 unit tests
minimumTests = 10
if "SAMPLE_APP" in os.environ:
minimumTests = 4
self.assertTrue(respData['totalTests'] >= minimumTests,
"at least "+str(minimumTests)+" unit tests. Found only "+str(respData['totalTests'])+". use SAMPLE_APP=1 if this is the sample app")
self.assertEquals(0, respData['nrFailed'])
class TestAddUser(testLib.RestTestCase):
"""Test adding users"""
def assertResponse(self, respData, count = 1, errCode = testLib.RestTestCase.SUCCESS):
"""
Check that the response data dictionary matches the expected values
"""
expected = { 'errCode' : errCode }
if count is not None:
expected['count'] = count
self.assertDictEqual(expected, respData)
def testAdd1(self):
respData = self.makeRequest("/users/add", method="POST", data = { 'user' : 'user1', 'password' : 'password'} )
self.assertResponse(respData, count = 1)