Skip to content

Commit b8fb167

Browse files
authored
Merge pull request #5 from Team9-RobotIX/increase_test_coverage
Increase test coverage
2 parents 3b60818 + c0259b3 commit b8fb167

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

flaskapp/tests.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,26 @@ def create_app(self):
2626
app.config['LIVESERVER_TIMEOUT'] = 10
2727
return app
2828

29-
def test_runAll(self):
30-
self.server_is_up_and_running_test()
31-
self.post_vals_works_test()
32-
print 'all tests have run, shutting down'
29+
def setUp(self):
30+
print 'setup'
31+
32+
###This must be first
33+
def test_shutdown_text_outputted(self):
3334
r = requests.post(url = self.url + 'shutdown', data = {})
35+
self.assertEqual(r.text, 'Server shutting down...')
3436

35-
#Test that the server is responding
36-
def server_is_up_and_running_test(self):
37+
def test_shutdown_error_outputted(self):
38+
with self.assertRaises(RuntimeError):
39+
r = flaskapp.shutdown()
40+
print 'Errored as expected: '+r.text
41+
42+
def test_server_is_up_and_running(self):
3743
print self.get_server_url()
3844
response = urllib2.urlopen(self.url)
3945
self.assertEqual(response.code, 200)
4046
print 'Server is up and running'
4147

42-
def post_vals_works_test(self):
48+
def test_post_vals_works_with_correct_vals(self):
4349
data = {'onOff':1, 'turnAngle':41.0}
4450
urlPost = self.url + 'post'
4551
r = requests.post(url = urlPost, data = data)
@@ -48,6 +54,27 @@ def post_vals_works_test(self):
4854
self.assertEqual(data['onOff'], retData['onOff'])
4955
print 'Successfully returned: '+r.text
5056

57+
def test_post_vals_fails_with_invalid_turnangle(self):
58+
data = {'onOff':1, 'turnAngle':181.0}
59+
urlPost = self.url + 'post'
60+
r = requests.post(url = urlPost, data = data)
61+
self.assertEqual('invalid request', r.text)
62+
print 'Failed as expected: '+r.text
63+
64+
def test_post_vals_fails_with_invalid_onoff(self):
65+
data = {'onOff':2, 'turnAngle':41.0}
66+
urlPost = self.url + 'post'
67+
r = requests.post(url = urlPost, data = data)
68+
self.assertEqual('invalid request', r.text)
69+
print 'Failed as expected: '+r.text
70+
71+
def test_exception_handler(self):
72+
ret = flaskapp.exception_handler("error")
73+
self.assertEqual(ret, "Oh no! 'error'")
74+
75+
def tearDown(self):
76+
print 'teardown'
77+
5178
if __name__ == '__main__':
5279

5380
server = Process(target=flaskapp.main)

0 commit comments

Comments
 (0)