More tests

This commit is contained in:
Cyber MacGeddon 2025-09-05 16:22:26 +01:00
parent ba44ef7b52
commit ed41d05016

View file

@ -158,15 +158,17 @@ Bob Johnson,bob@company.org,42,UK"""
f.flush() f.flush()
try: try:
# Should read file without errors (API calls will fail but that's expected) # Should read file and process schema suggestion
with pytest.raises(Exception): # Expected to fail at API stage result = load_structured_data(
load_structured_data( api_url="http://localhost:8088",
api_url="http://localhost:8088", input_file=f.name,
input_file=f.name, suggest_schema=True,
suggest_schema=True, sample_size=100,
sample_size=100, sample_chars=500
sample_chars=500 )
)
# Schema suggestion completes and returns None
assert result is None
finally: finally:
os.unlink(f.name) os.unlink(f.name)
@ -179,14 +181,16 @@ Bob Johnson,bob@company.org,42,UK"""
f.flush() f.flush()
try: try:
# Should read file without errors (API calls will fail but that's expected) # Should read file and generate descriptor
with pytest.raises(Exception): # Expected to fail at API stage result = load_structured_data(
load_structured_data( api_url="http://localhost:8088",
api_url="http://localhost:8088", input_file=f.name,
input_file=f.name, generate_descriptor=True,
generate_descriptor=True, sample_chars=500
sample_chars=500 )
)
# Descriptor generation completes and returns None
assert result is None
finally: finally:
os.unlink(f.name) os.unlink(f.name)
@ -211,14 +215,15 @@ Bob Johnson,bob@company.org,42,UK"""
desc_file.flush() desc_file.flush()
try: try:
# Should load descriptor file but may fail at processing stage # Should handle invalid descriptor gracefully - creates default processing
with pytest.raises(Exception): # Expected to fail at validation or processing result = load_structured_data(
load_structured_data( api_url="http://localhost:8088",
api_url="http://localhost:8088", input_file=input_file.name,
input_file=input_file.name, descriptor_file=desc_file.name,
descriptor_file=desc_file.name, dry_run=True
dry_run=True )
)
assert result is None # Dry run returns None
finally: finally:
os.unlink(input_file.name) os.unlink(input_file.name)
os.unlink(desc_file.name) os.unlink(desc_file.name)
@ -231,13 +236,14 @@ Bob Johnson,bob@company.org,42,UK"""
try: try:
# Should handle parsing errors gracefully # Should handle parsing errors gracefully
with pytest.raises(Exception): result = load_structured_data(
load_structured_data( api_url="http://localhost:8088",
api_url="http://localhost:8088", input_file=input_file,
input_file=input_file, descriptor_file=descriptor_file,
descriptor_file=descriptor_file, dry_run=True
dry_run=True )
)
assert result is None # Dry run returns None
finally: finally:
self.cleanup_temp_file(input_file) self.cleanup_temp_file(input_file)
self.cleanup_temp_file(descriptor_file) self.cleanup_temp_file(descriptor_file)