forked from swordapp/python-client-sword2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_spec.py
More file actions
941 lines (748 loc) · 41.5 KB
/
Copy pathtest_spec.py
File metadata and controls
941 lines (748 loc) · 41.5 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
from lxml import etree
from . import TestController
from sword2 import Connection, Entry, Error_Document, Atom_Sword_Statement, Ore_Sword_Statement
PACKAGE = "tests/spec/example.zip"
PACKAGE_MIME = "application/zip"
SSS_URL = "http://localhost:8080/sd-uri"
SSS_UN = "sword"
SSS_PW = "sword"
SSS_OBO = "obo"
# Note, there are tests in here which use On-Behalf-Of, so those tests will
# fail if the server does not support mediation.
class TestConnection(TestController):
def test_01_get_service_document(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
# given that the client is fully functional, testing that the
# service document parses and is valid is sufficient. This, obviously,
# doesn't test the validation routine itself.
assert conn.sd != None
assert conn.sd.parsed == True
assert conn.sd.valid == True
assert len(conn.sd.workspaces) == 1
def test_02_get_service_document_on_behalf_of(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
# given that the client is fully functional, testing that the
# service document parses and is valid is sufficient. This, obviously,
# doesn't test the validation routine itself.
assert conn.sd != None
assert conn.sd.parsed == True
assert conn.sd.valid == True
assert len(conn.sd.workspaces) == 1
def test_03_basic_create_resource_with_package(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
assert receipt.code == 201
assert receipt.location != None
# these last two assertions are contingent on if we actually get a
# receipt back from the server (which we might not legitimately get)
assert receipt.dom is None or receipt.parsed == True
assert receipt.dom is None or receipt.valid == True
def test_04_advanced_create_resource_with_package(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress = True,
suggested_identifier = "abcdefghijklmnop")
assert receipt.code == 201
assert receipt.location != None
# these last two assertions are contingent on if we actually get a
# receipt back from the server (which we might not legitimately get)
assert receipt.dom is None or receipt.parsed == True
assert receipt.dom is None or receipt.valid == True
def test_05_basic_create_resource_with_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
assert receipt.code == 201
assert receipt.location != None
# these last two assertions are contingent on if we actually get a
# receipt back from the server (which we might not legitimately get)
assert receipt.dom is None or receipt.parsed == True
assert receipt.dom is None or receipt.valid == True
def test_06_advanced_create_resource_with_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress = True,
suggested_identifier = "zyxwvutsrq")
assert receipt.code == 201
assert receipt.location != None
# these last two assertions are contingent on if we actually get a
# receipt back from the server (which we might not legitimately get)
assert receipt.dom is None or receipt.parsed == True
assert receipt.dom is None or receipt.valid == True
def test_07_basic_create_resource_with_entry(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
receipt = conn.create(col_iri = col.href,
metadata_entry = e)
assert receipt.code == 201
assert receipt.location != None
# these last two assertions are contingent on if we actually get a
# receipt back from the server (which we might not legitimately get)
assert receipt.dom is None or receipt.parsed == True
assert receipt.dom is None or receipt.valid == True
def test_08_advanced_create_resource_with_entry(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
in_progress = True,
suggested_identifier = "1234567890")
assert receipt.code == 201
assert receipt.location != None
# these last two assertions are contingent on if we actually get a
# receipt back from the server (which we might not legitimately get)
assert receipt.dom is None or receipt.parsed == True
assert receipt.dom is None or receipt.valid == True
def test_09_basic_retrieve_deposit_receipt(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
# we're going to work with the location
assert receipt.location != None
new_receipt = conn.get_deposit_receipt(receipt.location)
assert new_receipt.code == 200
assert new_receipt.parsed == True
assert new_receipt.valid == True
def test_10_advanced_retrieve_deposit_receipt(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress = True,
suggested_identifier = "0987654321")
# we're going to work with the location
assert receipt.location != None
new_receipt = conn.get_deposit_receipt(receipt.location)
assert new_receipt.code == 200
assert new_receipt.parsed == True
assert new_receipt.valid == True
def test_11_basic_retrieve_content_cont_iri(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# we're going to work with the cont_iri
assert receipt.cont_iri is not None
resource = conn.get_resource(content_iri=receipt.cont_iri)
assert resource.code == 200
assert resource.content is not None
def test_12_basic_retrieve_content_em_iri(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# we're going to work with the edit_media iri
assert receipt.edit_media is not None
resource = conn.get_resource(content_iri=receipt.edit_media)
assert resource.code == 200
assert resource.content is not None
def test_13_advanced_retrieve_content_em_iri(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
packaging = 'http://purl.org/net/sword/package/SimpleZip'
if receipt.packaging is not None and len(receipt.packaging) > 0:
packaging = receipt.packaging[0]
resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO)
assert resource.code == 200
assert resource.content is not None
def test_14_error_retrieve_content_em_iri(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
honour_receipts=False, error_response_raises_exceptions=False)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
error = 'http://purl.org/net/sword/package/IJustMadeThisUp'
response = conn.get_resource(content_iri=receipt.edit_media, packaging=error)
assert response.code == 406
assert isinstance(response, Error_Document)
assert response.error_href == "http://purl.org/net/sword/error/ErrorContent"
def test_15_retrieve_content_em_iri_as_feed(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# we're going to work with the edit_media_feed iri
assert receipt.edit_media_feed is not None
response = conn.get_resource(content_iri=receipt.edit_media_feed)
assert response.code == 200
assert response.content is not None
# the response should be an xml document, so let's see if we can parse
# it. This should give us an exception which will fail the test if not
dom = etree.fromstring(response.content)
def test_16_basic_replace_file_content(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# now do the replace
with open(PACKAGE) as pkg:
new_receipt = conn.update(dr = receipt,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="update.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
assert new_receipt.code == 204
assert new_receipt.dom is None
def test_17_advanced_replace_file_content(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging='http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# now do the replace
with open(PACKAGE) as pkg:
new_receipt = conn.update(dr = receipt,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="update.zip",
packaging='http://purl.org/net/sword/package/SimpleZip',
metadata_relevant=True)
assert new_receipt.code == 204
assert new_receipt.dom is None
def test_18_basic_replace_metadata(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
receipt = conn.create(col_iri = col.href, metadata_entry = e, in_progress=True)
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# now do the replace
ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
new_receipt = conn.update(dr=receipt, metadata_entry=ne)
assert new_receipt.code == 204 or new_receipt.code == 200
if new_receipt.code == 204:
assert new_receipt.dom is None
if new_receipt.code == 200:
assert new_receipt.parsed == True
assert new_receipt.valid == True
def test_19_advanced_replace_metadata(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
receipt = conn.create(col_iri = col.href, metadata_entry = e)
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# now do the replace
ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
new_receipt = conn.update(dr=receipt, metadata_entry=ne, in_progress=True)
assert new_receipt.code == 204 or new_receipt.code == 200
if new_receipt.code == 204:
assert new_receipt.dom is None
if new_receipt.code == 200:
assert new_receipt.parsed == True
assert new_receipt.valid == True
def test_20_basic_replace_with_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# now do the replace
ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
with open(PACKAGE) as pkg:
new_receipt = conn.update(dr = receipt,
metadata_entry = ne,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="update.zip",
packaging='http://purl.org/net/sword/package/SimpleZip')
assert new_receipt.code == 204 or new_receipt.code == 200
if new_receipt.code == 204:
assert new_receipt.dom is None
if new_receipt.code == 200:
assert new_receipt.parsed == True
assert new_receipt.valid == True
def test_21_advanced_replace_with_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# now do the replace
ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
with open(PACKAGE) as pkg:
new_receipt = conn.update(dr = receipt,
metadata_entry = ne,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="update.zip",
packaging='http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
assert new_receipt.code == 204 or new_receipt.code == 200
if new_receipt.code == 204:
assert new_receipt.dom is None
if new_receipt.code == 200:
assert new_receipt.parsed == True
assert new_receipt.valid == True
def test_22_delete_content(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
# e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
# metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
# now delete the content but not the container
new_receipt = conn.delete_content_of_resource(dr=receipt)
assert new_receipt.code == 204
assert new_receipt.dom is None
def test_23_basic_add_content_to_resource_single_file(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
receipt = conn.get_deposit_receipt(receipt.location)
with open(PACKAGE) as pkg:
new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME)
assert new_receipt.code >= 200 and new_receipt.code < 400
assert new_receipt.location is not None
assert new_receipt.location != receipt.edit_media
def test_24_advanced_add_content_to_resource_single_file(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
receipt = conn.get_deposit_receipt(receipt.location)
with open(PACKAGE) as pkg:
new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
mimetype=PACKAGE_MIME,
metadata_relevant=True)
assert new_receipt.code >= 200 and new_receipt.code < 400
assert new_receipt.location is not None
assert new_receipt.location != receipt.edit_media
def test_25_basic_add_content_to_resource_package(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
receipt = conn.get_deposit_receipt(receipt.location)
with open(PACKAGE) as pkg:
new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
mimetype=PACKAGE_MIME,
packaging="http://purl.org/net/sword/package/SimpleZip")
assert new_receipt.code >= 200 and new_receipt.code < 400
assert new_receipt.location is not None
assert new_receipt.location == receipt.edit_media
def test_26_advanced_add_content_to_resource_package(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
receipt = conn.get_deposit_receipt(receipt.location)
with open(PACKAGE) as pkg:
new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
mimetype=PACKAGE_MIME,
packaging="http://purl.org/net/sword/package/SimpleZip",
metadata_relevant=True)
assert new_receipt.code >= 200 and new_receipt.code < 400
assert new_receipt.location is not None
assert new_receipt.location == receipt.edit_media
def test_27_basic_add_metadata(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
#with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
#payload=pkg,
#mimetype=PACKAGE_MIME,
#filename="example.zip",
#packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
dcterms_creator="Me!", dcterms_rights="CC0")
new_receipt = conn.append(dr=receipt, metadata_entry=ne)
assert new_receipt.code == 200
def test_28_advanced_add_metadata(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
#payload=pkg,
#mimetype=PACKAGE_MIME,
#filename="example.zip",
#packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
dcterms_creator="Me!", dcterms_rights="CC0")
new_receipt = conn.append(dr=receipt, metadata_entry=ne, in_progress=True)
assert new_receipt.code == 200
def test_29_basic_add_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
dcterms_creator="Me!", dcterms_rights="CC0")
with open(PACKAGE) as pkg:
new_receipt = conn.append(dr=receipt,
metadata_entry=ne,
payload=pkg,
filename="addition.zip",
mimetype=PACKAGE_MIME,
packaging="http://purl.org/net/sword/package/SimpleZip")
assert new_receipt.code >= 200 and new_receipt.code < 400
def test_30_advanced_add_multipart(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
receipt = conn.get_deposit_receipt(receipt.location)
ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
dcterms_creator="Me!", dcterms_rights="CC0")
with open(PACKAGE) as pkg:
new_receipt = conn.append(dr=receipt,
metadata_entry=ne,
payload=pkg,
filename="addition.zip",
mimetype=PACKAGE_MIME,
packaging="http://purl.org/net/sword/package/SimpleZip",
in_progress=True,
metadata_relevant=True)
assert new_receipt.code >= 200 and new_receipt.code < 400
# FIXME: this test just does not work, for no discernable reason. The
# final assert of a 404 fails, and the debug output of the client says
# that the server responded with a 200. Nonetheless, the server logs show
# that it responded with a 404, which would suggest a caching issue in the
# client. I have so far been unable to figure out where, though, despite
# having tried turning off httplib2 caching and passing cache-control
# headers in as per the httplib2 documentation. help?
def test_31_delete_container(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO,
error_response_raises_exceptions=False)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
#with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
metadata_entry = e,
#payload=pkg,
#mimetype=PACKAGE_MIME,
#filename="example.zip",
#packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress=True)
# ensure that we have a receipt (the server may not give us one
# by default)
edit_iri = receipt.location
receipt = conn.get_deposit_receipt(edit_iri)
# delete the container
new_receipt = conn.delete_container(dr=receipt)
assert new_receipt.code == 204
assert new_receipt.dom is None
# the next check is that this 404s appropriately now
another_receipt = conn.get_deposit_receipt(edit_iri)
# FIXME: this is the broken assert
assert another_receipt.code == 404, another_receipt.code
def test_32_get_atom_statement(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
# metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
edit_iri = receipt.location
receipt = conn.get_deposit_receipt(edit_iri)
assert receipt.atom_statement_iri is not None
# get the statement
statement = conn.get_atom_sword_statement(receipt.atom_statement_iri)
assert isinstance(statement, Atom_Sword_Statement)
def test_33_get_ore_statement(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
# metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip')
# ensure that we have a receipt (the server may not give us one
# by default)
edit_iri = receipt.location
receipt = conn.get_deposit_receipt(edit_iri)
assert receipt.ore_statement_iri is not None
# get the statement
statement = conn.get_ore_sword_statement(receipt.ore_statement_iri)
assert isinstance(statement, Ore_Sword_Statement)
def test_34_complete_deposit(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
# metadata_entry = e,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress = True,
suggested_identifier = "zyxwvutsrq")
# ensure that we have a receipt (the server may not give us one
# by default)
edit_iri = receipt.location
receipt = conn.get_deposit_receipt(edit_iri)
response = conn.complete_deposit(dr=receipt)
assert response.code == 200
def test_35_error_checksum_mismatch(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
error_response_raises_exceptions=False)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress = True,
suggested_identifier = "zyxwvutsrq",
md5sum="123456789")
assert receipt.code == 412
assert isinstance(receipt, Error_Document)
assert receipt.error_href == "http://purl.org/net/sword/error/ErrorChecksumMismatch"
def test_36_error_bad_request(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
error_response_raises_exceptions=False)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress = "Invalid", # the API seems to allow this!
suggested_identifier = "zyxwvutsrq")
assert receipt.code == 400
assert isinstance(receipt, Error_Document)
assert receipt.error_href == "http://purl.org/net/sword/error/ErrorBadRequest"
def test_37_error_target_owner_unknown(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
error_response_raises_exceptions=False)
conn.get_service_document()
col = conn.sd.workspaces[0][1][0]
with open(PACKAGE) as pkg:
receipt = conn.create(col_iri = col.href,
payload=pkg,
mimetype=PACKAGE_MIME,
filename="example.zip",
packaging = 'http://purl.org/net/sword/package/SimpleZip',
in_progress = True,
suggested_identifier = "zyxwvutsrq",
on_behalf_of="richard") # we expressly set the wrong obo on the request rather than the connection
assert receipt.code == 403
assert isinstance(receipt, Error_Document)
assert receipt.error_href == "http://purl.org/net/sword/error/TargetOwnerUnknown"
def test_38_error_mediation_not_allowed(self):
# this is a placeholder; it's not possible to reliably test for this
pass
def test_39_error_method_not_allowed(self):
# this is a placeholder; it's not possible to reliably test for this
pass
def test_40_error_max_upload_size_exceeded(self):
# this is a placeholder; it's not possible to reliably test for this
pass
def test_41_get_service_document_unauthorised(self):
conn = Connection(SSS_URL, user_name="alsdkfjsdz", user_pass="ZAKJKLASJDF")
conn.get_service_document()
assert conn.sd is None