| open_ai_mock = <MagicMock name='invoke' id='140671129753472'>
|
| open_ai_classification_mock = <AsyncMock name='ainvoke' id='140671129721616'>
|
| project_type = 'Document Discovery', file_input = 'supply-of-goods.docx'
|
| expected = 200, client = <FlaskClient <Flask 'app'>>
|
| tokens = {'access_token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTcxMTQzODc5MSwianRpIjoiZmRhM2UzNTY...xUDdHaFBjMXBndjg4YlJyM0h6TDFvZFp3OHVoX2ptZnFJUmhrZ1haVW5vNDc5ZTEzNWk0PSJ9.mVBi18z9VoqakzecGyKdBZ9fQgp9gqws8u8NDi08mu8'}
|
| work_flow_cache = {'assistant_info': {'id': 'b1241259f3a8457aaba012f800ca78e9', 'instructions': 'you are a legal assistant called Leah w...create_uid': '098b9e13401d4508ba61345b77f89fd7', ...}, ...]}}}, 'new_user_id': '3f6d19e71eea4e48a74bf06b231729d9', ...}
|
|
|
| @pytest.mark.parametrize(
|
| "project_type,file_input, expected",
|
| [
|
| (
|
| "Document Discovery",
|
| "supply-of-goods.docx",
|
| 200,
|
| ),
|
| (
|
| "Document Extraction",
|
| "dell.docx",
|
| 200,
|
| ),
|
| (
|
| "Document Redraft",
|
| "dell.docx",
|
| 200,
|
| ),
|
| (
|
| "Document Review",
|
| "dell.doc",
|
| 200,
|
| ),
|
| (
|
| "Playbook Builder",
|
| "dell.docx",
|
| 200,
|
| ),
|
|
|
| ("Document Redraft", "test.txt", 422),
|
| ("Leah Connect", "dell.docx", 200),
|
| ],
|
| )
|
| @mock.patch("utils.LLM.model.ChatOpenAI.ainvoke")
|
| @mock.patch("utils.LLM.model.ChatOpenAI.invoke")
|
| def test_document_upload(
|
| open_ai_mock,
|
| open_ai_classification_mock,
|
| project_type,
|
| file_input,
|
| expected,
|
| client: FlaskClient,
|
| tokens: Dict[str, str],
|
| work_flow_cache: Dict[str, Any],
|
| ):
|
| with open(
|
| Path(__file__).parent / "test_data/test_langchain_data.json", encoding="utf-8"
|
| ) as lang_fp:
|
| openai_sample = json.load(lang_fp)
|
| ai_data = openai_sample["upload"]
|
| metadata = ai_data["document"]["open_ai"]["metadata"]
|
| clause = ai_data["document"]["open_ai"]["clause"]
|
| mock_open_ai = mock.MagicMock(name="__call__").return_value
|
| if project_type == "Document Redraft":
|
| metadata["party_metadata"][0].update(
|
| {
|
| "mapped_model": "NDA Unilateral - Disclosing Party Model",
|
| "mapped_model_id": work_flow_cache["functions"]["redline"][
|
| "platform"
|
| ]["model_id"],
|
| "reasoning": "Test description",
|
| }
|
| )
|
| metadata["party_metadata"][1].update(
|
| {
|
| "mapped_model": "NDA Unilateral - Disclosing Party Model",
|
| "mapped_model_id": work_flow_cache["functions"]["redline"][
|
| "platform"
|
| ]["model_id"],
|
| "reasoning": "Test description",
|
| }
|
| )
|
| mock_open_ai.content = json.dumps(metadata)
|
| open_ai_mock.return_value = mock_open_ai
|
| open_ai_classification_mock.return_value = mock.MagicMock(name="ainvoke", content= json.dumps(clause))
|
|
|
| project_id = work_flow_cache["projects"][project_type]
|
| token = tokens["access_token"]
|
| with open(Path(__file__).parent / f"documents/{file_input}", "rb") as document:
|
| result = client.post(
|
| path="/v1/upload_doc",
|
| data={
|
| "file1": (document, file_input),
|
| "project_id": project_id,
|
| "project_type": project_type,
|
| },
|
| headers={"Authorization": f"Bearer {token}"},
|
| )
|
| > assert result.status_code == expected
|
| E assert 422 == 200
|
| E + where 422 = <WrapperTestResponse streamed [422 UNPROCESSABLE ENTITY]>.status_code
|
|
|
| tests/test_14_resource_upload.py:98: AssertionError
|