Skip to content

Commit

Permalink
fixing test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
shamlymajeed committed Apr 8, 2024
1 parent 718bca9 commit 4f60fa9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions ingest/api/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
self,
mqtt_conf: dict,
uuid_prefix: str,
testing: bool,
schema_path=None,
schema_file=None,
):
Expand All @@ -45,6 +46,8 @@ def __init__(
with open(esoh_mqtt_schema, "r") as file:
self.esoh_mqtt_schema = json.load(file)
self.schema_validator = Draft202012Validator(self.esoh_mqtt_schema)
if testing is True:
return

if mqtt_conf["host"] is not None:
if "username" in mqtt_conf:
Expand Down Expand Up @@ -117,9 +120,9 @@ def _build_messages(self, message: Union[str, object], input_type: str = None) -
if isinstance(message, str):
input_type = self._decide_input_type(message)
else:
logger.critical("Illegal usage, not allowed to input" + "objects without specifying input type")
logger.critical("Illegal usage, not allowed to input" + " objects without specifying input type")
raise HTTPException(
status_code=400,
detail="Illegal usage, not allowed to input" + "objects without specifying input type",
detail="Illegal usage, not allowed to input" + " objects without specifying input type",
)
return messages(message, input_type, self.uuid_prefix, self.schema_path, self.schema_validator)
6 changes: 3 additions & 3 deletions ingest/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Response(BaseModel):
@app.post("/nc")
async def upload_netcdf_file(files: UploadFile, input_type: str = "nc"):
try:
ingester = IngestToPipeline(mqtt_conf=mqtt_configuration, uuid_prefix="uuid")
ingester = IngestToPipeline(mqtt_conf=mqtt_configuration, uuid_prefix="uuid", testing=True)
contents = await files.read()
ds = xr.open_dataset(io.BytesIO(contents))
ingester.ingest(ds, input_type)
Expand All @@ -51,7 +51,7 @@ async def upload_netcdf_file(files: UploadFile, input_type: str = "nc"):
@app.post("/bufr")
async def upload_bufr_file(files: UploadFile, input_type: str = "bufr"):
try:
ingester = IngestToPipeline(mqtt_conf=mqtt_configuration, uuid_prefix="uuid")
ingester = IngestToPipeline(mqtt_conf=mqtt_configuration, uuid_prefix="uuid", testing=True)
contents = await files.read()
# filename = files.filename
ingester.ingest(contents, input_type)
Expand All @@ -68,7 +68,7 @@ async def upload_bufr_file(files: UploadFile, input_type: str = "bufr"):
@app.post("/json")
async def post_json(request: JsonMessageSchema, input_type: str = "json") -> Response:
try:
ingester = IngestToPipeline(mqtt_conf=mqtt_configuration, uuid_prefix="uuid")
ingester = IngestToPipeline(mqtt_conf=mqtt_configuration, uuid_prefix="uuid", testing=True)
ingester.ingest(request.dict(exclude_none=True), input_type)

except HTTPException as httpexp:
Expand Down
6 changes: 4 additions & 2 deletions ingest/test/test_ingest_to_pipeline_errors.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import pytest
import xarray as xr
from fastapi import HTTPException


from api.ingest import IngestToPipeline


def test_build_message_errors():
msg_build = IngestToPipeline(None, "testing", testing=True)

with pytest.raises(TypeError):
with pytest.raises(HTTPException):
msg_build._build_messages(xr.Dataset())


def test_decide_input_type():
msg_build = IngestToPipeline(None, "testing", testing=True)

with pytest.raises(ValueError):
with pytest.raises(HTTPException):
msg_build._decide_input_type("this_has_no_filetype")
4 changes: 2 additions & 2 deletions ingest/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_post_json_success(test_app, monkeypatch):
response = test_app.post("/json?input_type=json", json=json_data)
assert response.status_code == 200

assert response.json() == {"status_message": "Success", "status_code": 200}
assert response.json() == {"status_message": "Successfully ingested", "status_code": 200}


def test_post_json_failure(test_app, monkeypatch):
Expand All @@ -30,4 +30,4 @@ def test_post_json_failure(test_app, monkeypatch):

response = test_app.post("/json?input_type=json", json=json_data)
assert response.status_code == 200
assert response.json() == {"status_message": "Success", "status_code": 200}
assert response.json() == {"status_message": "Successfully ingested", "status_code": 200}

1 comment on commit 4f60fa9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py584621%24–69
datastore_pb2_grpc.py432347%37–52, 85–87, 92–94, 99–101, 106–108, 112–136, 174, 191, 208, 225
grpc_getter.py201145%15–16, 20–23, 27–29, 33–35
locustfile.py15150%1–31
main.py34585%41, 51–52, 62–63
metadata_endpoints.py552555%42–51, 55, 72–151, 155
response_classes.py50100% 
utilities.py681972%15, 33, 40, 62–65, 73–80, 85–92, 112, 116, 118
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   \_\_init\_\_.py110100% 
   covjson.py53198%75
   geojson.py15287%17, 42
routers
   \_\_init\_\_.py00100% 
   edr.py121794%131, 143, 151, 264–265, 310–311
   feature.py461959%75–108, 124–129, 135–157
TOTAL55017369% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
23 0 💤 0 ❌ 0 🔥 2.035s ⏱️

Please sign in to comment.