Added DCMeta - EAV based application to represent document meta-data. Started to...
[redakcja.git] / apps / dcmeta / tests.py
1 # -*- coding: utf-8
2 from django.test import TestCase
3 from dcmeta.models import Description
4
5 class ImportTests(TestCase):
6
7     def test_basic_rdf(self):
8         d = Description.import_rdf("""<?xml version="1.0"?>
9 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
10          xmlns:dc="http://purl.org/dc/elements/1.1/">
11   <rdf:Description rdf:about="http://wolnelektury.pl/document/test">
12     <dc:title>Simple test resource</dc:title>    
13   </rdf:Description>
14 </rdf:RDF>""")
15         self.assertEqual(d.attrs.count(), 1)
16         self.assertEqual(d['http://purl.org/dc/elements/1.1/', 'title'], u"Simple test resource")
17
18         # refetch the object
19         d = Description.objects.get(about_uri="http://wolnelektury.pl/document/test")
20
21         self.assertEqual(d.attrs.count(), 1)
22         self.assertEqual(d['http://purl.org/dc/elements/1.1/', 'title'], u"Simple test resource")
23
24         # access by prefix
25         self.assertEqual(d['dc', 'title'], u"Simple test resource")
26
27     def test_very_long_dc_property(self):
28         NAME = "very_long_prop_name.with_dots.and.other_stuff_longer_then_50_chars"
29         d = Description.import_rdf("""<?xml version="1.0"?>
30 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
31          xmlns:dc="http://purl.org/dc/elements/1.1/">
32   <rdf:Description rdf:about="http://wolnelektury.pl/document/test">
33     <dc:{0}>Simple test resource</dc:{0}>    
34   </rdf:Description>
35 </rdf:RDF>""".format(NAME))
36
37         self.assertEqual(d.attrs.count(), 1)
38         self.assertEqual(d['dc', NAME], u"Simple test resource")
39
40     def test_namespace_descriptors(self):
41         d = Description.import_rdf("""<?xml version="1.0"?>
42 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
43          xmlns:dc="http://purl.org/dc/elements/1.1/"
44          xmlns:marcrel="http://www.loc.gov/loc.terms/relators/">
45   <rdf:Description rdf:about="http://wolnelektury.pl/document/test">
46     <dc:title>Albatros</dc:title>    
47     <marcrel:trl>Lange, Antoni</marcrel:trl>
48     <marcrel:edt>Sekuła, Aleksandra</marcrel:edt>    
49   </rdf:Description>
50 </rdf:RDF>""")
51
52         self.assertEqual(d.dublincore.title, u"Albatros")
53         self.assertEqual(list(d.marcrel), [
54             ('trl', u"Lange, Antoni"), ('edt', u"Sekuła, Aleksandra"),
55         ])
56
57     def test_multiple_properties(self):
58         d = Description.import_rdf("""<?xml version="1.0"?>
59 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
60          xmlns:dc="http://purl.org/dc/elements/1.1/"
61          xmlns:marcrel="http://www.loc.gov/loc.terms/relators/">
62   <rdf:Description rdf:about="http://wolnelektury.pl/document/test">
63     <dc:title>Albatros</dc:title>    
64     <marcrel:trl>Lange, Antoni</marcrel:trl>
65     <marcrel:edt>Sekuła, Aleksandra</marcrel:edt>
66     <marcrel:edt>Niedziałkowska, Marta</marcrel:edt>
67     <marcrel:edt>Dąbek, Katarzyna</marcrel:edt>
68   </rdf:Description>
69 </rdf:RDF>""")
70
71         self.assertEqual(d['dc', 'title'], u"Albatros")
72         self.assertEqual(d['marcrel', 'trl'], u"Lange, Antoni")
73         self.assertEqual(d['marcrel', 'edt'], [
74                 u"Sekuła, Aleksandra",
75                 u"Niedziałkowska, Marta",
76                 u"Dąbek, Katarzyna",
77         ])