Skip to content

Commit c0259b3

Browse files
author
James O'donnell
committed
test shutdown
1 parent 84cebf8 commit c0259b3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

flaskapp/tests.py

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

29+
def setUp(self):
30+
print 'setup'
31+
32+
###This must be first
33+
def test_shutdown_text_outputted(self):
34+
r = requests.post(url = self.url + 'shutdown', data = {})
35+
self.assertEqual(r.text, 'Server shutting down...')
36+
37+
def test_shutdown_error_outputted(self):
38+
with self.assertRaises(RuntimeError):
39+
r = flaskapp.shutdown()
40+
print 'Errored as expected: '+r.text
41+
2942
def test_server_is_up_and_running(self):
3043
print self.get_server_url()
3144
response = urllib2.urlopen(self.url)
3245
self.assertEqual(response.code, 200)
3346
print 'Server is up and running'
3447

35-
#This must be part of the first test
36-
print 'all tests have run, shutting down'
37-
r = requests.post(url = self.url + 'shutdown', data = {})
38-
3948
def test_post_vals_works_with_correct_vals(self):
4049
data = {'onOff':1, 'turnAngle':41.0}
4150
urlPost = self.url + 'post'
@@ -63,6 +72,9 @@ def test_exception_handler(self):
6372
ret = flaskapp.exception_handler("error")
6473
self.assertEqual(ret, "Oh no! 'error'")
6574

75+
def tearDown(self):
76+
print 'teardown'
77+
6678
if __name__ == '__main__':
6779

6880
server = Process(target=flaskapp.main)

0 commit comments

Comments
 (0)