diff --git a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/simulation.py b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/simulation.py index 8a6152f749748b9990438b33fa5507c691eecd42..a99a9d73fb84565a1677d061919099151b5726dd 100644 --- a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/simulation.py +++ b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/simulation.py @@ -556,20 +556,26 @@ class Simulation(object): """ self.__delete_script('transfer-function', transfer_function_name) - def __save_experiment_data(self, experiment_data_type, experiment_data, method='put'): + def __save_experiment_data(self, experiment_data_type, experiment_data, + method='put', backend=False): """ Saves data related to the experiment. - Url format: in the format http://localhost:8080/experiment/{exp-id}/brain - + Url format: in the format http://proxy_url/proxy/{exp-id}/brain + or if backend has been set to true + http://sim_url/{exp-id}/sdf-world :param experiment_data_type: the type of experiment data to save (i.e. 'transfer-function', 'state-machine', 'brain' or 'sdf-world') :param experiment_data: the experiment data to be saved :param method: the http request to be executed. Default is: PUT + :param backend: whether this is a backend call or not """ - - url = '%s/experiment/%s/%s' % (self.__server_info['gzweb']['nrp-services'], - self.__experiment_id, - self.__config['simulation-scripts'][experiment_data_type]) + if backend: + url = '%s/%s' % (self.__sim_url, + self.__config['simulation-scripts'][experiment_data_type]) + else: + url = '%s/%s/%s' % (self.__config['proxy-services']['save-data'], + self.__experiment_id, + self.__config['proxy-save'][experiment_data_type]) try: method_fun = getattr(self.__http_client, method) status_code, _ = method_fun(url, body=experiment_data) @@ -592,8 +598,8 @@ class Simulation(object): transfer_functions_list.append(self.get_transfer_function(str(tf))) self.__save_experiment_data('transfer-function', - {'experimentId': self.__experiment_id, - 'transfer_functions': transfer_functions_list}) + {'experiment': self.__experiment_id, + 'transferFunctions': transfer_functions_list}) def save_state_machines(self): """ @@ -603,8 +609,8 @@ class Simulation(object): for sm in self.__get_simulation_scripts('state-machine')['data'].keys(): state_machines_dict[sm] = self.get_state_machine(str(sm)) - self.__save_experiment_data('state-machine', {'experimentId': self.__experiment_id, - 'state_machines': state_machines_dict}) + self.__save_experiment_data('state-machine', {'experiment': self.__experiment_id, + 'stateMachines': state_machines_dict}) def save_brain(self): """ @@ -621,14 +627,14 @@ class Simulation(object): del populations[pop]['regex'] self.save_transfer_functions() - self.__save_experiment_data('brain', {'data': pynn_script, - 'brain_populations': populations}) + self.__save_experiment_data('brain', {'brain': pynn_script, + 'populations': populations}) def save_world(self): """ Saves the current sdf world to the storage """ - return self.__save_experiment_data('sdf-world', {}, method='post') + return self.__save_experiment_data('sdf-world', {}, method='post', backend=True) def get_state_machine(self, state_machine_name): """ diff --git a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_simulation.py b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_simulation.py index 2bf450f7990fec7056d4faf13c6acd1a35f2c1d4..326e216d0d29c21c5a0ec26f6a21be3caa505372 100644 --- a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_simulation.py +++ b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_simulation.py @@ -453,10 +453,11 @@ class TestSimulation(unittest.TestCase): def test_save_experiment_data(self): exp_id = 'exp_id' serverurl = 'serverurl' + proxyurl = 'proxyurl' self._sim._Simulation__get_simulation_scripts = Mock() self._sim._Simulation__get_simulation_scripts.return_value = {'data': {'foo': ''}} - + self._sim._Simulation__sim_url = 'sim_url' self._sim.get_transfer_function = Mock() self._sim.get_transfer_function.return_value = 'bar' @@ -464,6 +465,8 @@ class TestSimulation(unittest.TestCase): self._sim.get_state_machine.return_value = 'bar' self._sim._Simulation__experiment_id = exp_id + + self._sim._Simulation__config['proxy-services']['save-data'] = proxyurl self._sim._Simulation__server_info = { 'gzweb':{ 'nrp-services': serverurl @@ -474,17 +477,16 @@ class TestSimulation(unittest.TestCase): self._sim._Simulation__http_client.put = Mock(return_value=(httplib.OK, None)) - self._sim.save_transfer_functions() - self._sim._Simulation__http_client.put.assert_called_once( - '%s/experiment/%s/state-machines' % (serverurl, exp_id), - body={'transfer_functions': 'bar','experimentId': exp_id}) + self._sim._Simulation__http_client.put.assert_called_once_with( + '%s/%s/transferFunctions' % (proxyurl, exp_id), + body={'transferFunctions': ['bar'],'experiment': exp_id}) self._sim._Simulation__http_client.put.reset_mock() self._sim.save_state_machines() self._sim._Simulation__http_client.put.assert_called_once_with( - '%s/experiment/%s/state-machines' % (serverurl, exp_id), - body={'state_machines': {'foo': 'bar'}, 'experimentId': exp_id}) + '%s/%s/stateMachines' % (proxyurl, exp_id), + body={'stateMachines': {'foo': 'bar'}, 'experiment': exp_id}) self._sim._Simulation__http_client.put.reset_mock() populations = { @@ -499,13 +501,13 @@ class TestSimulation(unittest.TestCase): self._sim.save_brain() self._sim._Simulation__http_client.put.assert_called_once_with( - '%s/experiment/%s/brain' % (serverurl, exp_id), - body={'brain_populations': populations,'data': 'some brain code'}) + '%s/%s/brain' % (proxyurl, exp_id), + body={'populations': populations,'brain': 'some brain code'}) self._sim._Simulation__http_client.post = Mock(return_value=(httplib.OK, None)) self._sim.save_world() self._sim._Simulation__http_client.post.assert_called_once_with( - '%s/experiment/%s/sdf_world' % (serverurl, exp_id), + '%s/sdf_world' % (self._sim._Simulation__sim_url), body={}) @patch('sys.stdout', new_callable=StringIO)