|
8 | 8 | from rdflib.namespace import RDF
|
9 | 9 |
|
10 | 10 | from ckanext.dcat.processors import RDFParser
|
| 11 | +from ckanext.dcatapchharvest.dcat_helpers import get_langs |
11 | 12 | from ckanext.dcatapchharvest.profiles import (DCAT, DCT)
|
12 | 13 | from ckanext.dcatapchharvest.tests.base_test_classes import BaseParseTest
|
13 | 14 |
|
|
16 | 17 |
|
17 | 18 |
|
18 | 19 | class TestSwissDCATAPProfileParsing(BaseParseTest):
|
| 20 | + languages = get_langs() |
19 | 21 |
|
20 | 22 | def test_rights_license(self):
|
21 | 23 |
|
@@ -51,16 +53,16 @@ def test_dataset_all_fields(self):
|
51 | 53 | extras = self._extras(dataset)
|
52 | 54 |
|
53 | 55 | # Basic fields
|
54 |
| - assert all(l in dataset['title'] for l in ['de', 'fr', 'it', 'en']), "title contains all languages" |
| 56 | + assert all(l in dataset['title'] for l in self.languages), "title contains all languages" |
55 | 57 | eq_(dataset['title']['de'], u'Statistisches Jahrbuch der Schweiz 1901')
|
56 | 58 | eq_(dataset['title']['fr'], u'Annuaire statistique de la Suisse 1901')
|
57 | 59 |
|
58 |
| - assert all(l in dataset['description'] for l in ['de', 'fr', 'it', 'en']), "description contains all languages" |
| 60 | + assert all(l in dataset['description'] for l in self.languages), "description contains all languages" |
59 | 61 | eq_(dataset['description']['de'], u'')
|
60 | 62 | eq_(dataset['url'], u'https://www.bfs.admin.ch/bfs/de/home/statistiken.html')
|
61 | 63 |
|
62 | 64 | # Keywords
|
63 |
| - assert all(l in dataset['keywords'] for l in ['de', 'fr', 'it', 'en']), "keywords contains all languages" |
| 65 | + assert all(l in dataset['keywords'] for l in self.languages), "keywords contains all languages" |
64 | 66 | eq_(sorted(dataset['keywords']['de']), ['publikation', 'statistische-grundlagen-und-ubersichten'])
|
65 | 67 | eq_(sorted(dataset['keywords']['fr']), ['bases-statistiques-et-generalites', 'publication'])
|
66 | 68 | eq_(sorted(dataset['keywords']['it']), ['basi-statistiche-e-presentazioni-generali', 'pubblicazione'])
|
@@ -101,6 +103,32 @@ def test_dataset_all_fields(self):
|
101 | 103 | see_also = dataset['see_alsos'][0]
|
102 | 104 | eq_(see_also['dataset_identifier'], u'4682791@bundesamt-fur-statistik-bfs')
|
103 | 105 |
|
| 106 | + relations = sorted(dataset["relations"], key=lambda relation: relation['url']) |
| 107 | + |
| 108 | + # Relations - only one label given, no language specified |
| 109 | + eq_(relations[0]['url'], "https://www.admin.ch/opc/de/classified-compilation/19920252/index.html") |
| 110 | + for lang in self.languages: |
| 111 | + eq_(relations[0]['label'][lang], 'legal_basis') |
| 112 | + |
| 113 | + # Relations - multilingual labels |
| 114 | + eq_(relations[1]['url'], "https://www.example.org/aaa") |
| 115 | + for lang in self.languages: |
| 116 | + eq_(relations[1]['label'][lang], 'Text for label ' + lang.upper()) |
| 117 | + |
| 118 | + # Relations - no label given |
| 119 | + eq_(relations[2]['url'], "https://www.example.org/bbb") |
| 120 | + for lang in self.languages: |
| 121 | + eq_(relations[2]['label'][lang], "https://www.example.org/bbb") |
| 122 | + |
| 123 | + # Relations - label given, language specified but not German. |
| 124 | + # If there is no label given in a language, we try to get one from |
| 125 | + # another language, in the priority order 'en' -> 'de' -> 'fr' -> 'it'. |
| 126 | + # Here we test that we end up with a label text in all languages, even |
| 127 | + # though the source only had a label in Italian. |
| 128 | + eq_(relations[3]['url'], "https://www.example.org/ccc") |
| 129 | + for lang in self.languages: |
| 130 | + eq_(relations[3]['label'][lang], 'Text for label IT') |
| 131 | + |
104 | 132 | # Qualified relations
|
105 | 133 | qualified_relations = sorted(dataset["qualified_relations"])
|
106 | 134 | eq_(
|
@@ -138,10 +166,10 @@ def test_dataset_all_fields(self):
|
138 | 166 | resource = dataset['resources'][0]
|
139 | 167 |
|
140 | 168 | # Simple values
|
141 |
| - assert all(l in resource['title'] for l in ['de', 'fr', 'it', 'en']), "resource title contains all languages" |
| 169 | + assert all(l in resource['title'] for l in self.languages), "resource title contains all languages" |
142 | 170 | eq_(resource['title']['fr'], u'Annuaire statistique de la Suisse 1901')
|
143 | 171 | eq_(resource['title']['de'], u'')
|
144 |
| - assert all(l in resource['description'] for l in ['de', 'fr', 'it', 'en']), "resource description contains all languages" |
| 172 | + assert all(l in resource['description'] for l in self.languages), "resource description contains all languages" |
145 | 173 | eq_(resource['description']['de'], u'')
|
146 | 174 | eq_(resource['format'], u'html')
|
147 | 175 | eq_(resource['media_type'], u'text/html')
|
|
0 commit comments