def test_validate_undefined_field(schema): tagpack = TagPack('http://example.com', 'tests/testfiles/tagpack_fail_undefined_field.yaml', schema) with pytest.raises(ValidationError) as e: schema.validate(tagpack, None) assert "Field failfield not allowed in header" in str(e.value)
def test_validate_fail_taxonomy_header(schema, taxonomies): tagpack = TagPack('http://example.com', 'tests/testfiles/tagpack_fail_taxonomy_header.yaml', schema) with pytest.raises(ValidationError) as e: schema.validate(tagpack, taxonomies) assert "Undefined concept unknown in field category" in str(e.value)
def test_load_from_file_entity_tagpack(schema, taxonomies): tagpack = TagPack.load_from_file('http://example.com/', 'tests/testfiles/ex_entity_tagpack.yaml', schema, taxonomies) assert isinstance(tagpack, TagPack) assert tagpack.uri == \ 'http://example.com/tests/testfiles/ex_entity_tagpack.yaml' assert tagpack.contents['title'] == 'Test Entity TagPack' assert isinstance(tagpack.schema, TagPackSchema) assert 'title' in tagpack.schema.header_fields assert isinstance(tagpack.taxonomies, dict)
def tagpack(schema, taxonomies): return TagPack('http://example.com', {'title': 'Test TagPack', 'creator': 'GraphSense Team', 'source': 'http://example.com/my_addresses', 'currency': 'BTC', 'lastmod': date.fromisoformat('2021-04-21'), 'tags': [ {'label': 'Some attribution tag', 'address': '123Bitcoin45' } ]}, schema, taxonomies)
def test_validate(schema): tagpack = TagPack('http://example.com', 'tests/testfiles/tagpack_ok.yaml', schema) schema.validate(tagpack, None)
def test_validate_ok_generic_field(schema, taxonomies): tagpack = TagPack('http://example.com', 'tests/testfiles/tagpack_ok_generic_field.yaml', schema) schema.validate(tagpack, taxonomies)
def test_validate_fail_missing_body(schema): tagpack = TagPack('http://example.com', 'tests/testfiles/tagpack_fail_missing_body.yaml', schema) with pytest.raises(ValidationError) as e: schema.validate(tagpack, None) assert "Mandatory field address missing" in str(e.value)
def test_validate_fail_type_date(schema): tagpack = TagPack('http://example.com', 'tests/testfiles/tagpack_fail_type_date.yaml', schema) with pytest.raises(ValidationError) as e: schema.validate(tagpack, None) assert "Field lastmod must be of type datetime" in str(e.value)
def test_init_fail_invalid_file(schema): with pytest.raises(TagPackFileError) as e: TagPack('http://example.com', 'tests/testfiles/tagpack_fail_invalid_file.yaml', schema) assert "Cannot extract TagPack fields" in str(e.value)
def tagpack(schema): return TagPack('http://example.com', TEST_TAGPACK, schema)