From ba44ef7b5262c6115df2c34f56bd5ceaabfcfcce Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Fri, 5 Sep 2025 16:21:06 +0100 Subject: [PATCH] More tests --- .../test_cli/test_load_structured_data.py | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/tests/unit/test_cli/test_load_structured_data.py b/tests/unit/test_cli/test_load_structured_data.py index 1da4b50d..70012274 100644 --- a/tests/unit/test_cli/test_load_structured_data.py +++ b/tests/unit/test_cli/test_load_structured_data.py @@ -244,25 +244,46 @@ Bob Johnson,bob@company.org,42,UK""" # Validation Tests def test_validation_rules_required_fields(self): - """Test validation rules for required fields""" - record = {"name": "John", "email": ""} # Missing required email - mappings = [ - { - "source_field": "name", - "target_field": "name", - "transforms": [], - "validation": [{"type": "required"}] - }, - { - "source_field": "email", - "target_field": "email", - "transforms": [], - "validation": [{"type": "required"}] + """Test CLI processes data with validation requirements""" + test_data = "name,email\nJohn,\nJane,jane@email.com" + descriptor_with_validation = { + "version": "1.0", + "format": {"type": "csv", "encoding": "utf-8", "options": {"header": True}}, + "mappings": [ + { + "source_field": "name", + "target_field": "name", + "transforms": [], + "validation": [{"type": "required"}] + }, + { + "source_field": "email", + "target_field": "email", + "transforms": [], + "validation": [{"type": "required"}] + } + ], + "output": { + "format": "trustgraph-objects", + "schema_name": "customer", + "options": {"confidence": 0.9, "batch_size": 100} } - ] + } - result = apply_transformations(record, mappings) + input_file = self.create_temp_file(test_data, '.csv') + descriptor_file = self.create_temp_file(json.dumps(descriptor_with_validation), '.json') - # Should still process but may log warnings - assert "name" in result - assert "email" in result \ No newline at end of file + try: + # Should process despite validation issues (warnings logged) + result = load_structured_data( + api_url="http://localhost:8088", + input_file=input_file, + descriptor_file=descriptor_file, + dry_run=True + ) + + assert result is None # Dry run returns None + + finally: + self.cleanup_temp_file(input_file) + self.cleanup_temp_file(descriptor_file) \ No newline at end of file