Пример #1
0
    def test_post_matrix_with_fields_and_feature_ok(
            self, mock_cw_put, mock_lambda_invoke, mock_dynamo_create_request):
        filter_ = {"op": ">", "field": "foo", "value": 42}
        format_ = MatrixFormat.LOOM.value

        body = {
            'filter': filter_,
            'format': format_,
            'fields': ["test.field1", "test.field2"],
            'feature': "transcript"
        }

        response = core.post_matrix(body)
        body.update({'request_id': mock.ANY})
        body.pop('format')

        mock_lambda_invoke.assert_called_once_with(LambdaName.DRIVER_V1, body)
        mock_dynamo_create_request.assert_called_once_with(
            mock.ANY, format_, ["test.field1", "test.field2"], "transcript")
        mock_cw_put.assert_called_once_with(metric_name=MetricName.REQUEST,
                                            metric_value=1)
        self.assertEqual(type(response[0]['request_id']), str)
        self.assertEqual(response[0]['status'],
                         MatrixRequestStatus.IN_PROGRESS.value)
        self.assertEqual(response[1], requests.codes.accepted)
Пример #2
0
    def test_post_matrix_with_just_filter_ok(self, mock_cw_put,
                                             mock_lambda_invoke,
                                             mock_dynamo_create_request):
        filter_ = {"op": ">", "field": "foo", "value": 42}
        format_ = MatrixFormat.LOOM.value

        body = {'filter': filter_, 'format': format_}

        response = core.post_matrix(body)
        body.update({'request_id': mock.ANY})
        body.update({'fields': constants.DEFAULT_FIELDS})
        body.update({'feature': constants.DEFAULT_FEATURE})
        body.update({"genus_species": GenusSpecies.HUMAN.value})
        body.pop('format')

        mock_lambda_invoke.assert_called_once_with(LambdaName.DRIVER_V1, body)
        mock_dynamo_create_request.assert_called_once_with(
            mock.ANY, format_, constants.DEFAULT_FIELDS, "gene",
            GenusSpecies.HUMAN)
        mock_cw_put.assert_called_once_with(metric_name=MetricName.REQUEST,
                                            metric_value=1)
        self.assertEqual(type(response[0]['request_id']), str)
        self.assertEqual(response[0]['status'],
                         MatrixRequestStatus.IN_PROGRESS.value)
        self.assertEqual(response[1], requests.codes.accepted)
Пример #3
0
    def test_post_matrix_with_ids_ok_and_unexpected_format(
            self, mock_lambda_invoke):
        bundle_fqids = ["id1", "id2"]
        format = "fake"

        body = {'bundle_fqids': bundle_fqids, 'format': format}
        response = core.post_matrix(body)
        self.assertEqual(response[1], requests.codes.bad_request)
Пример #4
0
    def test_post_matrix_with_ids_and_url(self, mock_lambda_invoke):
        bundle_fqids = ["id1", "id2"]
        bundle_fqids_url = "test_url"

        body = {
            'bundle_fqids': bundle_fqids,
            'bundle_fqids_url': bundle_fqids_url
        }
        response = core.post_matrix(body)

        self.assertEqual(mock_lambda_invoke.call_count, 0)
        self.assertEqual(response[1], requests.codes.bad_request)
Пример #5
0
    def test_post_matrix_with_species(self, mock_cw_put, mock_lambda_invoke,
                                      mock_dynamo_create_request):
        filter_ = {
            "op": "=",
            "field": "cell_suspension.genus_species.ontology_label",
            "value": "monkey whatever"
        }
        format_ = MatrixFormat.LOOM.value

        body = {'filter': filter_, 'format': format_}

        response = core.post_matrix(body)

        body.update({'request_id': mock.ANY})
        body.update({'fields': constants.DEFAULT_FIELDS})
        body.update({'feature': constants.DEFAULT_FEATURE})
        body.pop('format')

        genera_species = list(GenusSpecies)
        self.assertEqual(mock_lambda_invoke.call_count, len(genera_species))
        self.assertEqual(mock_dynamo_create_request.call_count,
                         len(genera_species))
        self.assertEqual(mock_cw_put.call_count, len(genera_species))

        for gs in genera_species:
            gs_body = body.copy()
            gs_body["genus_species"] = gs.value
            mock_lambda_invoke.assert_any_call(LambdaName.DRIVER_V1, gs_body)

            mock_dynamo_create_request.assert_any_call(
                mock.ANY, format_, constants.DEFAULT_FIELDS,
                constants.DEFAULT_FEATURE, gs)

        self.assertEqual(type(response[0]['request_id']), str)
        self.assertEqual(type(response[0]['non_human_request_ids']), dict)
        self.assertIn("Mus musculus", response[0]["non_human_request_ids"])
        self.assertEqual(response[0]['status'],
                         MatrixRequestStatus.IN_PROGRESS.value)
        self.assertEqual(response[1], requests.codes.accepted)
Пример #6
0
    def test_post_matrix_without_ids_or_url(self, mock_lambda_invoke):
        response = core.post_matrix({})

        self.assertEqual(mock_lambda_invoke.call_count, 0)
        self.assertEqual(response[1], requests.codes.bad_request)