Skip to content

Commit

Permalink
data model: schema and mapping and unit testing adaptation for languages
Browse files Browse the repository at this point in the history
* Adapts languages to json schema and mapping.
* Adapts unit testing.

Co-Authored-by: Aly Badr aly.badr@rero.ch
  • Loading branch information
Aly Badr committed Aug 7, 2019
1 parent fc57ec4 commit 6f5021b
Show file tree
Hide file tree
Showing 8 changed files with 7,579 additions and 9,309 deletions.
8,454 changes: 3,800 additions & 4,654 deletions data/items10k.json

Large diffs are not rendered by default.

8,334 changes: 3,719 additions & 4,615 deletions data/items300.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def unimarclanguages(self, key, value):
)
schema = loads(schema_in_bytes.decode('utf8'))
langs = schema[
'properties']['languages']['items']['properties']['language']['enum']
'properties']['language']['items']['properties']['value']['enum']
for language in languages:
if language in langs:
to_return.append({'language': language})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"pid",
"type",
"title",
"languages",
"language",
"identifiedBy"
],
"additionalProperties": false,
Expand Down Expand Up @@ -63,24 +63,29 @@
"type": "string",
"minLength": 3
},
"languages": {
"title": "Languages",
"language": {
"title": "Language",
"description": "List of languages for the resource.",
"type": "array",
"uniqueItems": true,
"minItems": 1,
"items": {
"type": "object",
"required": [
"language"
"type",
"value"
],
"additionalProperties": false,
"properties": {
"language": {
"title": "Language",
"description": "Required. Language of the resource, primary or not.",
"type": {
"title": "Type",
"description": "Type of the value.",
"type": "string",
"minLength": 3
},
"value": {
"title": "Language value",
"description": "Language value.",
"type": "string",
"default": "fre",
"validationMessage": "Required. Language of the resource, primary or not.",
"enum": [
"fre",
"ger",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"pid",
"type",
"title",
"languages"
"language"
],
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -62,24 +62,29 @@
"type": "string",
"minLength": 3
},
"languages": {
"title": "Languages",
"language": {
"title": "Language",
"description": "List of languages for the resource.",
"type": "array",
"uniqueItems": true,
"minItems": 1,
"items": {
"type": "object",
"required": [
"language"
"type",
"value"
],
"additionalProperties": false,
"properties": {
"language": {
"title": "Language",
"description": "Required. Language of the resource, primary or not.",
"type": {
"title": "Type",
"description": "Type of the value.",
"type": "string",
"minLength": 3
},
"value": {
"title": "Language value",
"description": "Language value.",
"type": "string",
"default": "fre",
"validationMessage": "Required. Language of the resource, primary or not.",
"enum": [
"fre",
"ger",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@
"type": {
"type": "keyword"
},
"languages": {
"language": {
"type": "object",
"properties": {
"language": {
"type": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
}
Expand Down Expand Up @@ -380,4 +383,4 @@
}
}
}
}
}
35 changes: 21 additions & 14 deletions tests/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,10 @@
"formats": [
"18 cm"
],
"languages": [
"language": [
{
"language": "fre"
"type": "bf:Language",
"value": "fre"
}
],
"publishers": [
Expand Down Expand Up @@ -944,9 +945,10 @@
"$schema": "https://ils.rero.ch/schema/documents/document-v0.0.1.json",
"pid": "doc2",
"type": "book",
"languages": [
"language": [
{
"language": "ara"
"type": "bf:Language",
"value": "ara"
}
],
"harvested": false,
Expand Down Expand Up @@ -1017,9 +1019,10 @@
"formats": [
"18 cm"
],
"languages": [
"language": [
{
"language": "fre"
"type": "bf:Language",
"value": "fre"
}
],
"publishers": [
Expand Down Expand Up @@ -1061,9 +1064,10 @@
"type": "ebook",
"harvested": true,
"title": "La maison des oubli\u00e9s",
"languages": [
"language": [
{
"language": "fre"
"type": "bf:Language",
"value": "fre"
}
],
"authors": [
Expand Down Expand Up @@ -1116,9 +1120,10 @@
}
],
"title": "Kurkuma: Effekte auf den menschlichen K\u00f6rper-Der aktuelle Stand der Wissenschaft",
"languages": [
"language": [
{
"language": "ger"
"type": "bf:Language",
"value": "ger"
}
],
"authors": [
Expand Down Expand Up @@ -1156,9 +1161,10 @@
"type": "ebook",
"harvested": true,
"title": "Harry Potter and the Chamber of Secrets",
"languages": [
"language": [
{
"language": "eng"
"type": "bf:Language",
"value": "eng"
}
],
"authors": [
Expand Down Expand Up @@ -1196,9 +1202,10 @@
"type": "ebook",
"harvested": true,
"title": "Nouveau titre",
"languages": [
"language": [
{
"language": "fre"
"type": "bf:Language",
"value": "fre"
}
],
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_documents_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def test_languages(document_schema, document_data_tmp):
validate(document_data_tmp, document_schema)

with pytest.raises(ValidationError):
document_data_tmp['languages'][0]['language'] = [2]
document_data_tmp['language'][0]['value'] = [2]
validate(document_data_tmp, document_schema)

with pytest.raises(ValidationError):
document_data_tmp['languages'][0]['language'] = ['gre']
document_data_tmp['language'][0]['value'] = ['gre']
validate(document_data_tmp, document_schema)


Expand Down

0 comments on commit 6f5021b

Please sign in to comment.