Coverage for apis_core/utils/test_rdf.py: 100%
37 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-06-25 10:00 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-06-25 10:00 +0000
1# SPDX-FileCopyrightText: 2023 Birger Schacht
2# SPDX-License-Identifier: MIT
4from pathlib import Path
6from django.test import TestCase
8from apis_core.utils import rdf
10# use `curl -H "Accept: application/rdf+xml" -L $URI` to fetch data
12testdata = Path(__file__).parent / "testdata"
15class RdfTest(TestCase):
16 def test_get_definition_from_dict_place_from_geonames(self):
17 achensee = {
18 "latitude": ["47.5"],
19 "longitude": ["11.7"],
20 "label": ["Achensee"],
21 }
22 # https://www.geonames.org/2783029/achensee.html
23 uri = str(testdata / "achensee.rdf")
25 attributes = rdf.get_something_from_uri(uri)
26 self.assertEqual(achensee["latitude"], attributes["latitude"])
27 self.assertEqual(achensee["longitude"], attributes["longitude"])
28 self.assertEqual(achensee["label"], attributes["label"])
30 def test_get_definition_from_dict_place_from_dnb(self):
31 wien = {
32 "label": ["Wien"],
33 "latitude": ["+048.208199"],
34 "longitude": ["016.371690"],
35 }
36 # https://d-nb.info/gnd/4066009-6
37 uri = str(testdata / "wien.rdf")
39 attributes = rdf.get_something_from_uri(uri)
40 self.assertEqual(wien["latitude"], attributes["latitude"])
41 self.assertEqual(wien["longitude"], attributes["longitude"])
42 self.assertEqual(wien["label"], attributes["label"])
44 def test_get_definition_from_dict_person_from_dnb(self):
45 pierre = {
46 "forename": [
47 "Pierre",
48 "Pʹer",
49 "Rudolf",
50 "Rodolphe",
51 "...",
52 ],
53 "surname": ["Ramus", "Großmann", "Grossmann", "Grossman", "Libertarian"],
54 "alternative_names": [
55 "Ramus, Pʹer",
56 "Großmann, Rudolf",
57 "Grossmann, Rudolf",
58 "Grossman, Rudolf",
59 "Grossman, Rodolphe",
60 "Grossmann, Rodolphe",
61 "Libertarian, ...",
62 ],
63 "date_of_birth": ["1882-04-15"],
64 "date_of_death": ["1942"],
65 }
66 # https://d-nb.info/gnd/118833197
67 uri = str(testdata / "ramus.rdf")
69 attributes = rdf.get_something_from_uri(uri)
70 self.assertEqual(pierre["forename"], attributes["forename"])
71 self.assertEqual(pierre["surname"], attributes["surname"])
72 # self.assertEqual(pierre["alternative_names"], attributes["alternative_names"])
73 self.assertEqual(pierre["date_of_birth"], attributes["date_of_birth"])
74 self.assertEqual(pierre["date_of_death"], attributes["date_of_death"])
76 def test_get_definition_from_dict_institution_from_dnb(self):
77 pierre_ges = {
78 "label": [
79 "Pierre-Ramus-Gesellschaft",
80 "Ramus-Gesellschaft",
81 "Pierre Ramus-Gesellschaft",
82 ],
83 }
84 # https://d-nb.info/gnd/415006-5
85 uri = str(testdata / "ramus_gesellschaft.rdf")
87 attributes = rdf.get_something_from_uri(uri)
88 self.assertEqual(pierre_ges["label"], attributes["label"])
90 def test_get_definition_from_dict_institution_from_dnb2(self):
91 oeaw = {
92 "label": [
93 "Akademie der Wissenschaften in Wien",
94 "Academy of Sciences in Vienna",
95 "Akademie der Wissenschaften (Wien)",
96 ],
97 }
98 # https://d-nb.info/gnd/35077-1
99 uri = str(testdata / "oeaw.rdf")
101 attributes = rdf.get_something_from_uri(uri)
102 self.assertEqual(oeaw["label"], attributes["label"])