marco@16
|
1 from . import TestController
|
marco@16
|
2
|
marco@16
|
3 from sword2 import Entry
|
marco@16
|
4 from sword2.utils import NS
|
marco@16
|
5
|
marco@16
|
6 class TestEntry(TestController):
|
marco@16
|
7 def test_01_blank_init(self):
|
marco@16
|
8 e = Entry()
|
marco@16
|
9 print e.entry.getchildren()
|
marco@16
|
10 assert len(e.entry.getchildren()) == 2 # generator, updated are there by default
|
marco@16
|
11
|
marco@16
|
12 def test_02_init_without_author(self):
|
marco@16
|
13 e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", dcterms_title="foo bar")
|
marco@16
|
14 assert e.entry.find(NS['atom'] % 'title') != None
|
marco@16
|
15 assert e.entry.find(NS['dcterms'] % 'appendix') != None
|
marco@16
|
16 assert e.entry.find(NS['dcterms'] % 'nonexistant_term') == None
|
marco@16
|
17
|
marco@16
|
18 def test_03_init_with_author(self):
|
marco@16
|
19 e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
|
marco@16
|
20 assert e.entry.find(NS['atom'] % 'title') != None
|
marco@16
|
21 assert e.entry.find(NS['atom'] % 'title').text == "Foo"
|
marco@16
|
22 a = e.entry.find(NS['atom'] % 'author')
|
marco@16
|
23 name = a.find(NS['atom'] % 'name')
|
marco@16
|
24 assert name.text == "Ben"
|
marco@16
|
25
|
marco@16
|
26 def test_04_init_add_namespace(self):
|
marco@16
|
27 e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
|
marco@16
|
28 e.register_namespace("mylocal", "info:localnamespace")
|
marco@16
|
29 assert "mylocal" in e.add_ns
|
marco@16
|
30
|
marco@16
|
31 def test_05_init_add_fields(self):
|
marco@16
|
32 e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
|
marco@16
|
33 e.add_field("dcterms_issued", "2009")
|
marco@16
|
34 assert e.entry.find(NS['dcterms'] % 'issued') != None
|
marco@16
|
35 assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
|
marco@16
|
36
|
marco@16
|
37 def test_06_init_add_fields(self):
|
marco@16
|
38 e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
|
marco@16
|
39 e.add_fields(dcterms_issued="2009",
|
marco@16
|
40 updated="2010",
|
marco@16
|
41 dcterms_description="A verbose and new description")
|
marco@16
|
42
|
marco@16
|
43 assert e.entry.find(NS['atom'] % 'updated') != None
|
marco@16
|
44 assert e.entry.find(NS['atom'] % 'updated').text == "2010"
|
marco@16
|
45 assert e.entry.find(NS['dcterms'] % 'issued') != None
|
marco@16
|
46 assert e.entry.find(NS['dcterms'] % 'issued').text == "2009"
|
marco@16
|
47 assert e.entry.find(NS['dcterms'] % 'description') != None
|
marco@16
|
48 assert e.entry.find(NS['dcterms'] % 'description').text == "A verbose and new description"
|
marco@16
|
49
|
marco@16
|
50
|
marco@16
|
51 def test_07_init_add_new_ns_field(self):
|
marco@16
|
52 e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
|
marco@16
|
53 e.register_namespace("mylocal", "info:localnamespace")
|
marco@16
|
54 e.add_field("mylocal_issued", "2003")
|
marco@16
|
55 assert e.entry.find(NS['mylocal'] % 'issued') != None
|
marco@16
|
56 assert e.entry.find(NS['mylocal'] % 'issued').text == "2003"
|
marco@16
|
57
|
marco@16
|
58 def test_08_init_add_new_ns_fields(self):
|
marco@16
|
59 e = Entry(title="Foo", id="asidjasidj", dcterms_appendix="blah blah", author={'name':'Ben', 'email':'foo@bar.com'})
|
marco@16
|
60 e.register_namespace("mylocal", "info:localnamespace")
|
marco@16
|
61 e.add_fields(mylocal_foobar="2009",
|
marco@16
|
62 updated="2010",
|
marco@16
|
63 mylocal_description="A verbose and new description")
|
marco@16
|
64
|
marco@16
|
65 assert e.entry.find(NS['atom'] % 'updated') != None
|
marco@16
|
66 assert e.entry.find(NS['atom'] % 'updated').text == "2010"
|
marco@16
|
67 assert e.entry.find(NS['mylocal'] % 'foobar') != None
|
marco@16
|
68 assert e.entry.find(NS['mylocal'] % 'foobar').text == "2009"
|
marco@16
|
69 assert e.entry.find(NS['mylocal'] % 'description') != None
|
marco@16
|
70 assert e.entry.find(NS['mylocal'] % 'description').text == "A verbose and new description"
|