@@ -91,36 +91,45 @@ def test_create_document_presign_fails():
9191
9292
9393def test_create_document_virus (test_data ):
94- record = {
95- "ods" : "H81109" ,
96- "nhs_number" : "9730154260" ,
97- }
94+ record = {"ods" : "H81109" , "nhs_number" : "9730154260" }
9895 payload = pdm_data_helper .create_upload_payload (record )
9996
10097 raw_upload_response = upload_document (payload )
10198 assert raw_upload_response .status_code == 200
10299 record ["id" ] = raw_upload_response .json ()["id" ].split ("~" )[1 ]
103100 test_data .append (record )
104101
105- # Presigned upload
106102 upload_response = raw_upload_response .json ()
107103 presign_uri = upload_response ["content" ][0 ]["attachment" ]["url" ]
108104 del upload_response ["content" ][0 ]["attachment" ]["url" ]
109- sample_pdf_path = os .path .join (os .path .dirname (__file__ ), "files" , "dummy.pdf" )
110- with open (sample_pdf_path , "rb" ) as f :
111- presign_response = requests .put (presign_uri , files = {"file" : f })
112- assert presign_response .status_code == 200
113-
114- def condition (response_json ):
115- logging .info (response_json )
116- return response_json .get ("docStatus" , False ) == "cancelled"
117-
118- raw_retrieve_response = retrieve_document_with_retry (
119- upload_response ["id" ], condition
120- )
121- retrieve_response = raw_retrieve_response .json ()
122105
123- assert retrieve_response ["docStatus" ] == "cancelled"
106+ try :
107+ # Create EICAR file
108+ eicar_path = os .path .join (os .path .dirname (__file__ ), "files" , "eicar.com" )
109+ eicar_base64 = "WDVPIVAlQEFQWzRcUFpYNTRQXlkyQ0MpN30kRUlDQVItU1RBTkRBUkQtQU5USVZJUlUtVEVTVC1GSUxFISRIK0gq"
110+ with open (eicar_path , "wb" ) as f :
111+ f .write (base64 .b64decode (eicar_base64 ))
112+
113+ # Upload EICAR file to presigned URL
114+ with open (eicar_path , "rb" ) as f :
115+ presign_response = requests .put (presign_uri , files = {"file" : f })
116+ assert presign_response .status_code == 200
117+
118+ def condition (response_json ):
119+ logging .info (response_json )
120+ return response_json .get ("docStatus" , False ) == "cancelled"
121+
122+ raw_retrieve_response = retrieve_document_with_retry (
123+ upload_response ["id" ], condition
124+ )
125+ retrieve_response = raw_retrieve_response .json ()
126+
127+ assert retrieve_response ["docStatus" ] == "cancelled"
128+
129+ finally :
130+ # Delete the EICAR file
131+ if os .path .exists (eicar_path ):
132+ os .remove (eicar_path )
124133
125134
126135@pytest .mark .parametrize (
0 commit comments