Coverage for apis_core/utils/test_rdf.py: 100%

45 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:51 +0000

1# SPDX-FileCopyrightText: 2023 Birger Schacht 

2# SPDX-License-Identifier: MIT 

3 

4from pathlib import Path 

5 

6from django.test import TestCase 

7 

8from apis_core.apis_entities.abc import E21_Person, E53_Place, E74_Group 

9from apis_core.utils import rdf 

10 

11# use `curl -H "Accept: application/rdf+xml" -L $URI` to fetch data 

12 

13testdata = Path(__file__).parent / "testdata" 

14 

15 

16class Place(E53_Place): 

17 class Meta: 

18 app_label = "test" 

19 

20 

21class Person(E21_Person): 

22 class Meta: 

23 app_label = "test" 

24 

25 

26class Institution(E74_Group): 

27 class Meta: 

28 app_label = "test" 

29 

30 

31class RdfTest(TestCase): 

32 def test_get_definition_from_dict_place_from_geonames(self): 

33 achensee = { 

34 "latitude": "47.5", 

35 "longitude": "11.7", 

36 "label": "Achensee", 

37 } 

38 # https://www.geonames.org/2783029/achensee.html 

39 uri = str(testdata / "achensee.rdf") 

40 

41 place = Place() 

42 defintion, attributes = rdf.get_definition_and_attributes_from_uri(uri, place) 

43 self.assertEqual(achensee, attributes) 

44 

45 def test_get_definition_from_dict_place_from_dnb(self): 

46 wien = {"label": "Wien", "latitude": "048.208199", "longitude": "016.371690"} 

47 # https://d-nb.info/gnd/4066009-6 

48 uri = str(testdata / "wien.rdf") 

49 

50 place = Place() 

51 defintion, attributes = rdf.get_definition_and_attributes_from_uri(uri, place) 

52 self.assertEqual(wien, attributes) 

53 

54 def test_get_definition_from_dict_person_from_dnb(self): 

55 pierre = { 

56 "forename": "Pierre", 

57 "surname": "Ramus", 

58 "date_of_birth": "1882-04-15", 

59 "date_of_death": "1942", 

60 } 

61 # https://d-nb.info/gnd/118833197 

62 uri = str(testdata / "ramus.rdf") 

63 

64 person = Person() 

65 defintion, attributes = rdf.get_definition_and_attributes_from_uri(uri, person) 

66 self.assertEqual(pierre, attributes) 

67 

68 def test_get_definition_from_dict_institution_from_dnb(self): 

69 pierre_ges = { 

70 "label": "Pierre-Ramus-Gesellschaft", 

71 } 

72 # https://d-nb.info/gnd/415006-5 

73 uri = str(testdata / "ramus_gesellschaft.rdf") 

74 

75 institution = Institution() 

76 defintion, attributes = rdf.get_definition_and_attributes_from_uri( 

77 uri, institution 

78 ) 

79 self.assertEqual(pierre_ges, attributes) 

80 

81 def test_get_definition_from_dict_institution_from_dnb2(self): 

82 pierre_ges = { 

83 "label": "Akademie der Wissenschaften in Wien", 

84 } 

85 # https://d-nb.info/gnd/35077-1 

86 uri = str(testdata / "oeaw.rdf") 

87 

88 institution = Institution() 

89 defintion, attributes = rdf.get_definition_and_attributes_from_uri( 

90 uri, institution 

91 ) 

92 self.assertEqual(pierre_ges, attributes)