Commit c4ff054e authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Add tests

parent 9d387437
import pytest
from validata_core import validate
@pytest.fixture()
def schema_with_orphan_custom_check():
return {
"$schema": "https://frictionlessdata.io/schemas/table-schema.json",
"fields": [
{
"name": "siren",
"title": "Numéro SIREN",
"type": "string",
}
],
"custom_checks": [
{"name": "french-siren-value", "params": {"column": "sirene"}}
],
}
@pytest.fixture()
def schema_with_unknown_custom_check():
return {
"$schema": "https://frictionlessdata.io/schemas/table-schema.json",
"fields": [
{
"name": "siren",
"title": "Numéro SIREN",
"type": "string",
}
],
"custom_checks": [{"name": "foo-siren-value", "params": {"column": "sirene"}}],
}
@pytest.fixture()
def schema_with_non_existing_primary_key():
return {
"$schema": "https://frictionlessdata.io/schemas/table-schema.json",
"fields": [
{
"name": "a",
}
],
"primaryKey": ["b"],
}
@pytest.fixture()
def schema_with_existing_primary_key():
return {
"$schema": "https://frictionlessdata.io/schemas/table-schema.json",
"fields": [
{
"name": "a",
}
],
"primaryKey": ["a"],
}
def test_schema_with_orphan_custom_checks(schema_with_orphan_custom_check):
source = [["siren"], ["529173189"]]
report = validate(source, schema_with_orphan_custom_check)
assert not report.valid
# Error doesn't appear in error common list
assert len(report.errors) == 0
# but in task errors
assert len(report.tasks[0].errors) == 1
# as a 'check-error'
assert report.tasks[0].errors[0]["code"] == "check-error"
def test_schema_with_unknown_custom_checks(schema_with_unknown_custom_check):
source = [["siren"], ["529173189"]]
report = validate(source, schema_with_unknown_custom_check)
assert not report.valid
# Error doesn't appear in error common list
assert len(report.errors) == 0
# but in task errors
assert len(report.tasks[0].errors) == 1
# as a 'check-error'
assert report.tasks[0].errors[0]["code"] == "check-error"
print(report.tasks[0].errors[0]["note"])
def test_primary_key_schema(schema_with_non_existing_primary_key):
source = [["a"], ["foo"]]
report = validate(source, schema_with_non_existing_primary_key)
assert not report.valid
assert report["errors"]
assert report["errors"][0]["code"] == "schema-error"
def test_primary_key_schema_2(schema_with_existing_primary_key):
source = [["b"], ["foo"]]
report = validate(source, schema_with_existing_primary_key)
assert not report.valid
assert not report["errors"]
assert report["tasks"]
assert report["tasks"][0]["errors"]
assert report["tasks"][0]["errors"][0]["code"] == "schema-error"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment