Ejemplo n.º 1
0
    def _test_file_get_not_found(self, replica: Replica):
        file_uuid = "ce55fd51-7833-469b-be0b-5da88ec0ffee"

        url = str(UrlBuilder().set(path="/v1/files/" + file_uuid).add_query(
            "replica", replica.name))

        with override_bucket_config(BucketConfig.TEST_FIXTURE):
            self.assertGetResponse(url,
                                   requests.codes.not_found,
                                   headers=get_auth_header(),
                                   expected_error=ExpectedErrorFields(
                                       code="not_found",
                                       status=requests.codes.not_found,
                                       expect_stacktrace=True))

        version = "2017-06-16T193604.240704Z"
        url = str(UrlBuilder().set(path="/v1/files/" + file_uuid).add_query(
            "replica", replica.name).add_query("version", version))

        with override_bucket_config(BucketConfig.TEST_FIXTURE):
            self.assertGetResponse(url,
                                   requests.codes.not_found,
                                   headers=get_auth_header(),
                                   expected_error=ExpectedErrorFields(
                                       code="not_found",
                                       status=requests.codes.not_found,
                                       expect_stacktrace=True))
    def _test_bundle_get_not_found(self, replica: Replica):
        bundle_uuid = str(uuid.uuid4())

        url = str(UrlBuilder()
                  .set(path="/v1/bundles/" + bundle_uuid)
                  .add_query("replica", replica.name))

        with override_bucket_config(BucketConfig.TEST_FIXTURE):
            self.assertGetResponse(
                url,
                requests.codes.not_found,
                expected_error=ExpectedErrorFields(
                    code="not_found",
                    status=requests.codes.not_found)
            )

        version = "2017-06-16T193604.240704Z"
        url = str(UrlBuilder()
                  .set(path="/v1/bundles/" + bundle_uuid)
                  .add_query("replica", replica.name)
                  .add_query("version", version))

        with override_bucket_config(BucketConfig.TEST_FIXTURE):
            self.assertGetResponse(
                url,
                requests.codes.not_found,
                expected_error=ExpectedErrorFields(
                    code="not_found",
                    status=requests.codes.not_found)
            )
Ejemplo n.º 3
0
    def test_search_returns_error_when_invalid_query_used(self):
        invalid_query_data = [({
            "query": {
                "mtch": {
                    "SomethingInvalid": "xxx"
                }
            }
        }, requests.codes.bad_request),
                              ({
                                  "query": {
                                      "match": ["SomethingInvalid", "xxx"]
                                  }
                              }, requests.codes.bad_request)]

        self.populate_search_index(self.index_document, 1)
        url = self.build_url()
        for bad_query, error in invalid_query_data:
            with self.subTest(msg="Invalid Queries:",
                              bad_query=bad_query,
                              error=error):
                self.assertPostResponse(
                    path=url,
                    headers=get_auth_header(),
                    json_request_body=dict(es_query=bad_query),
                    expected_code=error,
                    expected_error=ExpectedErrorFields(
                        code="elasticsearch_bad_request", status=error))
Ejemplo n.º 4
0
 def test_exptime(self):
     self.assertGetResponse("/internal/slow_request",
                            requests.codes.gateway_timeout,
                            expected_error=ExpectedErrorFields(
                                code="timed_out",
                                status=requests.codes.gateway_timeout,
                            ))
Ejemplo n.º 5
0
 def test_synthetic_504(self):
     file_uuid = str(uuid.uuid4())
     r = self.assertGetResponse(f"/v1/files/{file_uuid}?replica=aws",
                                requests.codes.gateway_timeout,
                                expected_error=ExpectedErrorFields(
                                    code="timed_out",
                                    status=requests.codes.gateway_timeout,
                                ),
                                headers={
                                    "DSS_FAKE_504_PROBABILITY": "1.0",
                                })
     with self.subTest(
             'Retry-After headers are included in a GET /v1/bundles/{uuid} 504 response.'
     ):
         self.assertEqual(int(r.response.headers['Retry-After']), 10)
Ejemplo n.º 6
0
    def test_file_get_no_replica(self):
        """
        Verify we raise the correct error code when we provide no replica.
        """
        file_uuid = "ce55fd51-7833-469b-be0b-5da88ec0ffee"

        url = str(UrlBuilder().set(path="/v1/files/" + file_uuid))

        with override_bucket_config(BucketConfig.TEST_FIXTURE):
            self.assertGetResponse(url,
                                   requests.codes.bad_request,
                                   headers=get_auth_header(),
                                   expected_error=ExpectedErrorFields(
                                       code="illegal_arguments",
                                       status=requests.codes.bad_request,
                                       expect_stacktrace=True))
Ejemplo n.º 7
0
    def test_no_files(self):
        """
        Verify we raise the correct error code when we do not provide the list of files.
        """
        bundle_uuid = "ce55fd51-7833-469b-be0b-5da88ec0ffee"

        url = str(UrlBuilder().set(path="/v1/bundles/" +
                                   bundle_uuid).add_query("replica", "aws"))

        with override_bucket_config(BucketConfig.TEST_FIXTURE):
            self.assertPutResponse(url,
                                   requests.codes.bad_request,
                                   json_request_body=dict(creator_uid=12345, ),
                                   expected_error=ExpectedErrorFields(
                                       code="illegal_arguments",
                                       status=requests.codes.bad_request,
                                       expect_stacktrace=True))
Ejemplo n.º 8
0
 def test_search_session_expired_when_session_deleted(self):
     self.populate_search_index(self.index_document, 20)
     self.check_count(smartseq2_paired_ends_v3_query, 20)
     url = self.build_url({"per_page": 10})
     search_obj = self.assertPostResponse(
         path=url,
         json_request_body=dict(es_query=smartseq2_paired_ends_v3_query),
         expected_code=requests.codes.partial)
     self.verify_search_result(search_obj.json,
                               smartseq2_paired_ends_v3_query, 20, 10)
     next_url = self.get_next_url(search_obj.response.headers)
     scroll_id = self.verify_next_url(next_url, 10)
     es_client = ElasticsearchClient.get()
     es_client.clear_scroll(scroll_id)
     self.assertPostResponse(
         path=self.strip_next_url(next_url),
         json_request_body=dict(es_query=smartseq2_paired_ends_v3_query),
         expected_code=requests.codes.not_found,
         expected_error=ExpectedErrorFields(
             code="elasticsearch_context_not_found",
             status=requests.codes.not_found))
Ejemplo n.º 9
0
 def test_error_returned_when_per_page_is_out_of_range(self):
     expected_error = ExpectedErrorFields(code="illegal_arguments",
                                          status=requests.codes.bad_request,
                                          expect_stacktrace=True)
     per_page_tests = [
         (9, {
             'expected_code': requests.codes.bad_request,
             'expected_error': expected_error
         }),  # min is 10
         (501, {
             'expected_code': requests.codes.bad_request,
             'expected_error': expected_error
         })
     ]  # max is 500
     for per_page, expected in per_page_tests:
         url = self.build_url({"per_page": per_page})
         with self.subTest(per_page=per_page, expected=expected):
             self.assertPostResponse(
                 path=url,
                 json_request_body=dict(
                     es_query=smartseq2_paired_ends_v3_query),
                 **expected)