Skip to content

Commit

Permalink
minor changes to test, to correctly test 500 error
Browse files Browse the repository at this point in the history
  • Loading branch information
deidyomega committed Nov 17, 2017
1 parent 280be64 commit fd2216b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class CERPTestCase(unittest.TestCase):
DEPLOY = False

def setUp(self):
cerp.app.testing = True
Expand Down Expand Up @@ -131,16 +130,14 @@ def test_api_topic_precinctNum_valid(self):
self.assertTrue(isinstance(page['data'], list))

def test_api_topic_precinctNum_diff(self):
page = self.convert_to_json(
self.app.get('/api/Presidential Election-2016/2235235101/diff?comp1=Clinton/Kaine&comp2=Trump/Pence')
)
page = self.convert_to_json(self.app.get(
'/api/Presidential Election-2016/2235235101/diff?comp1=Clinton/Kaine&comp2=Trump/Pence'))
# Result was found
self.assertTrue(page['result'])
self.assertTrue(page['data'])

page = self.convert_to_json(
self.app.get('/api/Presidential Election-2016/all/diff?comp1=Clinton/Kaine&comp2=Trump/Pence')
)
page = self.convert_to_json(self.app.get(
'/api/Presidential Election-2016/all/diff?comp1=Clinton/Kaine&comp2=Trump/Pence'))
# Result was found
self.assertTrue(page['result'])
self.assertTrue(isinstance(page['data'], dict))
Expand All @@ -150,12 +147,15 @@ def test_404_500(self):
self.convert_to_json(
self.app.get('/api/not_an_endpoint'))['result'])

try:
self.app.get('/api/Presidential Election-2016/dasfasdfa/meta')
self.assertTrue(False, "Should be invalid endpoint")
except KeyError as e:
self.assertIn("dasfasdfa", str(e))

def test_stop_heroku(self):
self.assertTrue(self.DEPLOY)

# Normally in debug mode, the 500 errors are caught and diplayed nicely
# so we can quickly fix them. However to test that the api is actually
# sending a json object when something goes wrong, we need to mimic the
# production settings
cerp.app.testing = False
cerp.app.debug = False
# This stops scary messages from populating the test environ over
# something we designed to fail
cerp.app.logger.disabled = True
prod_app = cerp.app.test_client()
self.assertFalse(self.convert_to_json(prod_app.get(
'/api/Presidential Election-2016/dasfasdfa/meta'))['result'])

0 comments on commit fd2216b

Please sign in to comment.