44
55from mindee .v2 .product .extraction .rag_documents import (
66 ExtractionRagAnnotationResponse ,
7+ RagAnnotation ,
78 RagDocumentAnnotationParameters ,
89 RagDocumentUploadParameters ,
910)
1819)
1920from tests .utils import V2_PRODUCT_PATH
2021
22+ expected_annotation = {
23+ "fields" : {
24+ "simple" : {"selected" : False , "guidelines" : None , "value" : True },
25+ "list" : {"selected" : False , "guidelines" : None , "items" : []},
26+ "object" : {"selected" : False , "guidelines" : None , "fields" : {}},
27+ }
28+ }
29+
2130
2231@pytest .mark .v2
2332def test_post_parameters_must_init ():
@@ -30,17 +39,41 @@ def test_post_parameters_must_init():
3039@pytest .mark .v2
3140def test_patch_parameters_must_init_from_dict ():
3241 """Should init PATCH parameters from an annotation dict."""
33- annotation = {"fields" : {"is_good" : {"value" : True }}}
42+ annotation = {
43+ "fields" : {
44+ "simple" : {"value" : True },
45+ "list" : {"items" : []},
46+ "object" : {"fields" : {}},
47+ }
48+ }
3449 parameters = RagDocumentAnnotationParameters (
3550 document_id = "invalid-document-id" , status = "Active" , annotation = annotation
3651 )
3752 req_params = parameters .get_request_parameters ()
3853 assert parameters .document_id == "invalid-document-id"
3954 assert req_params ["status" ] == "Active"
40- assert (
41- req_params ["annotation" ]
42- == '{"fields":{"is_good":{"selected":false,"value":true}}}'
55+ assert req_params ["annotation" ] == expected_annotation
56+
57+
58+ @pytest .mark .v2
59+ def test_patch_parameters_must_init_from_object ():
60+ """Should init PATCH parameters from an annotation instance."""
61+ annotation = RagAnnotation (
62+ {
63+ "fields" : {
64+ "simple" : {"value" : True },
65+ "list" : {"items" : []},
66+ "object" : {"fields" : {}},
67+ }
68+ }
4369 )
70+ parameters = RagDocumentAnnotationParameters (
71+ document_id = "invalid-document-id" , status = "Active" , annotation = annotation
72+ )
73+ req_params = parameters .get_request_parameters ()
74+ assert parameters .document_id == "invalid-document-id"
75+ assert req_params ["status" ] == "Active"
76+ assert req_params ["annotation" ] == expected_annotation
4477
4578
4679@pytest .mark .v2
@@ -49,15 +82,12 @@ def test_patch_parameters_must_init_from_string():
4982 parameters = RagDocumentAnnotationParameters (
5083 document_id = "invalid-document-id" ,
5184 status = "Active" ,
52- annotation = '{"fields": {"is_good ": {"value": true}}}' ,
85+ annotation = '{"fields": {"simple ": {"value": true},"list": {"items": []},"object": {"fields": {} }}}' ,
5386 )
5487 req_params = parameters .get_request_parameters ()
5588 assert parameters .document_id == "invalid-document-id"
5689 assert req_params ["status" ] == "Active"
57- assert (
58- req_params ["annotation" ]
59- == '{"fields":{"is_good":{"selected":false,"value":true}}}'
60- )
90+ assert req_params ["annotation" ] == expected_annotation
6191
6292
6393@pytest .mark .v2
0 commit comments