|
1 | 1 | from . import TestController |
2 | | -from sword2 import Connection, Entry |
| 2 | +from sword2 import Connection, Entry, Error_Document |
3 | 3 |
|
4 | 4 | PACKAGE = "tests/spec/example.zip" |
5 | 5 | PACKAGE_MIME = "application/zip" |
@@ -193,8 +193,94 @@ def test_10_advanced_retrieve_deposit_receipt(self): |
193 | 193 | assert new_receipt.parsed == True |
194 | 194 | assert new_receipt.valid == True |
195 | 195 |
|
196 | | - |
197 | | - |
| 196 | + def test_11_basic_retrieve_content_cont_iri(self): |
| 197 | + conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) |
| 198 | + conn.get_service_document() |
| 199 | + col = conn.sd.workspaces[0][1][0] |
| 200 | + with open(PACKAGE) as pkg: |
| 201 | + receipt = conn.create(col_iri = col.href, |
| 202 | + payload=pkg, |
| 203 | + mimetype=PACKAGE_MIME, |
| 204 | + filename="example.zip", |
| 205 | + packaging='http://purl.org/net/sword/package/SimpleZip') |
| 206 | + # ensure that we have a receipt (the server may not give us one |
| 207 | + # by default) |
| 208 | + receipt = conn.get_deposit_receipt(receipt.location) |
| 209 | + |
| 210 | + # we're going to work with the cont_iri |
| 211 | + assert receipt.cont_iri is not None |
| 212 | + |
| 213 | + resource = conn.get_resource(content_iri=receipt.cont_iri) |
| 214 | + |
| 215 | + assert resource.code == 200 |
| 216 | + assert resource.content is not None |
| 217 | + |
| 218 | + def test_12_basic_retrieve_content_em_iri(self): |
| 219 | + conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) |
| 220 | + conn.get_service_document() |
| 221 | + col = conn.sd.workspaces[0][1][0] |
| 222 | + with open(PACKAGE) as pkg: |
| 223 | + receipt = conn.create(col_iri = col.href, |
| 224 | + payload=pkg, |
| 225 | + mimetype=PACKAGE_MIME, |
| 226 | + filename="example.zip", |
| 227 | + packaging='http://purl.org/net/sword/package/SimpleZip') |
| 228 | + # ensure that we have a receipt (the server may not give us one |
| 229 | + # by default) |
| 230 | + receipt = conn.get_deposit_receipt(receipt.location) |
| 231 | + |
| 232 | + # we're going to work with the cont_iri |
| 233 | + assert receipt.edit_media is not None |
| 234 | + |
| 235 | + resource = conn.get_resource(content_iri=receipt.edit_media) |
| 236 | + |
| 237 | + assert resource.code == 200 |
| 238 | + assert resource.content is not None |
| 239 | + |
| 240 | + def test_13_advanced_retrieve_content_em_iri(self): |
| 241 | + conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW) |
| 242 | + conn.get_service_document() |
| 243 | + col = conn.sd.workspaces[0][1][0] |
| 244 | + with open(PACKAGE) as pkg: |
| 245 | + receipt = conn.create(col_iri = col.href, |
| 246 | + payload=pkg, |
| 247 | + mimetype=PACKAGE_MIME, |
| 248 | + filename="example.zip", |
| 249 | + packaging='http://purl.org/net/sword/package/SimpleZip') |
| 250 | + # ensure that we have a receipt (the server may not give us one |
| 251 | + # by default) |
| 252 | + receipt = conn.get_deposit_receipt(receipt.location) |
| 253 | + |
| 254 | + packaging = 'http://purl.org/net/sword/package/SimpleZip' |
| 255 | + if receipt.packaging is not None and len(receipt.packaging) > 0: |
| 256 | + packaging = receipt.packaging[0] |
| 257 | + |
| 258 | + resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO) |
| 259 | + |
| 260 | + assert resource.code == 200 |
| 261 | + assert resource.content is not None |
| 262 | + |
| 263 | + def test_14_error_retrieve_content_em_iri(self): |
| 264 | + conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, |
| 265 | + error_response_raises_exceptions=False) |
| 266 | + conn.get_service_document() |
| 267 | + col = conn.sd.workspaces[0][1][0] |
| 268 | + with open(PACKAGE) as pkg: |
| 269 | + receipt = conn.create(col_iri = col.href, |
| 270 | + payload=pkg, |
| 271 | + mimetype=PACKAGE_MIME, |
| 272 | + filename="example.zip", |
| 273 | + packaging='http://purl.org/net/sword/package/SimpleZip') |
| 274 | + # ensure that we have a receipt (the server may not give us one |
| 275 | + # by default) |
| 276 | + receipt = conn.get_deposit_receipt(receipt.location) |
| 277 | + |
| 278 | + error = 'http://purl.org/net/sword/package/IJustMadeThisUp' |
| 279 | + response = conn.get_resource(content_iri=receipt.edit_media, packaging=error) |
| 280 | + |
| 281 | + assert response.code == 406 |
| 282 | + assert isinstance(response, Error_Document) |
| 283 | + |
198 | 284 |
|
199 | 285 |
|
200 | 286 |
|
|
0 commit comments