Skip to content

Commit ba1ac5e

Browse files
committed
updated robot api tests
1 parent da771a8 commit ba1ac5e

File tree

10 files changed

+552
-110
lines changed

10 files changed

+552
-110
lines changed

tests/api/extracts.robot

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/api/indexer.robot

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,86 @@ Resource keywords.robot
33

44
*** Test Cases ***
55
Add File and Delete it
6-
Index File ${CURDIR}/${test_file_1} 0 test
6+
Index File ${CURDIR}/${test_file_pdf} 0 test
77
Delete File 0 test
88
[Teardown] Clean Up Test test
99

1010
Get Non Existent Task Status
11-
${response}= Get Task Status 82891771158d68c1eacb9d1f151391007f68c96901000000 404
11+
${response}= Get Task Status 82891771158d68c1eacb9d1f151391007f68c96901000000 ${HEADERS} 404
1212
Should Be Equal As Strings
1313
... ${response}[detail]
14-
... Task '82891771158d68c1eacb9d1f151391007f68c96901000000' not found.
15-
16-
Get Invalid Task Id Status (-1)
17-
${response}= Get Task Status -1 404
18-
Should Be Equal As Strings ${response}[detail] Task '-1' not found.
19-
20-
Get Invalid Task Id Status (123)
21-
${response}= Get Task Status 123 404
22-
Should Be Equal As Strings ${response}[detail] Task '123' not found.
14+
... Task '82891771158d68c1eacb9d1f151391007f68c96901000000' not found
2315

2416
Add File and Check Metadata
25-
&{file_metadata}= Create Dictionary filename=${test_file_1} partition=test file_id=0
26-
Index File ${CURDIR}/${test_file_1} 0 test
17+
&{file_metadata}= Create Dictionary filename=${test_file_pdf} partition=test file_id=0
18+
Index File ${CURDIR}/${test_file_txt} 0 test
2719
${response}= Get File Metadata 0 test &{file_metadata}
2820
[Teardown] Clean Up Test test
2921

3022
Add File and Patch it with new metadata
31-
Index File ${CURDIR}/${test_file_2} 0 test
23+
Index File ${CURDIR}/${test_file_txt} 0 test
3224
${metadata}= Create Dictionary title=Test Title author=Test Author
3325
${metadata}= Evaluate json.dumps(${metadata}) json
3426
Patch File 0 test ${metadata}
3527
&{file_metadata}= Create Dictionary title=Test Title author=Test Author
3628
${response}= Get File Metadata 0 test &{file_metadata}
37-
[Teardown] Clean Up Test test
3829

39-
Get Non Existent File
40-
Get File Metadata id=0 part=test expected_status=404
30+
Move File to New Partition
31+
[Documentation] Move a file from one partition to another and verify it no longer exists in the source partition.
32+
# --- Step 1: Move file to destination partition
33+
${metadata}= Create Dictionary partition=test1
34+
${metadata_json}= Evaluate json.dumps(${metadata}) json
35+
${form_data}= Create Dictionary metadata=${metadata_json}
36+
${response}= PATCH
37+
... ${BASE_URL}/indexer/partition/test/file/0
38+
... headers=${HEADERS}
39+
... data=${form_data}
40+
... expected_status=200
41+
${json}= Set Variable ${response.json()}
42+
Dictionary Should Contain Key ${json} message
4143

42-
Get Invalid File Id (-1)
43-
Get File Metadata id=-1 part=test expected_status=404
44+
# --- Step 2: Check that the file exists in destination partition
45+
${response}= GET
46+
... ${BASE_URL}/partition/test1/file/0
47+
... headers=${HEADERS}
48+
... expected_status=200
49+
# --- Step 3: Verify that file no longer exists in the original partition
50+
${response}= GET
51+
... ${BASE_URL}/partition/test/file/0
52+
... headers=${HEADERS}
53+
... expected_status=404
54+
${json}= Set Variable ${response.json()}
55+
Should Contain ${json}[detail] does not exist
4456

45-
Get Invalid File Id (`"&é\'-!")
57+
58+
Get Invalid File Id (`"&é\'-!")
4659
Get File Metadata id="&é\'-! part=test expected_status=404
4760

48-
Test Indexer Overload
49-
${task_ids}= Create List
50-
FOR ${i} IN RANGE 0 100
51-
${response}= Index File Non Blocking ${CURDIR}/${test_file_1} ${i} test
52-
${task_url}= Set Variable ${response}[task_status_url]
53-
${task_id}= Fetch From Right ${task_url} /
54-
Append To List ${task_ids} ${task_id}
55-
END
56-
Sleep 1
57-
FOR ${i} IN RANGE 0 1200
58-
FOR ${task_id} IN @{task_ids}
59-
${response}= Get Task Status ${task_id}
60-
${task_state}= Set Variable ${response}[task_state]
61-
IF '${task_state}' == 'FAILED'
62-
Fail Task '${task_id}' failed.
63-
ELSE IF '${task_state}' == 'COMPLETED'
64-
Remove Values From List ${task_ids} ${task_id}
65-
END
66-
END
67-
Sleep 1
68-
${list_length}= Get Length ${task_ids}
69-
IF ${list_length} > 0
70-
Log ${task_ids}
71-
END
72-
# Exit early if all tasks completed
73-
${list_length}= Get Length ${task_ids}
74-
IF ${list_length} == 0
75-
BREAK
76-
END
77-
END
78-
IF ${list_length} > 0
79-
Log Some tasks are still running after 1200 seconds: ${task_ids}
80-
Fail Some tasks are still running after 1200 seconds.
81-
END
82-
[Teardown] Clean Up Test test
61+
62+
Copy File to Another Partition
63+
[Documentation] Index a file into one partition, copy it to another, and verify it exists in the destination.
64+
65+
# --- Step 1: Copy file to destination partition
66+
${form_data}= Create Dictionary source_partition=test1 source_file_id=0
67+
${response}= POST
68+
... ${BASE_URL}/indexer/partition/test/file/1/copy
69+
... headers=${HEADERS}
70+
... data=${form_data}
71+
... expected_status=201
72+
73+
# --- Step 2: Check that the file exists in destination partition
74+
${response}= GET
75+
... ${BASE_URL}/partition/test/file/1
76+
... headers=${HEADERS}
77+
... expected_status=200
78+
# --- Step 3: Verify that file still exists in the original partition
79+
${response}= GET
80+
... ${BASE_URL}/partition/test1/file/0
81+
... headers=${HEADERS}
82+
... expected_status=200
83+
${json}= Set Variable ${response.json()}
84+
85+
Cleanup
86+
${response}= DELETE ${BASE_URL}/partition/test headers=${HEADERS} expected_status=204
87+
${response}= DELETE ${BASE_URL}/partition/test1 headers=${HEADERS} expected_status=204
88+

tests/api/keywords.robot

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@ Library Collections
44
Library RequestsLibrary
55

66
*** Variables ***
7-
${BASE}
8-
${PORT}
9-
${test_file_1} test_file_1.pdf
10-
${test_file_2} test_file_2.pdf
7+
${BASE}
8+
${PORT}
9+
${test_file_pdf} ../resources/test_file.pdf
10+
${test_file_txt} ../resources/test_file.txt
1111
${test_part_1} test
1212
${test_part_2} test2
1313
${BASE_URL} ${BASE}:${PORT}
14+
${AUTH_TOKEN} none
15+
&{HEADERS} Authorization=Bearer ${AUTH_TOKEN}
1416

1517
*** Keywords ***
1618
Clean Up Test
1719
[Arguments] @{part}
1820
${allowed_status}= Create List 204 404
1921
FOR ${partition} IN @{part}
20-
${response}= DELETE ${BASE_URL}/partition/${partition} expected_status=any
22+
${response}= DELETE ${BASE_URL}/partition/${partition} headers=${HEADERS} expected_status=any
2123
${status_code}= Convert To String ${response.status_code}
2224
List Should Contain Value ${allowed_status} ${status_code}
2325
END
2426

2527
Get Task Status
26-
[Arguments] ${task_id} ${expected_status}=200
27-
${response}= GET ${BASE_URL}/indexer/task/${task_id} expected_status=${expected_status}
28+
[Arguments] ${task_id} ${headers}=${HEADERS} ${expected_status}=200
29+
${response}= GET ${BASE_URL}/indexer/task/${task_id} headers=${headers} expected_status=${expected_status}
2830
RETURN ${response.json()}
2931

3032
Get Extract
31-
[Arguments] ${extract_id} ${expected_status}=200
32-
${response}= GET ${BASE_URL}/extract/${extract_id} expected_status=${expected_status}
33+
[Arguments] ${extract_id} ${headers}=${HEADERS} ${expected_status}=200
34+
${response}= GET ${BASE_URL}/extract/${extract_id} headers=${headers} expected_status=${expected_status}
3335
RETURN ${response.json()}
3436

3537
Index File Non Blocking
@@ -39,42 +41,53 @@ Index File Non Blocking
3941
${response}= POST
4042
... ${BASE_URL}/indexer/partition/${part}/file/${id}
4143
... files=${files}
44+
... headers=${HEADERS}
4245
... expected_status=${expected_status}
4346
${response}= Set Variable ${response.json()}
4447
Should Match Regexp ${response}[task_status_url] ${BASE_URL}/indexer/task/[a-fA-F0-9]{48}
4548
RETURN ${response}
4649

4750
Index File
48-
[Arguments] ${file_path} ${id} ${part} ${expected_status}=201
51+
[Arguments] ${file_path} ${id} ${part} ${headers}=${HEADERS} ${expected_status}=201
4952
${file}= Get File For Streaming Upload ${file_path}
5053
${files}= Create Dictionary file ${file}
5154
${response}= POST
5255
... ${BASE_URL}/indexer/partition/${part}/file/${id}
5356
... files=${files}
57+
... headers=${headers}
5458
... expected_status=${expected_status}
5559
${response}= Set Variable ${response.json()}
5660
Should Match Regexp ${response}[task_status_url] ${BASE_URL}/indexer/task/[a-fA-F0-9]{48}
5761
${task_id}= Fetch From Right ${response}[task_status_url] /
5862
Sleep 1
59-
FOR ${i} IN RANGE 0 60 # 60 seconds
60-
${response}= Get Task Status ${task_id}
63+
FOR ${i} IN RANGE 0 120
64+
${response}= Get Task Status ${task_id} headers=${headers}
6165
IF '${response}[task_state]' == 'COMPLETED' BREAK
6266
Sleep 1
63-
IF ${i} == 59
64-
Log Task '${task_id}' is still running after 60 seconds.
67+
IF ${i} == 119
68+
Log Task '${task_id}' is still running after 120 seconds.
6569
Log ${response}
66-
Fail Task '${task_id}' is still running after 60 seconds.
70+
Fail Task '${task_id}' is still running after 120 seconds.
6771
END
6872
END
6973

7074
Check File Exists
7175
[Arguments] ${id} ${part} ${expected_status}=200
72-
${response}= GET ${BASE_URL}/partition/check-file/${part}/file/${id} expected_status=${expected_status}
76+
${response}= GET ${BASE_URL}/${part}/file/${id} headers=${HEADERS} expected_status=${expected_status}
77+
${json}= Set Variable ${response.json()}
78+
7379
IF '${expected_status}' == '200'
74-
Should Be Equal As Strings ${response.json()} File '${id}' exists in partition '${part}'.
80+
Dictionary Should Contain Key ${json} metadata
81+
Dictionary Should Contain Key ${json} documents
82+
${documents}= Get From Dictionary ${json} documents
83+
Should Be True ${documents} != []
84+
FOR ${doc} IN @{documents}
85+
Dictionary Should Contain Key ${doc} link
86+
END
7587
END
88+
7689
IF '${expected_status}' == '404'
77-
Should Be Equal As Strings ${response.json()}[detail] [VDB_FILE_NOT_FOUND]: File ID '${id}' does not exist in partition '${part}'
90+
Should Be Equal As Strings ${json}[detail] [VDB_FILE_NOT_FOUND]: File ID '${id}' does not exist in partition '${part}'
7891
END
7992

8093
Patch File
@@ -83,26 +96,27 @@ Patch File
8396
${response}= PATCH
8497
... ${BASE_URL}/indexer/partition/${part}/file/${id}
8598
... data=${form_data}
99+
... headers=${HEADERS}
86100
... expected_status=${expected_status}
87101
IF '${expected_status}' == '200'
88102
Should Be Equal As Strings ${response.json()}[message] Metadata for file '${id}' successfully updated.
89103
END
90104

91105
Delete File
92106
[Arguments] ${id} ${part}=${test_part_1} ${expected_status}=204
93-
${response}= DELETE ${BASE_URL}/indexer/partition/${part}/file/${id} expected_status=${expected_status}
107+
${response}= DELETE ${BASE_URL}/indexer/partition/${part}/file/${id} headers=${HEADERS} expected_status=${expected_status}
94108
RETURN None
95109

96110
Delete Partition
97111
[Arguments] ${part} ${expected_status}=204
98-
${response}= DELETE ${BASE_URL}/partition/${part} expected_status=${expected_status}
112+
${response}= DELETE ${BASE_URL}/partition/${part} headers=${HEADERS} expected_status=${expected_status}
99113
RETURN None
100114

101115
Get File Metadata
102116
[Arguments] ${id} ${part} &{expected_metadata_and_status}
103117
${expected_status}= Get From Dictionary ${expected_metadata_and_status} expected_status 200
104118
${expected_metadata}= Remove From Dictionary ${expected_metadata_and_status} expected_status
105-
${response}= GET ${BASE_URL}/partition/${part}/file/${id} expected_status=${expected_status}
119+
${response}= GET ${BASE_URL}/partition/${part}/file/${id} headers=${HEADERS} expected_status=${expected_status}
106120
${json_response}= Set Variable ${response.json()}
107121
IF '${expected_status}' == '404'
108122
Should Be Equal As Strings ${json_response}[detail] [VDB_FILE_NOT_FOUND]: File ID '${id}' does not exist in partition '${part}'
@@ -116,5 +130,20 @@ Get File Metadata
116130
END
117131

118132
Get Models
119-
${response}= GET ${BASE_URL}/v1/models
120-
Log To Console ${response}
133+
[Arguments] ${headers}=${HEADERS}
134+
${response}= GET ${BASE_URL}/v1/models headers=${headers}
135+
Log To Console ${response}
136+
137+
Create User
138+
[Arguments] ${display_name} ${external_user_id} ${is_admin}=false ${expected_status}=201
139+
${form_data}= Create Dictionary
140+
... display_name=${display_name}
141+
... external_user_id=${external_user_id}
142+
... is_admin=${is_admin}
143+
${response}= POST
144+
... ${BASE_URL}/users
145+
... headers=${HEADERS}
146+
... data=${form_data}
147+
... expected_status=${expected_status}
148+
RETURN ${response.json()}
149+

tests/api/main.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Resource keywords.robot
33

44
*** Test Cases ***
55
Health Check
6-
${response}= GET ${BASE_URL}/health_check expected_status=any
6+
${response}= GET ${BASE_URL}/health_check headers=${HEADERS} expected_status=any
77
IF '${response.status_code}' != '200'
88
Fatal Error Health check failed with status code: ${response.status_code}. Canceling all tests.
99
END

0 commit comments

Comments
 (0)