Coverage for skema/rest/tests/test_metal_proxy.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-30 17:15 +0000

1from pathlib import Path 

2 

3from askem_extractions.data_model import AttributeCollection 

4from fastapi import status 

5 

6from skema.rest.metal_proxy import app 

7from fastapi.testclient import TestClient 

8 

9client = TestClient(app) 

10 

11 

12# def test_link_amr(): 

13# """Test that we are able to link and AMR to text extractions correctly""" 

14# amr_path = Path(__file__).parents[0] / "data" / "metal" / "SIDARTHE_AMR_uuids.json" 

15# extractions_path = Path(__file__).parents[0] / "data" / "metal" / "tr_document_results.json" 

16# 

17# params = { 

18# "similarity_model": "sentence-transformers/all-MiniLM-L6-v2", 

19# "similarity_threshold": 0.5 

20# } 

21# 

22# files = { 

23# "amr_file": amr_path.open("rb"), 

24# "text_extractions_file": extractions_path.open("rb") 

25# } 

26# 

27# response = client.post("/link_amr", params=params, files=files) 

28# 

29# assert response.status_code == 200, f"The response code for /link_amr was {response.status_code}" 

30# 

31# linked_amr = response.json() 

32# 

33# # There should be more than 5 linked AMR elements 

34# metadata = AttributeCollection(**linked_amr["metadata"]) 

35# num_linked_elements = sum([isinstance(md.amr_element_id, str) for md in metadata.attributes]) 

36# assert num_linked_elements > 5, f"Only {num_linked_elements}, should be close to 17 with the testing configuration" 

37 

38 

39def test_healthcheck(): 

40 """Test case for /healthcheck endpoint.""" 

41 response = client.get("/healthcheck") 

42 assert response.status_code in { 

43 status.HTTP_200_OK, 

44 status.HTTP_500_INTERNAL_SERVER_ERROR 

45 } 

46 

47 

48# if __name__ == "__main__": 

49# test_link_amr()