Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_celery_task_is_failure___result_is_failure(self):
response = self.app.get('/analysis_status/{}'.format('location'))
self.assertEqual(json.loads(response.data.decode('utf-8')), {
'id': -1,
'status': status.STATUS_FAILURE,
'message': "'message'",
'outputs_location': None,
})
@patch('src.server.app.CELERY.AsyncResult', Mock(return_value=fake_result('message', status.STATUS_FAILURE)))
def test_celery_task_is_failure___result_is_failure(self):
response = self.app.get('/analysis_status/{}'.format('location'))
self.assertEqual(json.loads(response.data.decode('utf-8')), {
'id': -1,
'status': status.STATUS_FAILURE,
'message': "'message'",
'outputs_location': None,
})
def test_celery_task_is_successful___result_is_successful(self):
response = self.app.get('/analysis_status/{}'.format('location'))
self.assertEqual(json.loads(response.data.decode('utf-8')), {
'id': -1,
'status': status.STATUS_SUCCESS,
'message': '',
'outputs_location': 'output_location',
})
def test_celery_task_is_pending___result_is_pending(self):
response = self.app.get('/analysis_status/{}'.format('location'))
self.assertEqual(json.loads(response.data.decode('utf-8')), {
'id': -1,
'status': status.STATUS_PENDING,
'message': '',
'outputs_location': None,
})
fake_result('output_location', status.STATUS_SUCCESS),
]))
def test_celery_task_is_successful_with_location_on_seccond_attempt___result_is_successful(self):
response = self.app.get('/analysis_status/{}'.format('location'))
self.assertEqual(json.loads(response.data.decode('utf-8')), {
'id': -1,
'status': status.STATUS_SUCCESS,
'message': '',
'outputs_location': 'output_location',
})
def test_lock_is_acquireable___start_analysis_is_ran(self, location, analysis_settings_path):
with patch('src.model_execution_worker.tasks.start_analysis', Mock(return_value=True)) as start_analysis_mock:
start_analysis_task.update_state = Mock()
start_analysis_task(location, analysis_settings_path)
start_analysis_task.update_state.assert_called_once_with(state=OASIS_TASK_STATUS["running"]["id"])
start_analysis_mock.assert_called_once_with(
os.path.join(settings.get('worker', 'media_root'), analysis_settings_path),
location,
complex_data_files=None
)
@patch('src.server.app.CELERY.AsyncResult', Mock(return_value=fake_result('message', status.STATUS_PENDING)))
def test_celery_task_is_pending___result_is_pending(self):
response = self.app.get('/analysis_status/{}'.format('location'))
self.assertEqual(json.loads(response.data.decode('utf-8')), {
'id': -1,
'status': status.STATUS_PENDING,
'message': '',
'outputs_location': None,
})
def session_fixture(request):
server_addr = config.get('server', 'API_HOST')
server_port = config.get('server', 'API_PORT')
server_vers = config.get('server', 'API_VERS')
server_user = config.get('server', 'API_USER')
server_pass = config.get('server', 'API_PASS')
print(request.param)
try:
server_url = 'http://{}:{}'.format(socket.gethostbyname(server_addr), server_port)
except Exception:
server_url = 'http://{}:{}'.format('localhost', server_port)
session = APIClient(server_url, server_vers, server_user, server_pass)
print(session.api.tkn_access)
return request.param, session
def run_analysis(c):
try:
upload_directory = os.path.join("upload", str(uuid.uuid1()))
shutil.copytree(
os.path.join(input_data_directory, "csv"),
upload_directory)
client = OasisAPIClient(api_url, logging.getLogger())
input_location = client.upload_inputs_from_directory(
upload_directory, do_il, do_validation=False)
client.run_analysis(
analysis_settings, input_location,
output_data_directory, do_clean=False)
c.increment_num_completed()
except Exception:
logging.exception("API test failed")
c.increment_num_failed()
@oasis_log()
def post_exposure():
"""
Upload an exposure resource
---
description: Uploads an exposure resource by posting an exposure tar file.
The tar file can be compressed or uncompressed.
produces:
- application/json
responses:
200:
description: The exposure summary of the created exposure resource.
schema:
$ref: '#/definitions/ExposureSummary'
"""
request_file = request.files['file']
filename = uuid.uuid4().hex