Skip to content

Commit 26f61d6

Browse files
better testing
1 parent d6b6e9b commit 26f61d6

File tree

1 file changed

+65
-47
lines changed

1 file changed

+65
-47
lines changed

tests/api_test.robot

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ ${BASE_URL} ${BASE}:${PORT}
1313

1414
*** Keywords ***
1515
Clean Up Test
16-
[Arguments] @{partition}
16+
[Arguments] @{part}
1717
${allowed_status}= Create List 204 404
18-
FOR ${part} IN @{partition}
19-
${response}= DELETE ${BASE_URL}/partition/${part} expected_status=any
18+
FOR ${partition} IN @{part}
19+
${response}= DELETE ${BASE_URL}/partition/${partition} expected_status=any
2020
${status_code}= Convert To String ${response.status_code}
2121
List Should Contain Value ${allowed_status} ${status_code}
2222
END
@@ -28,15 +28,15 @@ Get Task Status
2828
RETURN ${response.json()}
2929

3030
Get Extract
31-
[Arguments] ${extract_id} ${partition} ${expected_status}=200
31+
[Arguments] ${extract_id} ${expected_status}=200
3232
${response}= GET ${BASE_URL}/extract/${extract_id} expected_status=${expected_status}
3333
RETURN ${response.json()}
3434

3535
Index File
36-
[Arguments] ${file_path} ${file_id} ${partition} ${expected_status}=201
36+
[Arguments] ${file_path} ${id} ${part} ${expected_status}=201
3737
${file}= Get File For Streaming Upload ${file_path}
3838
${files}= Create Dictionary file ${file}
39-
${response}= POST ${BASE_URL}/indexer/partition/${partition}/file/${file_id} files=${files} expected_status=${expected_status}
39+
${response}= POST ${BASE_URL}/indexer/partition/${part}/file/${id} files=${files} expected_status=${expected_status}
4040
${response}= Set Variable ${response.json()}
4141
Should Match Regexp ${response}[task_status_url] ${BASE_URL}/indexer/task/[a-fA-F0-9]{48}
4242
${task_id}= Fetch From Right ${response}[task_status_url] /
@@ -47,53 +47,64 @@ Index File
4747
Sleep 1
4848
END
4949

50-
Get File Metadata
51-
[Arguments] ${file_id} ${partition} ${expected_status}=200
52-
${response}= GET ${BASE_URL}/partition/${partition}/file/${file_id} expected_status=${expected_status}
53-
RETURN ${response.json()}[metadata]
54-
55-
5650
Check File Exists
57-
[Arguments] ${file_id} ${partition} ${expected_status}=200
58-
${response}= GET ${BASE_URL}/partition/check-file/${partition}/file/${file_id} expected_status=${expected_status}
59-
Run Keyword If '${expected_status}' == '200' Should Be Equal As Strings ${response.json()} File '${file_id}' exists in partition '${partition}'.
60-
Run Keyword If '${expected_status}' == '404' Should Be Equal As Strings ${response.json()}[detail] File '${file_id}' not found in partition '${partition}'.
51+
[Arguments] ${id} ${part} ${expected_status}=200
52+
${response}= GET ${BASE_URL}/partition/check-file/${part}/file/${id} expected_status=${expected_status}
53+
Run Keyword If '${expected_status}' == '200' Should Be Equal As Strings ${response.json()} File '${id}' exists in partition '${part}'.
54+
Run Keyword If '${expected_status}' == '404' Should Be Equal As Strings ${response.json()}[detail] File '${id}' not found in partition '${part}'.
6155

6256
Patch File
63-
[Arguments] ${file_id} ${partition} ${metadata} ${expected_status}=200
57+
[Arguments] ${id} ${part} ${metadata} ${expected_status}=200
6458
${form_data}= Create Dictionary metadata=${metadata}
65-
${response}= PATCH ${BASE_URL}/indexer/partition/${partition}/file/${file_id} data=${form_data} expected_status=${expected_status}
66-
Run Keyword If '${expected_status}' == '200' Should Be Equal As Strings ${response.json()}[message] Metadata for file '${file_id}' successfully updated.
59+
${response}= PATCH ${BASE_URL}/indexer/partition/${part}/file/${id} data=${form_data} expected_status=${expected_status}
60+
Run Keyword If '${expected_status}' == '200' Should Be Equal As Strings ${response.json()}[message] Metadata for file '${id}' successfully updated.
6761

6862

6963
Delete File
70-
[Arguments] ${file_id} ${partition}=test ${expected_status}=204
71-
${response}= DELETE ${BASE_URL}/indexer/partition/${partition}/file/${file_id} expected_status=${expected_status}
64+
[Arguments] ${id} ${part}=test ${expected_status}=204
65+
${response}= DELETE ${BASE_URL}/indexer/partition/${part}/file/${id} expected_status=${expected_status}
7266
RETURN None
7367

7468

7569
Delete Partition
76-
[Arguments] ${partition} ${expected_status}=204
77-
${response}= DELETE ${BASE_URL}/partition/${partition} expected_status=${expected_status}
70+
[Arguments] ${part} ${expected_status}=204
71+
${response}= DELETE ${BASE_URL}/partition/${part} expected_status=${expected_status}
7872
RETURN None
7973

74+
Get File Metadata
75+
[Arguments] ${id} ${part} ${expected_status}=200 &{expected_metadata}
76+
${is_empty}= Evaluate not bool(${expected_metadata})
77+
Run Keyword If ${is_empty} Set Variable &{expected_metadata} Create Dictionary
78+
${response}= GET ${BASE_URL}/partition/${part}/file/${id} expected_status=${expected_status}
79+
${json_response}= Set Variable ${response.json()}
80+
Log to Console ${json_response}
81+
Log to Console ${json_response['metadata']}
82+
Run Keyword If '${expected_status}' == '404' Should Be Equal As Strings ${json_response}[detail] File '${id}' not found in partition '${part}'.
83+
FOR ${key} IN @{expected_metadata.keys()}
84+
Should Be Equal ${json_response['metadata']['${key}']} ${expected_metadata['${key}']}
85+
END
86+
8087
*** Test Cases ***
8188
Health Check
8289
${response}= GET ${BASE_URL}/health_check expected_status=200
8390
Should Be Equal As Strings ${response.json()} RAG API is up.
8491
[Teardown]
8592

93+
Add File and Check Metadata
94+
&{file_metadata}= Create Dictionary filename=eng.pdf partition=test file_id=0
95+
Index File ${test_file_1} 0 test
96+
${response}= Get File Metadata 0 test &{file_metadata}
97+
[Teardown] Clean Up Test test
98+
8699
Add File and Patch it with new metadata
87100
Index File ${test_file_2} 0 test
88101
${metadata}= Create Dictionary title=Test Title author=Test Author
89102
${metadata}= Evaluate json.dumps(${metadata}) json
90103
Patch File 0 test ${metadata}
91-
${response}= Get File Metadata 0 test
92-
Should Be Equal As Strings ${response}[title] Test Title
93-
Should Be Equal As Strings ${response}[author] Test Author
104+
&{file_metadata}= Create Dictionary title=Test Title author=Test Author
105+
${response}= Get File Metadata 0 test &{file_metadata}
94106
[Teardown] Clean Up Test test
95107

96-
97108
Add File and Delete it
98109
Index File ${test_file_1} 0 test
99110
Delete File 0 test
@@ -109,23 +120,30 @@ Add files to two partitions and search each partition
109120
[Teardown] Clean Up Test test test2
110121

111122

112-
113-
# Get Non Existent Task Status
114-
# ${response}= Get Task Status 82891771158d68c1eacb9d1f151391007f68c96901000000 404
115-
# Should Be Equal As Strings ${response}[detail] Task '82891771158d68c1eacb9d1f151391007f68c96901000000' not found.
116-
# Get Invalid Task Id Status (-1)
117-
# ${response}= Get Task Status -1 404
118-
# Should Be Equal As Strings ${response.json()}[detail] '-1' is not a valid task id.
119-
# Get Invalid Task Id Status (123)
120-
# ${response}= Get Task Status 123 400
121-
# Should Be Equal As Strings ${response.json()}[detail] '123' is not a valid task id.
122-
123-
# Get Non Existent Extract
124-
# ${response}= Get Task Status 82891771158d68c1eacb9d1f151391007f68c96901000000 404
125-
# Should Be Equal As Strings ${response}[detail] Task '82891771158d68c1eacb9d1f151391007f68c96901000000' not found.
126-
# Get Invalid Extract Id (-1)
127-
# ${response}= Get Task Status -1 400
128-
# Should Be Equal As Strings ${response.json()}[detail] '-1' is not a valid task id.
129-
# Get Invalid Extract Id (123)
130-
# ${response}= Get Task Status 123 400
131-
# Should Be Equal As Strings ${response.json()}[detail] '123' is not a valid task id.
123+
# Shoud Fail tests
124+
Get Non Existent Task Status
125+
${response}= Get Task Status 82891771158d68c1eacb9d1f151391007f68c96901000000 404
126+
Should Be Equal As Strings ${response}[detail] Task '82891771158d68c1eacb9d1f151391007f68c96901000000' not found.
127+
Get Invalid Task Id Status (-1)
128+
${response}= Get Task Status -1 404
129+
Should Be Equal As Strings ${response}[detail] Task '-1' not found.
130+
Get Invalid Task Id Status (123)
131+
${response}= Get Task Status 123 404
132+
Should Be Equal As Strings ${response}[detail] Task '123' not found.
133+
134+
Get Non Existent Extract
135+
${response}= Get Task Status 82891771158d68c1eacb9d1f151391007f68c96901000000 404
136+
Should Be Equal As Strings ${response}[detail] Task '82891771158d68c1eacb9d1f151391007f68c96901000000' not found.
137+
Get Invalid Extract Id (-1)
138+
${response}= Get Task Status -1 404
139+
Should Be Equal As Strings ${response}[detail] Task '-1' not found.
140+
Get Invalid Extract Id (123)
141+
${response}= Get Task Status 123 404
142+
Should Be Equal As Strings ${response}[detail] Task '123' not found.
143+
144+
Get Non Existent File
145+
Get File Metadata 0 test 404
146+
Get Invalid File Id (-1)
147+
Get File Metadata -1 test 404
148+
Get Invalid File Id (`"&é\'-!/")
149+
Get File Metadata "&é\'-!/ test 404

0 commit comments

Comments
 (0)