Add test for added HTTP POST handler
This commit is contained in:
parent
1279ae2549
commit
7cebd35571
1 changed files with 31 additions and 0 deletions
31
cara/tests/apps/calculator/test_report_json.py
Normal file
31
cara/tests/apps/calculator/test_report_json.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import json
|
||||
|
||||
import tornado.testing
|
||||
|
||||
import cara.apps.calculator
|
||||
from cara.apps.calculator import model_generator
|
||||
|
||||
_TIMEOUT = 40.
|
||||
|
||||
|
||||
class TestCalculatorJsonResponse(tornado.testing.AsyncHTTPTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.http_client.defaults['request_timeout'] = _TIMEOUT
|
||||
|
||||
def get_app(self):
|
||||
return cara.apps.calculator.make_app()
|
||||
|
||||
@tornado.testing.gen_test(timeout=_TIMEOUT)
|
||||
def test_json_response(self):
|
||||
response = yield self.http_client.fetch(
|
||||
request=self.get_url("/calculator/report-json"),
|
||||
method="POST",
|
||||
headers={'content-type': 'application/json'},
|
||||
body=json.dumps(model_generator.baseline_raw_form_data())
|
||||
)
|
||||
self.assertEqual(response.code, 200)
|
||||
|
||||
data = json.loads(response.body)
|
||||
self.assertIsInstance(data['prob_inf'], float)
|
||||
self.assertIsInstance(data['expected_new_cases'], float)
|
||||
Loading…
Reference in a new issue