Skip to content
Snippets Groups Projects
Commit 42b22d67 authored by florian's avatar florian
Browse files

TST: Extend json cfood in unit tests

parent b325d6fb
No related branches found
No related tags found
2 merge requests!53Release 0.1,!15F fix reference list
...@@ -203,9 +203,10 @@ def test_json_converter(converter_registry): ...@@ -203,9 +203,10 @@ def test_json_converter(converter_registry):
assert children[2].name == "archived" assert children[2].name == "archived"
assert children[2].value.__class__ == bool assert children[2].value.__class__ == bool
assert children[3].__class__ == DictDictElement assert children[3].__class__ == DictListElement
assert children[3].name == "coordinator" assert children[3].name == "Person"
assert children[3].value.__class__ == dict assert children[3].value.__class__ == list
assert len(children[3].value) == 2
assert children[4].__class__ == DictTextElement assert children[4].__class__ == DictTextElement
assert children[4].name == "start_date" assert children[4].name == "start_date"
......
...@@ -3,13 +3,56 @@ JSONTest: # name of the converter ...@@ -3,13 +3,56 @@ JSONTest: # name of the converter
type: JSONFile type: JSONFile
match: '(.*)' match: '(.*)'
validate: ./testjson.schema.json validate: ./testjson.schema.json
subtree: records:
element: # name of the first subtree element which is a converter Project: # this is an identifiable in this case
parents:
- Project # not needed as the name is equivalent
subtree:
name_element:
type: DictTextElement
match_name: "name"
match_value: "(?P<name>.*)"
records:
Project:
name: $name
url_element: # name of the first subtree element which is a converter
type: DictTextElement type: DictTextElement
match_value: "(?P<url>.*)" match_value: "(?P<url>.*)"
match_name: "url" match_name: "url"
records: records:
Project: # this is an identifiable in this case Project:
parents: url: $url
- Project # not needed as the name is equivalent persons_element:
url: $url type: DictListElement
match_name: "Person"
subtree:
person_element:
type: Dict
records:
Person:
parents:
- Person
Project:
Person: +$Person
subtree:
firstname_element:
type: DictTextElement
match_name: "firstname"
match_value: "(?P<firstname>.*)"
records:
Person:
firstname: $firstname
lastname_element:
type: DictTextElement
match_name: "lastname"
match_value: "(?P<lastname>.*)"
records:
Person:
lastname: $lastname
email_element:
type: DictTextElement
match_name: "email"
match_value: "(?P<email>.*)"
records:
Person:
email: $email
...@@ -2,11 +2,18 @@ ...@@ -2,11 +2,18 @@
"name": "DEMO", "name": "DEMO",
"projectId": 10002, "projectId": 10002,
"archived": false, "archived": false,
"coordinator": { "Person": [
"firstname": "Miri", {
"lastname": "Mueller", "firstname": "Miri",
"email": "miri.mueller@science.de" "lastname": "Mueller",
}, "email": "miri.mueller@science.de"
},
{
"firstname": "Mara",
"lastname": "Mueller",
"email": "mara.mueller@science.de"
}
],
"start_date": "2022-03-01", "start_date": "2022-03-01",
"candidates": ["Mouse", "Penguine"], "candidates": ["Mouse", "Penguine"],
"rvalue": 0.4444, "rvalue": 0.4444,
......
...@@ -11,25 +11,28 @@ ...@@ -11,25 +11,28 @@
"archived": { "archived": {
"type": "boolean" "type": "boolean"
}, },
"coordinator": { "Person": {
"type": "object", "type": "array",
"properties": { "items": {
"firstname": { "type": "object",
"type": "string" "properties": {
}, "firstname": {
"lastname": { "type": "string"
"type": "string" },
}, "lastname": {
"email": { "type": "string"
"type": "string" },
"email": {
"type": "string"
}
},
"required": [
"firstname",
"lastname",
"email"
],
"additionalProperties": true
} }
},
"required": [
"firstname",
"lastname",
"email"
],
"additionalProperties": true
}, },
"start_date": { "start_date": {
"type": "string", "type": "string",
...@@ -51,7 +54,7 @@ ...@@ -51,7 +54,7 @@
"required": [ "required": [
"name", "name",
"projectId", "projectId",
"coordinator" "Person"
], ],
"additionalProperties": false "additionalProperties": false
} }
...@@ -47,19 +47,24 @@ def test_json(): ...@@ -47,19 +47,24 @@ def test_json():
# Load and register converter packages: # Load and register converter packages:
converter_registry = crawler.load_converters(crawler_definition) converter_registry = crawler.load_converters(crawler_definition)
crawler.start_crawling( records = crawler.start_crawling(
JSONFile(os.path.basename(json_file_path), json_file_path), JSONFile(os.path.basename(json_file_path), json_file_path),
crawler_definition, crawler_definition,
converter_registry converter_registry
) )
subd = crawler.debug_tree
subc = crawler.debug_metadata rec = [r for r in records if r.name == "DEMO"]
#print(json.dumps(subd, indent=3)) assert len(rec) == 1
print(subd) rec = rec[0]
print(subc) assert len(rec.parents) == 1
assert rec.parents[0].name == "Project"
assert rec.get_property("url") is not None
assert rec.get_property("url").value == "https://site.de/index.php/"
def test_broken_validation(): def test_broken_validation():
crawler_definition_path = rfp("broken_cfoods", "broken_validation_path.yml") crawler_definition_path = rfp(
"broken_cfoods", "broken_validation_path.yml")
crawler = Crawler() crawler = Crawler()
with raises(FileNotFoundError) as err: with raises(FileNotFoundError) as err:
crawler_definition = crawler.load_definition(crawler_definition_path) crawler_definition = crawler.load_definition(crawler_definition_path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment