-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_ledger_DeleteLedgerTemplate.py
294 lines (256 loc) · 8.77 KB
/
test_ledger_DeleteLedgerTemplate.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
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
"""
Copyright BOOSTRY Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
"""
import pytest
from sqlalchemy import select
from app.model.db import (
LedgerDataType,
LedgerDetailsTemplate,
LedgerTemplate,
Token,
TokenType,
TokenVersion,
)
from tests.account_config import config_eth_account
class TestDeleteLedgerTemplate:
# target API endpoint
base_url = "/ledger/{token_address}/template"
###########################################################################
# Normal Case
###########################################################################
# <Normal_1>
@pytest.mark.asyncio
async def test_normal_1(self, async_client, async_db):
user = config_eth_account("user1")
issuer_address = user["address"]
token_address = "0xABCdeF1234567890abcdEf123456789000000000"
# prepare data
_token = Token()
_token.type = TokenType.IBET_STRAIGHT_BOND
_token.tx_hash = ""
_token.issuer_address = issuer_address
_token.token_address = token_address
_token.abi = {}
_token.version = TokenVersion.V_24_09
async_db.add(_token)
_template = LedgerTemplate()
_template.token_address = token_address
_template.issuer_address = issuer_address
_template.token_name = "テスト原簿"
_template.headers = [
{
"key": "aaa",
"value": "bbb",
},
{
"hoge": "aaaa",
"fuga": "bbbb",
},
]
_template.footers = [
{
"key": "aaa",
"value": "bbb",
},
{
"f-hoge": "f-aaaa",
"f-fuga": "f-bbbb",
},
]
async_db.add(_template)
_details_1 = LedgerDetailsTemplate()
_details_1.token_address = token_address
_details_1.token_detail_type = "権利_test_1"
_details_1.headers = [
{
"key": "aaa",
"value": "bbb",
},
{"test1": "a", "test2": "b"},
]
_details_1.footers = [
{
"key": "aaa",
"value": "bbb",
},
{"f-test1": "a", "f-test2": "b"},
]
_details_1.data_type = LedgerDataType.IBET_FIN.value
_details_1.data_source = token_address
async_db.add(_details_1)
_details_2 = LedgerDetailsTemplate()
_details_2.token_address = token_address
_details_2.token_detail_type = "権利_test_2"
_details_2.headers = [
{
"key": "aaa",
"value": "bbb",
},
{"test3": "a", "test4": "b"},
]
_details_2.footers = [
{
"key": "aaa",
"value": "bbb",
},
{"f-test3": "a", "f-test4": "b"},
]
_details_2.data_type = LedgerDataType.DB.value
_details_2.data_source = "data_id_2"
async_db.add(_details_2)
await async_db.commit()
# request target API
resp = await async_client.delete(
self.base_url.format(token_address=token_address),
headers={
"issuer-address": issuer_address,
},
)
# assertion
assert resp.status_code == 200
assert resp.json() is None
_template_list = (await async_db.scalars(select(LedgerTemplate))).all()
assert len(_template_list) == 0
_details_list = (await async_db.scalars(select(LedgerDetailsTemplate))).all()
assert len(_details_list) == 0
###########################################################################
# Error Case
###########################################################################
# <Error_1>
# Parameter Error
@pytest.mark.asyncio
async def test_error_1(self, async_client, async_db):
token_address = "0xABCdeF1234567890abcdEf123456789000000000"
# request target API
resp = await async_client.delete(
self.base_url.format(token_address=token_address),
)
# assertion
assert resp.status_code == 422
assert resp.json() == {
"meta": {"code": 1, "title": "RequestValidationError"},
"detail": [
{
"input": None,
"loc": ["header", "issuer-address"],
"msg": "Field required",
"type": "missing",
}
],
}
# <Error_2>
# Parameter Error(issuer-address)
@pytest.mark.asyncio
async def test_error_2(self, async_client, async_db):
token_address = "0xABCdeF1234567890abcdEf123456789000000000"
# request target API
resp = await async_client.delete(
self.base_url.format(token_address=token_address),
headers={
"issuer-address": "test",
},
)
# assertion
assert resp.status_code == 422
assert resp.json() == {
"meta": {"code": 1, "title": "RequestValidationError"},
"detail": [
{
"input": "test",
"loc": ["header", "issuer-address"],
"msg": "issuer-address is not a valid address",
"type": "value_error",
}
],
}
# <Error_3>
# Token Not Found
@pytest.mark.asyncio
async def test_error_3(self, async_client, async_db):
user = config_eth_account("user1")
issuer_address = user["address"]
token_address = "0xABCdeF1234567890abcdEf123456789000000000"
# request target API
resp = await async_client.delete(
self.base_url.format(token_address=token_address),
headers={
"issuer-address": issuer_address,
},
)
# assertion
assert resp.status_code == 404
assert resp.json() == {
"meta": {"code": 1, "title": "NotFound"},
"detail": "token does not exist",
}
# <Error_4>
# Processing Token
@pytest.mark.asyncio
async def test_error_4(self, async_client, async_db):
user = config_eth_account("user1")
issuer_address = user["address"]
token_address = "0xABCdeF1234567890abcdEf123456789000000000"
# prepare data
_token = Token()
_token.type = TokenType.IBET_STRAIGHT_BOND
_token.tx_hash = ""
_token.issuer_address = issuer_address
_token.token_address = token_address
_token.abi = {}
_token.token_status = 0
_token.version = TokenVersion.V_24_09
async_db.add(_token)
await async_db.commit()
# request target API
resp = await async_client.delete(
self.base_url.format(token_address=token_address),
headers={
"issuer-address": issuer_address,
},
)
# assertion
assert resp.status_code == 400
assert resp.json() == {
"meta": {"code": 1, "title": "InvalidParameterError"},
"detail": "this token is temporarily unavailable",
}
# <Error_5>
# Ledger Template Not Found
@pytest.mark.asyncio
async def test_error_5(self, async_client, async_db):
user = config_eth_account("user1")
issuer_address = user["address"]
token_address = "0xABCdeF1234567890abcdEf123456789000000000"
# prepare data
_token = Token()
_token.type = TokenType.IBET_STRAIGHT_BOND
_token.tx_hash = ""
_token.issuer_address = issuer_address
_token.token_address = token_address
_token.abi = {}
_token.version = TokenVersion.V_24_09
async_db.add(_token)
await async_db.commit()
# request target API
resp = await async_client.delete(
self.base_url.format(token_address=token_address),
headers={
"issuer-address": issuer_address,
},
)
# assertion
assert resp.status_code == 404
assert resp.json() == {
"meta": {"code": 1, "title": "NotFound"},
"detail": "ledger template does not exist",
}