Ejemplo n.º 1
0
 def run():
     try:
         results = run_simulation(run_params)
         self._results[params_hash] = result(
             'success',
             results=results)
     except ParseError as e:
         self._results[params_hash] = result(
             'error',
             message=e.message)
Ejemplo n.º 2
0
async def test_simulate_route(cli):
    for req_data in TEST_DATA:
        # Unpack the initial values
        simulation_name = req_data['name']
        simulation_parameters = req_data['parameters']

        # Determine the expected results by calling the simulator directly
        expected_simulation_results_frame = run_simulation(
            simulation_parameters)

        # Roundtrip the results through our JSON encoder to get data the same
        # shape - note that this means that any flaws in the JSON encoder will
        # NOT be revealed by this test.
        expected_simulation_results_json = json.dumps(
            expected_simulation_results_frame,
            cls=DataFrameJSONEncoder)
        expected_simulation_results_dict = json.loads(
            expected_simulation_results_json)

        # First request the results URL
        resp = await cli.post(
            '/simulate',
            data=json.dumps({'name': simulation_name,
                             'parameters': simulation_parameters}))
        assert resp.status == 200
        data = await resp.json()
        # assert resp['result-id'] == 'asdfadsfa'

        # Now request the result
        resp = await cli.get(
            '/simulation/{}'.format(data['result-id']))
        assert resp.status == 200
        data = await resp.json()

        # Do they match?
        assert data['status'] == 'success'
        assert data['name'] == simulation_name
        assert data['params'] == simulation_parameters
        assert data['results'] == expected_simulation_results_dict
Ejemplo n.º 3
0
 def run():
     try:
         results = run_simulation(run_params)
         self._results[params_hash] = result('success', results=results)
     except ParseError as e:
         self._results[params_hash] = result('error', message=e.message)