Ejemplo n.º 1
0
    def test_process(self):
        headers = {'content-type': 'application/json'}
        with TestClient(fastapi_app_factory.build(NoopAnnotator())) as client:
            request = ""
            response = client.post(BASE_URL + "/process", request, headers=headers)
            assert response.status_code == 400

            # ignore empty container
            request = json.dumps({})
            response = client.post(BASE_URL + "/process", request, headers=headers)
            assert response.status_code == 200
            assert response.text == request

            # real container
            request = json.dumps(EXAMPLE_REQUEST)
            response = client.post(BASE_URL + "/process", request, headers=headers)
            assert response.status_code == 200

            # bad mime type
            request = json.dumps(EXAMPLE_REQUEST)
            response = client.post(BASE_URL + "/process", request, headers={'content-type': 'plain/text'})
            assert response.status_code == 415

            # bad mime type trumps bad json parse body
            response = client.post(BASE_URL + "/process", "{:asdfasdf", headers={'content-type': 'plain/text'})
            assert response.status_code == 415

            # we require an unstructured container at the top level. You can
            # add unknown stuff to the inside and we'll pass it through, but not at the top level.
            request = json.dumps({"bogus": {}})
            response = client.post(BASE_URL + "/process", request, headers=headers)
            assert response.status_code == 400
Ejemplo n.º 2
0
 def test_invalid_container_error(self):
     headers = {'content-type': 'application/json'}
     example_container = {
         "unstructured": [
             {
                 "text": "The patient reports severe bowel discomfort for the last week.",
                 "data": {
                     "concepts": [
                         {
                             "cui": "C1096594",
                             "preferredName": "bowel discomfort",
                             "semanticType": "sosy",
                             "source": "umls",
                             "sourceVersion": "2020AA",
                             "type": "umls.SignOrSymptom",
                             "begin": 27,
                             "end": 43,
                             "coveredText": "bowel discomfort",
                             "vocabs": "CHV"
                         }
                     ]
                 }
             }
         ]
     }
     with TestClient(fastapi_app_factory.build(InvalidContainerModelErrorAnnotator())) as client:
         response = client.post(BASE_URL + "/process", json.dumps(example_container), headers=headers)
         assert response.status_code == 500
Ejemplo n.º 3
0
 def test_process_error(self):
     headers = {'content-type': 'application/json'}
     with TestClient(fastapi_app_factory.build(ErrorAnnotator())) as client:
         # ErrorAnnotator should blow up when it sees a real request
         request = json.dumps(EXAMPLE_REQUEST)
         response = client.post(BASE_URL + "/process", request, headers=headers)
         assert response.status_code == 500
def client():
    """
    This fixture is run once per test class, and it
    gives us a chance to do setup/teardown logic
    using "with" syntax. This is important because
    TestClient only calls on_event("startup") in the
    context of "with" syntax (when client.__enter__() is called)
    :return:
    """
    print("starting test server")
    app = fastapi_app_factory.build(StanzaSentenceAnnotator())
    with TestClient(app) as client:
        yield client
    print("shutting down test server")
def client():
    """
    This fixture is run once per test class, and it
    gives us a chance to do setup/teardown logic
    using "with" syntax. This is important because
    TestClient only calls on_event("startup") in the
    context of "with" syntax (when client.__enter__() is called)
    :return:
    """
    print("starting test server")
    # codes below ordered from less->more specific: ["cancer", "lung cancer", "non-small-cell lung cancer"]
    LUNG_CANCER_CODE_HIERARCHY = ['363346000', '93880001', '254637007']
    app = fastapi_app_factory.build(
        CodeResolutionAnnotator(LUNG_CANCER_CODE_HIERARCHY))
    with TestClient(app) as client:
        yield client
    print("shutting down test server")
Ejemplo n.º 6
0
def app():
    # create the standard ACD endpoints using a factory constructor.
    myapp = fastapi_app_factory.build(BMIAnnotator(),
                                      example_request='''{
  "structured" : [ {
    "data" : {
       "heightInches" : 70,
       "weightPounds" : 170
    }
   }
  ]
}''')

    # add an additional custom endpoint
    @myapp.get(fastapi_app_factory.BASE_URL + "/my_custom_endpoint")
    async def custom_endpoint(request: Request):
        """An example of how to add a custom endpoint to your microservice beyond the standard ACD endpoints."""
        return {"someData": "Goes Here"}

    return myapp
Ejemplo n.º 7
0
def app():
    return fastapi_app_factory.build(SpacySentenceAnnotator())
Ejemplo n.º 8
0
def app():
    return fastapi_app_factory.build(RegexAnnotator(regex_patterns))
Ejemplo n.º 9
0
 def test_status_error(self):
     with TestClient(fastapi_app_factory.build(ErrorAnnotator())) as client:
         response = client.get(BASE_URL + "/status/health_check")
         assert response.status_code == 500