-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
274 lines (216 loc) · 8.18 KB
/
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
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
import unittest
import responses
from hivesigner.client import Client
from hivesigner.operations import *
class TestClient(unittest.TestCase):
def test_get_login_url(self):
c = Client(
"client_id"
"client_secret"
)
self.assertEqual(
c.get_login_url("http://localhost", "login"),
"https://hivesigner.com/oauth2/authorize?client_id"
"=client_idclient_secret&redirect_uri=http%3A%2F%2Flocalh"
"ost&scope=login")
def test_get_login_url_override_defaults(self):
c = Client(
oauth_base_url="http://foo.bar/oauth2/",
client_id="client_id",
client_secret="client_secret"
)
self.assertEqual(
c.get_login_url("http://localhost", "login"),
"http://foo.bar/oauth2/authorize?client_id=client_id&"
"redirect_uri=http%3A%2F%2Flocalhost&scope=login")
@responses.activate
def test_get_access_token(self):
def request_callback(request):
self.assertEqual(
request.url,
"https://hivesigner.com/api/oauth2/token/")
self.assertEqual(
request.body,
'grant_type=authorization_code&code=code&client_id='
'client_id&client_secret=client_secret'
)
return 200, {}, json.dumps({"access_token": "foo"})
c = Client(
client_id="client_id",
client_secret="client_secret"
)
responses.add_callback(
responses.POST,
'https://hivesigner.com/api/oauth2/token/',
callback=request_callback,
)
c.get_access_token("code")
@responses.activate
def test_refresh_access_token(self):
def request_callback(request):
self.assertEqual(
request.url,
"https://hivesigner.com/api/oauth2/token/")
self.assertEqual(
request.body,
'refresh_token=refresh_token&client_id=client_id&'
'client_secret=client_secret&scope=login'
)
return 200, {}, json.dumps({"access_token": "foo"})
c = Client(
client_id="client_id",
client_secret="client_secret"
)
responses.add_callback(
responses.POST,
'https://hivesigner.com/api/oauth2/token/',
callback=request_callback,
)
c.refresh_access_token("refresh_token", "login")
@responses.activate
def test_me(self):
def request_callback(request):
self.assertEqual(
request.url,
"https://hivesigner.com/api/me/")
return 200, {}, json.dumps({"access_token": "foo"})
c = Client(
access_token="foo"
)
responses.add_callback(
responses.POST,
'https://hivesigner.com/api/me/',
callback=request_callback,
)
c.me()
def test_op_upvote(self):
vote = Vote(
"voter", "author", "permlink", 100)
self.assertEqual(vote.voter, "voter")
self.assertEqual(vote.author, "author")
self.assertEqual(vote.permlink, "permlink")
self.assertEqual(vote.weight, 10000)
def test_op_downvote(self):
vote = Vote(
"voter", "author", "permlink", -50)
self.assertEqual(vote.voter, "voter")
self.assertEqual(vote.author, "author")
self.assertEqual(vote.permlink, "permlink")
self.assertEqual(vote.weight, -5000)
def test_comment(self):
comment = Comment(
"author",
"permlink",
"body",
title="title",
json_metadata={"app": "testapp/0.0.1", "tags": ["test"]},
)
self.assertEqual(comment.author, "author")
self.assertEqual(comment.permlink, "permlink")
self.assertEqual(comment.body, "body")
self.assertEqual(comment.title, "title")
self.assertEqual(
comment.json_metadata,
json.dumps({"app": "testapp/0.0.1", "tags": ["test"]}))
def test_comment_options(self):
comment_options = CommentOptions(
"author",
"permlink",
allow_curation_rewards=False,
)
self.assertEqual(comment_options.author, "author")
self.assertEqual(comment_options.permlink, "permlink")
self.assertEqual(
comment_options.allow_curation_rewards, False)
def test_comment_options_comment_injection(self):
comment = Comment(
"author",
"permlink",
"body",
title="title",
json_metadata={"app": "testapp/0.0.1", "tags": ["test"]},
)
comment_options = CommentOptions(
parent_comment=comment,
allow_curation_rewards=False,
)
self.assertEqual(comment_options.author, "author")
self.assertEqual(comment_options.permlink, "permlink")
self.assertEqual(
comment_options.allow_curation_rewards, False)
def test_delete_comment(self):
delete_comment = DeleteComment(
"author", "permlink"
)
self.assertEqual(delete_comment.author, "author")
self.assertEqual(delete_comment.permlink, "permlink")
def test_follow(self):
follow = Follow("follower", "following")
self.assertEqual(follow.follower, "follower")
self.assertEqual(follow.following, "following")
self.assertEqual(follow.what, ["blog",])
def test_unfollow(self):
unfollow = Unfollow("follower", "following")
self.assertEqual(unfollow.follower, "follower")
self.assertEqual(unfollow.following, "following")
self.assertEqual(unfollow.what, [])
def test_mute(self):
ignore = Mute("follower", "following")
self.assertEqual(ignore.follower, "follower")
self.assertEqual(ignore.following, "following")
self.assertEqual(ignore.what, ["ignore"])
def test_reblog(self):
resteem = Reblog("account", "author", "permlink")
self.assertEqual(resteem.account, "account")
self.assertEqual(resteem.author, "author")
self.assertEqual(resteem.permlink, "permlink")
def test_claim_reward_balance(self):
claim_reward_balance = ClaimRewardBalance(
'account', '0.000 HIVE', '1.500 HBD', '1132.996000 VESTS'
)
self.assertEqual(claim_reward_balance.account, "account")
self.assertEqual(claim_reward_balance.reward_hive, "0.000 HIVE")
self.assertEqual(claim_reward_balance.reward_hbd, "1.500 HBD")
self.assertEqual(
claim_reward_balance.reward_vests, "1132.996000 VESTS")
def test_custom_json(self):
custom_json = CustomJson(
[],
["author"],
"testcustomjson",
{"foo": "<i>bar"}
)
self.assertEqual(custom_json.required_auth, [])
self.assertEqual(custom_json.required_posting_auths, ["author"])
self.assertEqual(custom_json.custom_operation_id, "testcustomjson")
self.assertEqual(custom_json.structure, {"foo": "<i>bar"})
def test_hot_sign(self):
c = Client()
sign_url = c.hot_sign(
"transfer",
{
"to": "turbot",
"amount": "0.001 HBD",
"memo": "selam",
},
redirect_uri="http://localhost"
)
self.assertEqual(sign_url, "https://hivesigner.com/sign/tra"
"nsfer?to=turbot&amount=0.001+HBD&me"
"mo=selam&redirect_uri=http%3A%2F%2F"
"localhost")
def test_hot_sign_without_redirect_uri(self):
c = Client()
sign_url = c.hot_sign(
"transfer",
{
"to": "turbot",
"amount": "0.001 HBD",
"memo": "selam",
},
)
self.assertEqual(sign_url, "https://hivesigner.com/sign/tra"
"nsfer?to=turbot&amount=0.001+HBD&me"
"mo=selam")
if __name__ == '__main__':
unittest.main()