How to use oasislmf - 10 common examples

To help you get started, we’ve selected a few oasislmf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
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,
        })
github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
    @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,
        })
github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
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',
        })
github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
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,
        })
github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
        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',
        })
github OasisLMF / OasisPlatform / tests / test_tasks.py View on Github external
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
            )
github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
    @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,
        })
github OasisLMF / OasisPlatform / tests / integration / api_integration.py View on Github external
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
github OasisLMF / OasisPlatform / src / utils / api_tester_old.py View on Github external
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()
github OasisLMF / OasisPlatform / src / server.bak / app.py View on Github external
@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