-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Api fixtures. * Api fixtures. * Api fixtures. * Api fixtures. --------- Co-authored-by: Nupur Khare <[email protected]>
- Loading branch information
1 parent
e0a997d
commit d378aa7
Showing
4 changed files
with
102 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1662,7 +1662,7 @@ def test_content_update_api(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.content_id_text}", | ||
json={ | ||
"cognition_id": pytest.content_id_text, | ||
"row_id": pytest.content_id_text, | ||
"data": "AWS Fargate is a serverless compute engine for containers that allows you to run " | ||
"Docker containers without having to manage the underlying EC2 instances. With Fargate, " | ||
"you can focus on developing and deploying your applications rather than managing the infrastructure.", | ||
|
@@ -1682,7 +1682,7 @@ def test_content_update_api_collection_does_not_exist(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.content_id_text}", | ||
json={ | ||
"cognition_id": pytest.content_id_text, | ||
"row_id": pytest.content_id_text, | ||
"data": "Docker containers without having to manage the underlying EC2 instances.", | ||
"collection": "test_content_update_api_collection_does_not_exist", | ||
"content_type": "text" | ||
|
@@ -1700,7 +1700,7 @@ def test_content_update_api_invalid(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.content_id_text}", | ||
json={ | ||
"cognition_id": pytest.content_id_text, | ||
"row_id": pytest.content_id_text, | ||
"data": "AWS Fargate is a serverless compute engine.", | ||
"collection": "details", | ||
"content_type": "text" | ||
|
@@ -1720,7 +1720,7 @@ def test_content_update_api_already_exist(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{content_id}", | ||
json={ | ||
"cognition_id": content_id, | ||
"row_id": content_id, | ||
"data": "AWS Fargate is a serverless compute engine for containers that allows you to run " | ||
"Docker containers without having to manage the underlying EC2 instances. With Fargate, " | ||
"you can focus on developing and deploying your applications rather than managing the infrastructure.", | ||
|
@@ -1742,7 +1742,7 @@ def test_content_update_api_id_not_found(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{content_id}", | ||
json={ | ||
"cognition_id": content_id, | ||
"row_id": content_id, | ||
"data": "Artificial intelligence (AI) involves using computers to do things that traditionally require human " | ||
"intelligence. AI can process large amounts of data in ways that humans cannot. The goal for AI is " | ||
"to be able to do things like recognize patterns, make decisions, and judge like humans.", | ||
|
@@ -1760,15 +1760,22 @@ def test_content_update_api_id_not_found(): | |
|
||
|
||
@mock.patch('kairon.shared.cognition.processor.CognitionDataProcessor.list_cognition_data', autospec=True) | ||
def test_list_cognition_data(mock_list_cognition_data): | ||
def _list_cognition_data(*args, **kwargs): | ||
return [{'vector_id': 1, | ||
'_id': '65266ff16f0190ca4fd09898', | ||
@mock.patch('kairon.shared.cognition.processor.CognitionDataProcessor.get_cognition_data', autospec=True) | ||
def test_list_cognition_data(mock_get_cognition_data, mock_list_cognition_data): | ||
cognition_data = [{'vector_id': 1, | ||
'row_id': '65266ff16f0190ca4fd09898', | ||
'data': 'AWS Fargate is a serverless compute engine for containers that allows you to run Docker containers without having to manage the underlying EC2 instances. With Fargate, you can focus on developing and deploying your applications rather than managing the infrastructure.', | ||
'content_type': 'text', | ||
'collection': 'aws', 'user': '"[email protected]"', 'bot': pytest.bot,}] | ||
|
||
'collection': 'aws', 'user': '"[email protected]"', 'bot': pytest.bot}] | ||
row_count = 1 | ||
def _list_cognition_data(*args, **kwargs): | ||
return cognition_data | ||
mock_list_cognition_data.return_value = _list_cognition_data() | ||
|
||
def _get_cognition_data(*args, **kwargs): | ||
return cognition_data, row_count | ||
mock_get_cognition_data.return_value = _get_cognition_data() | ||
|
||
filter_query = 'without having to manage' | ||
response = client.get( | ||
url=f"/api/bot/{pytest.bot}/data/cognition?data={filter_query}", | ||
|
@@ -1778,8 +1785,8 @@ def _list_cognition_data(*args, **kwargs): | |
print(actual) | ||
assert actual["success"] | ||
assert actual["error_code"] == 0 | ||
assert actual["data"] | ||
assert actual["data"][0]['collection'] | ||
assert actual["data"]['data'][0]['collection'] == 'aws' | ||
assert actual["data"]['row_count'] == 1 | ||
|
||
|
||
def test_get_content_without_data(): | ||
|
@@ -1791,17 +1798,16 @@ def test_get_content_without_data(): | |
print(actual) | ||
assert actual["success"] | ||
assert actual["error_code"] == 0 | ||
assert actual["data"] | ||
assert actual["data"][0]['collection'] == 'details' | ||
assert actual["data"][0]['data'] == 'AWS Fargate is a serverless compute engine for containers that allows you to run Docker containers without having to manage the underlying EC2 instances. With Fargate, you can focus on developing and deploying your applications rather than managing the infrastructure.' | ||
assert actual["data"][1]['data'] == 'Blockchain technology is an advanced database mechanism that allows transparent information sharing within a business network.' | ||
assert actual["data"]['data'][0]['collection'] == None | ||
assert actual["data"]['data'][0]['data'] == 'Blockchain technology is an advanced database mechanism that allows transparent information sharing within a business network.' | ||
assert actual["data"]['row_count'] == 1 | ||
|
||
|
||
def test_delete_content(): | ||
response_one = client.delete( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.content_id_no_collection}", | ||
json={ | ||
"cognition_id": pytest.content_id_no_collection, | ||
"row_id": pytest.content_id_no_collection, | ||
}, | ||
headers={"Authorization": pytest.token_type + " " + pytest.access_token} | ||
) | ||
|
@@ -1814,7 +1820,7 @@ def test_delete_content(): | |
response = client.delete( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.content_id_text}", | ||
json={ | ||
"cognition_id": pytest.content_id_text, | ||
"row_id": pytest.content_id_text, | ||
}, | ||
headers={"Authorization": pytest.token_type + " " + pytest.access_token} | ||
) | ||
|
@@ -1830,7 +1836,7 @@ def test_delete_content_does_not_exist(): | |
response = client.delete( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{content_id}", | ||
json={ | ||
"cognition_id": content_id, | ||
"row_id": content_id, | ||
}, | ||
headers={"Authorization": pytest.token_type + " " + pytest.access_token} | ||
) | ||
|
@@ -1851,7 +1857,8 @@ def test_get_content_not_exists(): | |
assert actual["success"] | ||
assert actual["message"] is None | ||
assert actual["error_code"] == 0 | ||
assert actual["data"] == [] | ||
assert actual["data"]['data'] == [] | ||
assert actual["data"]['row_count'] == 0 | ||
|
||
|
||
def test_payload_upload_api_with_gpt_feature_disabled(): | ||
|
@@ -1973,7 +1980,7 @@ def test_payload_updated_api_collection_does_not_exists(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.payload_id}", | ||
json={ | ||
"cognition_id": pytest.payload_id, | ||
"row_id": pytest.payload_id, | ||
"data": {"details": "data science"}, | ||
"collection": "test_payload_updated_api_collection_does_not_exists", | ||
"content_type": "json" | ||
|
@@ -2010,7 +2017,7 @@ def test_payload_updated_api(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.payload_id}", | ||
json={ | ||
"cognition_id": pytest.payload_id, | ||
"row_id": pytest.payload_id, | ||
"data": {"details": "data science"}, | ||
"collection": "Details", | ||
"content_type": "json" | ||
|
@@ -2033,7 +2040,7 @@ def _mock_get_bot_settings(*args, **kwargs): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{payload_id}", | ||
json={ | ||
"cognition_id": payload_id, | ||
"row_id": payload_id, | ||
"data": {"details": "data science"}, | ||
"content_type": "json", | ||
}, | ||
|
@@ -2053,7 +2060,7 @@ def test_payload_content_update_api_id_not_found(): | |
response = client.put( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{payload_id}", | ||
json={ | ||
"cognition_id": payload_id, | ||
"row_id": payload_id, | ||
"data": {"details": "data"}, | ||
"content_type": "json", | ||
}, | ||
|
@@ -2070,23 +2077,23 @@ def test_payload_content_update_api_id_not_found(): | |
|
||
def test_get_payload_content(): | ||
response = client.get( | ||
url=f"/api/bot/{pytest.bot}/data/cognition", | ||
url=f"/api/bot/{pytest.bot}/data/cognition?collection=Details", | ||
headers={"Authorization": pytest.token_type + " " + pytest.access_token} | ||
) | ||
actual = response.json() | ||
print(actual) | ||
assert actual["success"] | ||
assert actual["error_code"] == 0 | ||
assert actual["data"][0]['data'] == {'details': 'data science'} | ||
|
||
assert actual["data"][0]['collection'] == 'Details' | ||
assert actual["data"]['data'][0]['data'] == {'details': 'data science'} | ||
assert actual["data"]['data'][0]['collection'] == 'Details' | ||
assert actual["data"]['row_count'] == 1 | ||
|
||
|
||
def test_delete_payload_content(): | ||
response = client.delete( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{pytest.payload_id}", | ||
json={ | ||
"cognition_id": pytest.payload_id, | ||
"row_id": pytest.payload_id, | ||
}, | ||
headers={"Authorization": pytest.token_type + " " + pytest.access_token} | ||
) | ||
|
@@ -2103,7 +2110,7 @@ def test_delete_payload_content_does_not_exist(): | |
response = client.delete( | ||
url=f"/api/bot/{pytest.bot}/data/cognition/{payload_id}", | ||
json={ | ||
"cognition_id": payload_id, | ||
"row_id": payload_id, | ||
}, | ||
headers={"Authorization": pytest.token_type + " " + pytest.access_token} | ||
) | ||
|
@@ -2123,7 +2130,8 @@ def test_get_payload_content_not_exists(): | |
assert actual["success"] | ||
assert actual["message"] is None | ||
assert actual["error_code"] == 0 | ||
assert actual["data"] == [] | ||
assert actual["data"]['data'] == [] | ||
assert actual["data"]['row_count'] == 0 | ||
|
||
|
||
def test_get_kairon_faq_action_with_no_actions(): | ||
|
Oops, something went wrong.