-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_statement.py
More file actions
138 lines (112 loc) · 5.47 KB
/
test_statement.py
File metadata and controls
138 lines (112 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from . import TestController
from sword2 import Atom_Sword_Statement, Ore_Sword_Statement
from sword2.utils import NS
from datetime import datetime
ATOM_TEST_STATEMENT = """<atom:feed xmlns:sword="http://purl.org/net/sword/terms/"
xmlns:atom="http://www.w3.org/2005/Atom">
<atom:category scheme="http://purl.org/net/sword/terms/state"
term="http://purl.org/net/sword/terms/state/Testing"
label="Testing">
The work has passed through review and is now in the archive
</atom:category>
<atom:entry>
<atom:category scheme="http://purl.org/net/sword/terms/"
term="http://purl.org/net/sword/terms/originalDeposit"
label="Orignal Deposit"/>
<atom:content type="application/zip"
src="http://localhost:8080/part-IRI/43/my_deposit/example.zip"/>
<sword:packaging>http://purl.org/net/sword/package/SimpleZip</sword:packaging>
<sword:depositedOn>2011-03-02T20:50:06Z</sword:depositedOn>
<sword:depositedBy>sword</sword:depositedBy>
<sword:depositedOnBehalfOf>jbloggs</sword:depositedOnBehalfOf>
</atom:entry>
</atom:feed>
"""
ORE_TEST_STATEMENT = """<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ore="http://www.openarchives.org/ore/terms/"
xmlns:sword="http://purl.org/net/sword/terms/">
<rdf:Description rdf:about="http://localhost:8080/edit-IRI/43/my_deposit">
<ore:describes rdf:resource="http://localhost:8080/agg-IRI/43/my_deposit"/>
</rdf:Description>
<rdf:Description rdf:about="http://localhost:8080/agg-IRI/43/my_deposit">
<ore:isDescribedBy rdf:resource="http://localhost:8080/edit-IRI/43/my_deposit"/>
<ore:aggregates rdf:resource="http://localhost:8080/part-IRI/43/my_deposit/example.zip"/>
<sword:originalDeposit rdf:resource="http://localhost:8080/part-IRI/43/my_deposit/example.zip"/>
<sword:state rdf:resource="http://purl.org/net/sword/terms/state/Testing"/>
</rdf:Description>
<rdf:Description rdf:about="http://localhost:8080/part-IRI/43/my_deposit/example.zip">
<sword:packaging rdf:resource="http://purl.org/net/sword/package/SimpleZip"/>
<sword:depositedOn rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">
2011-03-02T20:50:06Z
</sword:depositedOn>
<sword:depositedBy rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
sword
</sword:depositedBy>
<sword:depositedOnBehalfOf>jbloggs</sword:depositedOnBehalfOf>
</rdf:Description>
<rdf:Description rdf:about="http://purl.org/net/sword/terms/state/Testing">
<sword:stateDescription>
The work has passed through review and is now in the archive
</sword:stateDescription>
</rdf:Description>
</rdf:RDF>
"""
class TestStatement(TestController):
def test_01_atom_blank_init(self):
s = Atom_Sword_Statement()
assert len(s.original_deposits) == 0
assert len(s.resources) == 0
assert len(s.states) == 0
assert s.xml_document == None
assert s.dom == None
assert not s.parsed
assert not s.valid
def test_02_atom_init_with_statement(self):
s = Atom_Sword_Statement(ATOM_TEST_STATEMENT)
assert len(s.states) == 1
assert len(s.original_deposits) == 1
assert len(s.resources) == 1
assert s.xml_document != None
assert s.dom != None
assert s.parsed
assert s.valid
uri, description = s.states[0]
assert uri == "http://purl.org/net/sword/terms/state/Testing"
assert description == "The work has passed through review and is now in the archive"
t = datetime.strptime("2011-03-02T20:50:06Z", "%Y-%m-%dT%H:%M:%SZ")
entry = s.resources[0]
assert len(entry.packaging) == 1
assert entry.deposited_by == "sword"
assert entry.deposited_on_behalf_of == "jbloggs"
assert entry.deposited_on == t
assert entry.uri == "http://localhost:8080/part-IRI/43/my_deposit/example.zip"
assert entry.packaging[0] == "http://purl.org/net/sword/package/SimpleZip"
def test_03_ore_blank_init(self):
s = Ore_Sword_Statement()
assert len(s.original_deposits) == 0
assert len(s.resources) == 0
assert len(s.states) == 0
assert s.xml_document == None
assert s.dom == None
assert not s.parsed
assert not s.valid
def test_04_ore_init_with_statement(self):
s = Ore_Sword_Statement(ORE_TEST_STATEMENT)
assert len(s.states) == 1
assert len(s.original_deposits) == 1
assert len(s.resources) == 1
assert s.xml_document != None
assert s.dom != None
assert s.parsed
assert s.valid
uri, description = s.states[0]
assert uri == "http://purl.org/net/sword/terms/state/Testing"
assert description == "The work has passed through review and is now in the archive"
t = datetime.strptime("2011-03-02T20:50:06Z", "%Y-%m-%dT%H:%M:%SZ")
entry = s.resources[0]
assert len(entry.packaging) == 1
assert entry.deposited_by == "sword"
assert entry.deposited_on_behalf_of == "jbloggs"
assert entry.deposited_on == t
assert entry.uri == "http://localhost:8080/part-IRI/43/my_deposit/example.zip"
assert entry.packaging[0] == "http://purl.org/net/sword/package/SimpleZip"