Skip to content

WIP: adding tests

WIP: adding tests #860

This check has been archived and is scheduled for deletion. Learn more about checks retention
GitHub Actions / Black failed Dec 14, 2023 in 0s

17 errors

Black found 17 errors

Annotations

Check failure on line 22 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/__init__.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/__init__.py#L15-L22

     "add_identifier_to_resource_type",
     "external_request",
     "internal_patient_search",
     "new_resource_hook",
     "sync_bundle",
-    "restore_patient"
+    "restore_patient",
 ]

Check failure on line 103 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L85-L103

 
 @fixture
 def internal_patient_duplicate_inactive_match(datadir):
     return load_json(datadir, "internal_patient_duplicate_inactive_match.json")
 
+
 def test_new_upsert(
     client,
     mocker,
     faux_token,
     external_patient_search,
     internal_patient_miss,
     new_patient,
-    ):
+):
     """Without finding a matching patient, should insert new and return"""
 
     # Mock HAPI search failing to find a matching patient
     mocker.patch(
         "patientsearch.models.sync.requests.get",

Check failure on line 129 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L117-L129

     client,
     mocker,
     faux_token,
     external_patient_search_active,
     internal_patient_miss,
-    new_patient_active
-    ):
+    new_patient_active,
+):
     """Without finding a matching patient, should insert new and return"""
 
     # Mock HAPI search failing to find a matching patient
     mocker.patch(
         "patientsearch.models.sync.requests.get",

Check failure on line 155 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L143-L155

     client,
     mocker,
     faux_token,
     external_patient_search_active,
     internal_patient_miss,
-    new_patient_active
-    ):
+    new_patient_active,
+):
     """Finding a matching inactive patient, user chose to generate new patient"""
 
     # Mock HAPI search finding a matching inactive
     mocker.patch(
         "patientsearch.models.sync.requests.get",

Check failure on line 189 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L174-L189

         assert len(entry["identifier"]) == 1
         assert entry["identifier"][0] == ident
 
 
 def test_existing(
-    client, 
-    mocker, 
-    faux_token, 
-    external_patient_search, 
-    internal_patient_match, 
+    client,
+    mocker,
+    faux_token,
+    external_patient_search,
+    internal_patient_match,
 ):
     """Finding a matching patient, return existing"""
 
     # Mock HAPI search finding a matching patient
     mocker.patch(

Check failure on line 208 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L193-L208

     result = sync_bundle(faux_token, external_patient_search)
     assert result == internal_patient_match["entry"][0]["resource"]
 
 
 def test_existing_active(
-    client, 
-    mocker, 
-    faux_token, 
-    external_patient_search_active,
-    internal_patient_active_match, 
+    client,
+    mocker,
+    faux_token,
+    external_patient_search_active,
+    internal_patient_active_match,
 ):
     """Finding a matching active patient from active external search, return existing"""
 
     # Mock HAPI search finding a matching active patient
     mocker.patch(

Check failure on line 231 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L212-L231

     result = sync_bundle(faux_token, external_patient_search_active)
     assert result != internal_patient_active_match["entry"][0]["resource"]
 
 
 def test_existing_inactive(
-    client, 
-    mocker, 
-    faux_token, 
-    external_patient_search_active,
-    internal_patient_inactive_match
+    client,
+    mocker,
+    faux_token,
+    external_patient_search_active,
+    internal_patient_inactive_match,
 ):
     """Finding a matching inactive patient from active external search, return existing restored"""
 
-    # Mock HAPI search finding a matching inactive patient 
+    # Mock HAPI search finding a matching inactive patient
     # when the service is called for the patient to be restored
     mocker.patch(
         "patientsearch.models.sync.requests.get",
         return_value=mock_response(internal_patient_inactive_match),
     )

Check failure on line 247 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L232-L247

     result = sync_bundle(faux_token, external_patient_search_active)
     assert result == internal_patient_inactive_match["entry"][0]["resource"]
 
 
 def test_existing_modified(
-    client,
-    mocker, 
-    faux_token, 
-    external_patient_search, 
-    internal_patient_match
+    client, mocker, faux_token, external_patient_search, internal_patient_match
 ):
     """Confirm modified external details get synchronized"""
 
     # Mock HAPI search finding a matching patient (w/o the identifier)
     assert "identifier" not in internal_patient_match["entry"][0]["resource"]

Check failure on line 278 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L268-L278

     # Confirm we get back the identified/patched patient from the PUT
     result = sync_bundle(faux_token, external_patient_search_w_identifier)
     assert result == identified_internal
     assert result["identifier"] == [found_identifier]
 
+
 def test_duplicate(
     client,
     mocker,
     faux_token,
     external_patient_search,

Check failure on line 332 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/tests/test_sync.py#L326-L332

     )
 
     # Shouldn't kill the process, but return the first
     result = sync_bundle(faux_token, external_patient_search_active)
     assert result == internal_patient_duplicate_inactive_match["entry"][0]["resource"]
-

Check failure on line 208 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py#L197-L208

 
     if not different(src_patient, internal_patient):
         # If patient is active, proceed. If not, re-activate
         if internal_patient.get("active") != True:
             return internal_patient
-        
+
         params = patient_as_search_params(internal_patient)
         # Ensure it is active
         internal_patient["active"] = True
         return HAPI_request(
             token=token,

Check failure on line 235 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py#L224-L235

             resource=internal_patient,
             resource_id=internal_patient["id"],
         )
 
 
-def patient_as_search_params(patient, active_only = False):
+def patient_as_search_params(patient, active_only=False):
     """Generate HAPI search params from patient resource"""
 
     # Use same parameters sent to external src looking for existing Patient
     # Note FHIR uses list for 'name' and 'given', common parameter use defines just one
     search_map = (

Check failure on line 268 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py#L247-L268

             ("name.given[0]", "given", ""),
             ("name[0].given[0]", "given", ""),
             ("birthDate", "birthdate", "eq"),
             ("active", True, "eq"),
         )
-        
+
     search_params = {}
 
     for path, queryterm, compstr in search_map:
         match = json_search(path, patient)
         if match and isinstance(match, str):
             search_params[queryterm] = compstr + match
     return search_params
 
 
-def internal_patient_search(token, patient, active_only = False):
+def internal_patient_search(token, patient, active_only=False):
     """Look up given patient from "internal" HAPI store, returns bundle"""
     params = patient_as_search_params(patient, active_only)
 
     return HAPI_request(
         token=token, method="GET", resource_type="Patient", params=params

Check failure on line 322 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/models/sync.py#L301-L322

             current_app.logger.warning(
                 f"expected ONE matching patient, found {match_count}"
             )
 
         internal_patient = internal_search["entry"][0]["resource"]
-        #TODO: ask whether they prefer to merge and update active value or to start a new Patient for each sync attempt toward a non-active patient. 
+        # TODO: ask whether they prefer to merge and update active value or to start a new Patient for each sync attempt toward a non-active patient.
         merged_patient = _merge_patient(
             src_patient=patient, internal_patient=internal_patient, token=token
         )
         return merged_patient
 
     # No match, insert and return
     patient = new_resource_hook(resource=patient)
     patient["active"] = True
     return HAPI_request(
-        token=token, method="POST", resource_type="Patient", resource=patient,
+        token=token,
+        method="POST",
+        resource_type="Patient",
+        resource=patient,
     )
 
 
 def restore_patient(token, patient):
     """Restore single internal patient resource"""

Check failure on line 33 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/api.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/api.py#L22-L33

     add_identifier_to_resource_type,
     external_request,
     internal_patient_search,
     new_resource_hook,
     sync_bundle,
-    restore_patient
+    restore_patient,
 )
 from patientsearch.extensions import oidc
 from patientsearch.jsonify_abort import jsonify_abort
 
 api_blueprint = Blueprint("patientsearch-api", __name__)

Check failure on line 514 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/api.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/api.py#L503-L514

             extra["patient"]["subject.id"] = local_fhir_patient["id"]
     else:
         # See if local match already exists
         patient = resource_from_args(resource_type, request.args)
         try:
-            internal_bundle = internal_patient_search(token, patient, not reinstate_patient)
+            internal_bundle = internal_patient_search(
+                token, patient, not reinstate_patient
+            )
         except (RuntimeError, ValueError) as error:
             return jsonify_abort(status_code=400, message=str(error))
         local_fhir_patient = None
         if internal_bundle["total"] > 0:
             local_fhir_patient = internal_bundle["entry"][0]["resource"]

Check failure on line 544 in /home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/api.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/cosri-patientsearch/cosri-patientsearch/patientsearch/api.py#L533-L544

                 resource_type=resource_type,
                 resource=patient,
             )
             patient["active"] = True
             local_fhir_patient = HAPI_request(
-                token=token, method=method, resource_type="Patient", resource=patient)
+                token=token, method=method, resource_type="Patient", resource=patient
+            )
         except (RuntimeError, ValueError) as error:
             return jsonify_abort(status_code=400, message=str(error))
         audit_entry(
             "PDMP search failed; create new patient from search params", extra=extra
         )