diff --git a/kairon/shared/cognition/processor.py b/kairon/shared/cognition/processor.py index 70a0029c0..88443e28b 100644 --- a/kairon/shared/cognition/processor.py +++ b/kairon/shared/cognition/processor.py @@ -383,18 +383,24 @@ def validate_column_values(data: Any, schema: Dict): if schema and isinstance(data, dict): data_type = schema['data_type'] column_name = schema['column_name'] - if column_name in data and data[column_name] and data_type == CognitionMetadataType.int.value: - try: - return int(data[column_name]) - except ValueError: - raise AppException("Invalid data type!") - elif column_name in data and data[column_name] and data_type == CognitionMetadataType.float.value: - try: - return float(data[column_name]) - except ValueError: - raise AppException("Invalid data type!") + if column_name in data and data[column_name] is not None: + value = data[column_name] + + if data_type == CognitionMetadataType.int.value and not isinstance(value, int): + raise AppException( + f"Invalid data type for '{column_name}': Expected integer value") + + if data_type == CognitionMetadataType.float.value and not isinstance(value, float): + raise AppException( + f"Invalid data type for '{column_name}': Expected float value") + + if data_type == CognitionMetadataType.str.value and not isinstance(value, str): + raise AppException( + f"Invalid data type for '{column_name}': Expected string value") + + return value else: - return data[column_name] + raise AppException(f"Column '{column_name}' does not exist or has no value.") @staticmethod def find_matching_metadata(bot: Text, data: Any, collection: Text = None): @@ -484,7 +490,7 @@ def validate_data(self, primary_key_col: str, collection_name: str, event_type: }) if "document_non_existence" in event_validations: - if str(row_key) not in existing_document_map: + if row_key not in existing_document_map: row_errors.append({ "status": "Document does not exist", "primary_key": row_key, @@ -550,7 +556,6 @@ async def upsert_data(self, primary_key_col: str, collection_name: str, event_ty } for row in data: - row = {str(key): str(value) for key, value in row.items()} primary_key_value = row.get(primary_key_col) existing_document = existing_document_map.get(primary_key_value) diff --git a/kairon/shared/data/processor.py b/kairon/shared/data/processor.py index 74ead0d52..1b21875e2 100644 --- a/kairon/shared/data/processor.py +++ b/kairon/shared/data/processor.py @@ -8717,10 +8717,26 @@ def save_doc_content(self, bot: Text, user: Text, doc_content, table_name: Text, from ..cognition.processor import CognitionDataProcessor cognition_processor = CognitionDataProcessor() + schema = CognitionSchema.objects(bot=bot, collection_name=table_name).first() + + metadata_map = {meta['column_name']: meta['data_type'] for meta in schema.metadata} + if overwrite: cognition_processor.delete_all_cognition_data_by_collection(table_name.lower(), bot) for row in reversed(doc_content): + for column, value in row.items(): + if column in metadata_map: + data_type = metadata_map[column] + try: + if data_type == 'int': + row[column] = int(value) if value else None + elif data_type == 'float': + row[column] = float(value) if value else None + except (ValueError, TypeError): + raise ValueError( + f"Error converting column '{column}' with value '{value}' to type '{data_type}'") + payload = { 'collection': table_name, 'content_type': CognitionDataType.json.value, diff --git a/tests/integration_test/services_test.py b/tests/integration_test/services_test.py index f9be29a12..733ca91f2 100644 --- a/tests/integration_test/services_test.py +++ b/tests/integration_test/services_test.py @@ -1452,10 +1452,10 @@ def test_knowledge_vault_sync_push_menu(mock_embedding, mock_collection_exists, assert schema_response["error_code"] == 0 dummy_data = { - "id": "1", + "id": 1, "item": "Juice", - "price": "2.00", - "quantity": "9" + "price": 2.00, + "quantity": 9 } dummy_doc = CognitionData( data=dummy_data, @@ -1471,8 +1471,8 @@ def test_knowledge_vault_sync_push_menu(mock_embedding, mock_collection_exists, assert cognition_data.count() == 1 sync_data = [ - {"id": 1, "item": "Juice", "price": "2.50", "quantity": "10"}, - {"id": 2, "item": "Apples", "price": "1.20", "quantity": "20"} + {"id": 1, "item": "Juice", "price": 2.50, "quantity": 10}, + {"id": 2, "item": "Apples", "price": 1.20, "quantity": 20} ] response = client.post( @@ -1490,8 +1490,8 @@ def test_knowledge_vault_sync_push_menu(mock_embedding, mock_collection_exists, assert cognition_data.count() == 2 expected_data = [ - {"id": "1", "item": "Juice", "price": "2.50", "quantity": "10"}, - {"id": "2", "item": "Apples", "price": "1.20", "quantity": "20"} + {"id": 1, "item": "Juice", "price": 2.50, "quantity": 10}, + {"id": 2, "item": "Apples", "price": 1.20, "quantity": 20} ] for index, doc in enumerate(cognition_data): @@ -1575,10 +1575,10 @@ def test_knowledge_vault_sync_field_update(mock_embedding, mock_collection_exist assert schema_response["error_code"] == 0 dummy_data_one = { - "id": "1", + "id": 1, "item": "Juice", - "price": "2.80", - "quantity": "56" + "price": 2.80, + "quantity": 56 } dummy_doc = CognitionData( data=dummy_data_one, @@ -1590,10 +1590,10 @@ def test_knowledge_vault_sync_field_update(mock_embedding, mock_collection_exist ) dummy_doc.save() dummy_data_two = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "12" + "price": 2.80, + "quantity": 12 } dummy_doc = CognitionData( data=dummy_data_two, @@ -1609,8 +1609,8 @@ def test_knowledge_vault_sync_field_update(mock_embedding, mock_collection_exist assert cognition_data.count() == 2 sync_data = [ - {"id": 1, "price": "80.50"}, - {"id": 2, "price": "27.00"} + {"id": 1, "price": 80.50}, + {"id": 2, "price": 27.00} ] response = client.post( @@ -1628,8 +1628,8 @@ def test_knowledge_vault_sync_field_update(mock_embedding, mock_collection_exist assert cognition_data.count() == 2 expected_data = [ - {"id": "1", "item": "Juice", "price": "80.50", "quantity": "56"}, - {"id": "2", "item": "Milk", "price": "27.00", "quantity": "12"} + {"id": 1, "item": "Juice", "price": 80.50, "quantity": 56}, + {"id": 2, "item": "Milk", "price": 27.00, "quantity": 12} ] for index, doc in enumerate(cognition_data): @@ -1871,7 +1871,6 @@ def test_knowledge_vault_sync_column_length_mismatch(mock_embedding): json=sync_data, headers={"Authorization": pytest.token_type + " " + pytest.access_token} ) - actual = response.json() assert not actual["success"] assert actual["message"] == "Validation failed" @@ -1928,10 +1927,10 @@ def test_knowledge_vault_sync_invalid_columns(mock_embedding): assert schema_response.json()["error_code"] == 0 dummy_data = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "12" + "price": 2.80, + "quantity": 12 } dummy_doc = CognitionData( data=dummy_data, @@ -1962,7 +1961,7 @@ def test_knowledge_vault_sync_invalid_columns(mock_embedding): cognition_data = CognitionData.objects(bot=pytest.bot, collection="groceries") assert cognition_data.count() == 1 expected_data = [ - {"id": "2", "item": "Milk", "price": "2.80", "quantity": "12"} + {"id": 2, "item": "Milk", "price": 2.80, "quantity": 12} ] for index, doc in enumerate(cognition_data): doc_data = doc.to_mongo().to_dict()["data"] @@ -1972,7 +1971,6 @@ def test_knowledge_vault_sync_invalid_columns(mock_embedding): CognitionData.objects(bot=pytest.bot, collection="groceries").delete() LLMSecret.objects.delete() - @pytest.mark.asyncio @responses.activate @mock.patch.object(litellm, "aembedding", autospec=True) @@ -2017,10 +2015,10 @@ def test_knowledge_vault_sync_document_non_existence(mock_embedding): assert schema_response.json()["error_code"] == 0 dummy_data = { - "id": "1", + "id": 1, "item": "Juice", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } dummy_doc = CognitionData( data=dummy_data, @@ -2033,7 +2031,7 @@ def test_knowledge_vault_sync_document_non_existence(mock_embedding): dummy_doc.save() sync_data = [ - {"id": "2", "price": 27.0} + {"id": 2, "price": 27.0} ] response = client.post( @@ -2046,16 +2044,16 @@ def test_knowledge_vault_sync_document_non_existence(mock_embedding): assert not actual["success"] assert actual["message"] == "Validation failed" assert actual["error_code"] == 400 - assert actual["data"] == {'2': [{'status': 'Document does not exist', 'primary_key': '2', 'message': "No document found for 'id': 2"}]} + assert actual["data"] == {'2': [{'status': 'Document does not exist', 'primary_key': 2, 'message': "No document found for 'id': 2"}]} cognition_data = CognitionData.objects(bot=pytest.bot, collection="groceries") assert cognition_data.count() == 1 expected_data = [ { - "id": "1", + "id": 1, "item": "Juice", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } ] @@ -2165,10 +2163,10 @@ def test_upload_doc_content(): last_row = cognition_data.order_by('-_id').first() assert last_row["data"] == { - 'order_id': '67', + 'order_id': 67, 'order_priority': 'Low', - 'sales': '12.34', - 'profit': '54.98' + 'sales': 12.34, + 'profit': 54.98 } CognitionData.objects(bot=pytest.bot, collection="test_doc_content_upload").delete() @@ -2271,10 +2269,10 @@ def test_upload_doc_content_append(): } last_row = cognition_data.order_by('-_id').first() assert last_row["data"] == { - 'order_id': '67', - 'order_priority': 'Low', - 'sales': '12.34', - 'profit': '54.98' + 'order_id': 67, + 'order_priority': "Low", + 'sales': 12.34, + 'profit': 54.98 } CognitionData.objects(bot=pytest.bot, collection="test_doc_content_upload_append").delete() @@ -2493,18 +2491,18 @@ def test_upload_doc_content_datatype_validation_failure(): third_last_row = cognition_data[-3] assert third_last_row["data"] == { - "order_id": "33", + "order_id": 33, "order_priority": "Low", - "sales": "905.94", - "profit": "-4.19" + "sales": 905.94, + "profit": -4.19 } fourth_last_row = cognition_data[-4] assert fourth_last_row["data"] == { - "order_id": "657", + "order_id": 657, "order_priority": "Not Specified", - "sales": "237.28", - "profit": "-2088.68" + "sales": 237.28, + "profit": -2088.68 } CognitionData.objects(bot=pytest.bot, collection="test_doc_content_upload_datatype_validation_failure").delete() @@ -6493,7 +6491,7 @@ def _mock_get_bot_settings(*args, **kwargs): ) actual = response.json() assert not actual["success"] - assert actual["message"] == 'Invalid data type!' + assert actual["message"] == "Invalid data type for 'age': Expected integer value" def test_payload_updated_api_collection_does_not_exists(): diff --git a/tests/unit_test/data_processor/data_processor2_test.py b/tests/unit_test/data_processor/data_processor2_test.py index 3688bbb35..5abb2781a 100644 --- a/tests/unit_test/data_processor/data_processor2_test.py +++ b/tests/unit_test/data_processor/data_processor2_test.py @@ -1,4 +1,9 @@ import os + +import pytest + +from kairon.exceptions import AppException +from kairon.shared.cognition.processor import CognitionDataProcessor from kairon.shared.utils import Utility os.environ["system_file"] = "./tests/testing_data/system.yaml" Utility.load_environment() @@ -47,3 +52,87 @@ def test_non_list_non_string_values(): expected_output = [{'age': 22, 'height': 5.7, 'name': 'Tom'}] result = MongoProcessor.data_format_correction_cognition_data(data_entries, metadata) assert result == expected_output, f"Expected {expected_output}, but got {result}" + +def test_validate_metadata_and_payload_valid(): + schema = { + "column_name": "item", + "data_type": "str", + "enable_search": True, + "create_embeddings": True + } + data = { + "id": 1, + "item": "Cover", + "price": 0.4, + "quantity": 20 + } + + CognitionDataProcessor.validate_column_values(data, schema) + +def test_validate_metadata_and_payload_invalid_str(): + schema = { + "column_name": "item", + "data_type": "str", + "enable_search": True, + "create_embeddings": True + } + data = { + "id": 1, + "item": 123, + "price": 0.4, + "quantity": 20 + } + + with pytest.raises(AppException, match="Invalid data type for 'item': Expected string value"): + CognitionDataProcessor.validate_column_values(data, schema) + + +def test_validate_metadata_and_payload_invalid_int(): + schema = { + "column_name": "id", + "data_type": "int", + "enable_search": True, + "create_embeddings": True + } + data = { + "id": "one", + "item": "Cover", + "price": 0.4, + "quantity": 20 + } + + with pytest.raises(AppException, match="Invalid data type for 'id': Expected integer value"): + CognitionDataProcessor.validate_column_values(data, schema) + +def test_validate_metadata_and_payload_invalid_float(): + schema = { + "column_name": "price", + "data_type": "float", + "enable_search": True, + "create_embeddings": True + } + data = { + "id": 1, + "item": "Cover", + "price": "cheap", # Invalid: should be a float + "quantity": 20 + } + + with pytest.raises(AppException, match="Invalid data type for 'price': Expected float value"): + CognitionDataProcessor.validate_column_values(data, schema) + +def test_validate_metadata_and_payload_missing_column(): + schema = { + "column_name": "quantity", + "data_type": "int", + "enable_search": True, + "create_embeddings": True + } + data = { + "id": 1, + "item": "Cover", + "price": 0.4 + } + + with pytest.raises(AppException, match="Column 'quantity' does not exist or has no value."): + CognitionDataProcessor.validate_column_values(data, schema) diff --git a/tests/unit_test/data_processor/data_processor_test.py b/tests/unit_test/data_processor/data_processor_test.py index 22c2846ec..7b89f90aa 100644 --- a/tests/unit_test/data_processor/data_processor_test.py +++ b/tests/unit_test/data_processor/data_processor_test.py @@ -1472,11 +1472,12 @@ def test_validate_data_field_update_success(self): cognition_schema.save() dummy_data_one = { - "id": "1", + "id": 1, "item": "Juice", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } + existing_document = CognitionData( data=dummy_data_one, content_type="json", @@ -1488,10 +1489,10 @@ def test_validate_data_field_update_success(self): existing_document.save() dummy_data_two = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "50" + "price": 2.80, + "quantity": 50 } existing_document = CognitionData( data=dummy_data_two, @@ -1622,7 +1623,7 @@ def test_validate_data_column_length_mismatch(self): cognition_schema.save() data = [ - {"id": "1", "item": "Milk", "quantity": 10} + {"id": 1, "item": "Milk", "quantity": 10} ] processor = CognitionDataProcessor() @@ -1633,10 +1634,10 @@ def test_validate_data_column_length_mismatch(self): data=data, bot=bot ) - assert "1" in validation_summary - assert validation_summary["1"][0]["status"] == "Column length mismatch" - assert validation_summary["1"][0]["expected_columns"] == ["id", "item", "price", "quantity"] - assert validation_summary["1"][0]["actual_columns"] == ["id", "item", "quantity"] + assert 1 in validation_summary + assert validation_summary[1][0]["status"] == "Column length mismatch" + assert validation_summary[1][0]["expected_columns"] == ["id", "item", "price", "quantity"] + assert validation_summary[1][0]["actual_columns"] == ["id", "item", "quantity"] CognitionSchema.objects(bot=bot, collection_name=collection_name).delete() def test_validate_data_invalid_columns(self): @@ -1664,7 +1665,7 @@ def test_validate_data_invalid_columns(self): cognition_schema.save() data = [ - {"id": "1", "item": "Juice", "quantity": 10, "discount": 0.10} # Invalid "discount" column + {"id": 1, "item": "Juice", "quantity": 10, "discount": 0.10} ] processor = CognitionDataProcessor() @@ -1675,10 +1676,10 @@ def test_validate_data_invalid_columns(self): data=data, bot=bot ) - assert "1" in validation_summary - assert validation_summary["1"][0]["status"] == "Invalid columns in input data" - assert validation_summary["1"][0]["expected_columns"] == ["id", "item", "price", "quantity"] - assert validation_summary["1"][0]["actual_columns"] == ["id", "item", "quantity", "discount"] + assert 1 in validation_summary + assert validation_summary[1][0]["status"] == "Invalid columns in input data" + assert validation_summary[1][0]["expected_columns"] == ["id", "item", "price", "quantity"] + assert validation_summary[1][0]["actual_columns"] == ["id", "item", "quantity", "discount"] CognitionSchema.objects(bot=bot, collection_name=collection_name).delete() def test_validate_data_document_non_existence(self): @@ -1706,10 +1707,10 @@ def test_validate_data_document_non_existence(self): cognition_schema.save() dummy_data = { - "id": "1", + "id": 1, "item": "Juice", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } existing_document = CognitionData( data=dummy_data, @@ -1722,7 +1723,7 @@ def test_validate_data_document_non_existence(self): existing_document.save() data = [ - {"id": "2", "price": 27.0} + {"id": 2, "price": 27.0} ] processor = CognitionDataProcessor() @@ -1733,9 +1734,9 @@ def test_validate_data_document_non_existence(self): data=data, bot=bot ) - assert "2" in validation_summary - assert validation_summary["2"][0]["status"] == "Document does not exist" - assert validation_summary["2"][0]["primary_key"] == "2" + assert 2 in validation_summary + assert validation_summary[2][0]["status"] == "Document does not exist" + assert validation_summary[2][0]["primary_key"] == 2 CognitionSchema.objects(bot=bot, collection_name="groceries").delete() CognitionData.objects(bot=bot, collection="groceries").delete() @@ -1771,10 +1772,10 @@ async def test_upsert_data_push_menu_success(self, mock_embedding, mock_collecti cognition_schema.save() dummy_data = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } existing_document = CognitionData( data=dummy_data, @@ -1787,8 +1788,8 @@ async def test_upsert_data_push_menu_success(self, mock_embedding, mock_collecti existing_document.save() upsert_data = [ - {"id": 1, "item": "Juice", "price": "2.50", "quantity": "10"}, # New entry - {"id": 2, "item": "Milk", "price": "3.00", "quantity": "5"} # Existing entry to be updated + {"id": 1, "item": "Juice", "price": 2.50, "quantity": 10}, # New entry + {"id": 2, "item": "Milk", "price": 3.00, "quantity": 5} # Existing entry to be updated ] llm_secret = LLMSecret( @@ -1824,17 +1825,17 @@ async def test_upsert_data_push_menu_success(self, mock_embedding, mock_collecti assert result["message"] == "Upsert complete!" assert len(upserted_data) == 2 - inserted_record = next((item for item in upserted_data if item.data["id"] == "1"), None) + inserted_record = next((item for item in upserted_data if item.data["id"] == 1), None) assert inserted_record is not None assert inserted_record.data["item"] == "Juice" - assert inserted_record.data["price"] == "2.50" - assert inserted_record.data["quantity"] == "10" + assert inserted_record.data["price"] == 2.50 + assert inserted_record.data["quantity"] == 10 - updated_record = next((item for item in upserted_data if item.data["id"] == "2"), None) + updated_record = next((item for item in upserted_data if item.data["id"] == 2), None) assert updated_record is not None assert updated_record.data["item"] == "Milk" - assert updated_record.data["price"] == "3.00" # Updated price - assert updated_record.data["quantity"] == "5" + assert updated_record.data["price"] == 3.00 # Updated price + assert updated_record.data["quantity"] == 5 CognitionSchema.objects(bot=bot, collection_name="groceries").delete() CognitionData.objects(bot=bot, collection="groceries").delete() @@ -1871,10 +1872,10 @@ async def test_upsert_data_field_update_success(self, mock_embedding, mock_colle cognition_schema.save() dummy_data_one = { - "id": "1", + "id": 1, "item": "Juice", - "price": "2.80", - "quantity": "56" + "price": 2.80, + "quantity": 56 } existing_document = CognitionData( data=dummy_data_one, @@ -1887,10 +1888,10 @@ async def test_upsert_data_field_update_success(self, mock_embedding, mock_colle existing_document.save() dummy_data_two = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "12" + "price": 2.80, + "quantity": 12 } existing_document = CognitionData( data=dummy_data_two, @@ -1903,8 +1904,8 @@ async def test_upsert_data_field_update_success(self, mock_embedding, mock_colle existing_document.save() upsert_data = [ - {"id": 1, "price": "80.50"}, - {"id": 2, "price": "27.00"} + {"id": 1, "price": 80.50}, + {"id": 2, "price": 27.00} ] llm_secret = LLMSecret( @@ -1940,17 +1941,17 @@ async def test_upsert_data_field_update_success(self, mock_embedding, mock_colle assert result["message"] == "Upsert complete!" assert len(upserted_data) == 2 - inserted_record = next((item for item in upserted_data if item.data["id"] == "1"), None) + inserted_record = next((item for item in upserted_data if item.data["id"] == 1), None) assert inserted_record is not None assert inserted_record.data["item"] == "Juice" - assert inserted_record.data["price"] == "80.50" - assert inserted_record.data["quantity"] == "56" + assert inserted_record.data["price"] == 80.50 + assert inserted_record.data["quantity"] == 56 - updated_record = next((item for item in upserted_data if item.data["id"] == "2"), None) + updated_record = next((item for item in upserted_data if item.data["id"] == 2), None) assert updated_record is not None assert updated_record.data["item"] == "Milk" - assert updated_record.data["price"] == "27.00" # Updated price - assert updated_record.data["quantity"] == "12" + assert updated_record.data["price"] == 27.00 # Updated price + assert updated_record.data["quantity"] == 12 CognitionSchema.objects(bot=bot, collection_name="groceries").delete() CognitionData.objects(bot=bot, collection="groceries").delete() @@ -1987,10 +1988,10 @@ async def test_upsert_data_empty_data_list(self, mock_embedding, mock_collection cognition_schema.save() dummy_data = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } existing_document = CognitionData( data=dummy_data, @@ -2037,10 +2038,10 @@ async def test_upsert_data_empty_data_list(self, mock_embedding, mock_collection assert len(data) == 1 existing_record = data[0] - assert existing_record.data["id"] == "2" + assert existing_record.data["id"] == 2 assert existing_record.data["item"] == "Milk" - assert existing_record.data["price"] == "2.80" - assert existing_record.data["quantity"] == "5" + assert existing_record.data["price"] == 2.80 + assert existing_record.data["quantity"] == 5 CognitionSchema.objects(bot=bot, collection_name=collection_name).delete() CognitionData.objects(bot=bot, collection=collection_name).delete() @@ -2073,10 +2074,10 @@ async def test_sync_with_qdrant_success(self, mock_collection_upsert, mock_embed cognition_schema.save() document_data = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } document = CognitionData( data=document_data, @@ -2091,7 +2092,7 @@ async def test_sync_with_qdrant_success(self, mock_collection_upsert, mock_embed saved_document = None for doc in CognitionData.objects(bot=bot, collection=collection_name): doc_dict = doc.to_mongo().to_dict() - if doc_dict.get("data", {}).get("id") == "2": # Match based on `data.id` + if doc_dict.get("data", {}).get("id") == 2: # Match based on `data.id` saved_document = doc_dict break assert saved_document, "Saved CognitionData document not found" @@ -2179,10 +2180,10 @@ async def test_sync_with_qdrant_upsert_failure(self, mock_request, mock_embeddin cognition_schema.save() document_data = { - "id": "2", + "id": 2, "item": "Milk", - "price": "2.80", - "quantity": "5" + "price": 2.80, + "quantity": 5 } document = CognitionData( data=document_data, @@ -17996,7 +17997,7 @@ def test_save_payload_content_invalid_data_type(self): "data": {"number": "Twenty-three"}, "content_type": "json", "collection": "test_save_payload_content_invalid_data_type"} - with pytest.raises(AppException, match="Invalid data type!"): + with pytest.raises(AppException, match="Invalid data type for 'number': Expected integer value"): processor.save_cognition_data(payload, user, bot) def test_save_payload_content_data_empty(self): diff --git a/tests/unit_test/llm_test.py b/tests/unit_test/llm_test.py index 34e39e99c..46e42ed8b 100644 --- a/tests/unit_test/llm_test.py +++ b/tests/unit_test/llm_test.py @@ -235,7 +235,7 @@ async def test_gpt3_faq_embedding_train_payload_with_int(self, mock_embedding, a collection_name="payload_with_int", bot=bot, user=user).save() test_content = CognitionData( - data={"name": "Ram", "age": "23", "color": "red"}, + data={"name": "Ram", "age": 23, "color": "red"}, content_type="json", collection="payload_with_int", bot=bot, user=user).save() diff --git a/tests/unit_test/validator/content_importer_test.py b/tests/unit_test/validator/content_importer_test.py index b3192e452..1af11f73f 100644 --- a/tests/unit_test/validator/content_importer_test.py +++ b/tests/unit_test/validator/content_importer_test.py @@ -151,10 +151,10 @@ def test_import_data_success(self): assert cognition_data.count() == original_row_count last_row = cognition_data.order_by('-_id').first() assert last_row["data"] == { - 'order_id': '67', - 'order_priority': 'Low', - 'sales': '12.34', - 'profit': '54.98' + 'order_id': 67, + 'order_priority': "Low", + 'sales': 12.34, + 'profit': 54.98 } def test_import_data_partial_success(self): @@ -185,18 +185,18 @@ def test_import_data_partial_success(self): third_last_row = cognition_data[-3] assert third_last_row["data"] == { - "order_id": "33", + "order_id": 33, "order_priority": "Low", - "sales": "905.94", - "profit": "-4.19" + "sales": 905.94, + "profit": -4.19 } fourth_last_row = cognition_data[-4] assert fourth_last_row["data"] == { - "order_id": "657", + "order_id": 657, "order_priority": "Not Specified", - "sales": "237.28", - "profit": "-2088.68" + "sales": 237.28, + "profit": -2088.68 }