-
Notifications
You must be signed in to change notification settings - Fork 3
/
transaction_tests.py
109 lines (87 loc) · 4.63 KB
/
transaction_tests.py
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
#!/bin/env python
import TestConstants
from abstract_fedora_tests import FedoraTests, register_tests, Test
import json
import pyjq
@register_tests
class FedoraTransactionTests(FedoraTests):
# Create test objects all inside here for easy of review
CONTAINER = "/test_transaction"
def get_transaction_provider(self):
headers = {
'Accept': TestConstants.JSONLD_MIMETYPE
}
r = self.do_get(self.getFedoraBase(), headers=headers)
self.assertEqual(200, r.status_code, "Did not get expected response")
body = r.content.decode('UTF-8')
json_body = json.loads(body)
tx_provider = pyjq.first('.[]."http://fedora.info/definitions/v4/repository#hasTransactionProvider" | .[]."@id"',
json_body)
return tx_provider
@Test
def doCommitTest(self):
self.log("Running doCommitTest")
tx_provider = self.get_transaction_provider()
if tx_provider is None:
self.log("Could not location transaction provider")
self.log("Skipping test")
else:
self.log("Create a transaction")
r = self.do_post(tx_provider)
self.assertEqual(201, r.status_code, "Did not get expected response code")
full_transaction_uri = self.get_location(r)
transaction = full_transaction_uri.replace(self.getFedoraBase(), "")
self.log("Transaction is {0}".format(transaction))
self.log("Get status of transaction")
r = self.do_get(full_transaction_uri)
self.assertEqual(200, r.status_code, "Did not get expected response code")
self.log("Create an container in the transaction")
r = self.do_post(full_transaction_uri + self.CONTAINER)
self.assertEqual(201, r.status_code, "Did not get expected response code")
transaction_obj = self.get_location(r)
self.log("Container is available inside the transaction")
r = self.do_get(transaction_obj)
self.assertEqual(200, r.status_code, "Did not get expected response code")
self.log("Container not available outside the transaction")
outside_location = transaction_obj.replace(transaction, "")
r = self.do_get(outside_location)
self.assertEqual(404, r.status_code, "Did not get expected response code")
self.log("Commit transaction")
r = self.do_post(full_transaction_uri + "/fcr:tx/fcr:commit")
self.assertEqual(204, r.status_code, "Did not get expected response code")
self.log("Container is now available outside the transaction")
r = self.do_get(outside_location)
self.assertEqual(200, r.status_code, "Did not get expected response code")
self.log("Passed")
@Test
def doRollbackTest(self):
self.log("Running doRollbackTest")
tx_provider = self.get_transaction_provider()
if tx_provider is None:
self.log("Could not location transaction provider")
self.log("Skipping test")
else:
self.log("Create a transaction")
r = self.do_post(tx_provider)
self.assertEqual(201, r.status_code, "Did not get expected response code")
full_transaction_uri = self.get_location(r)
transaction = full_transaction_uri.replace(self.getFedoraBase(), "")
self.log("Transaction is {0}".format(transaction))
self.log("Create an container in the transaction")
r = self.do_post(full_transaction_uri + self.CONTAINER)
self.assertEqual(201, r.status_code, "Did not get expected response code")
transaction_obj = self.get_location(r)
self.log("Container is available inside the transaction")
r = self.do_get(transaction_obj)
self.assertEqual(200, r.status_code, "Did not get expected response code")
self.log("Container not available outside the transaction")
outside_location = transaction_obj.replace(transaction, "")
r = self.do_get(outside_location)
self.assertEqual(404, r.status_code, "Did not get expected response code")
self.log("Rollback transaction")
r = self.do_post(full_transaction_uri + "/fcr:tx/fcr:rollback")
self.assertEqual(204, r.status_code, "Did not get expected response code")
self.log("Container is still not available outside the transaction")
r = self.do_get(outside_location)
self.assertEqual(404, r.status_code, "Did not get expected response code")
self.log("Passed")