本文整理汇总了Python中helper.Helper.get_anonymous_token方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.get_anonymous_token方法的具体用法?Python Helper.get_anonymous_token怎么用?Python Helper.get_anonymous_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper.Helper
的用法示例。
在下文中一共展示了Helper.get_anonymous_token方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid_create
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import get_anonymous_token [as 别名]
def test_valid_create(self):
ws = websocket.create_connection(Helper.really_server)
init_request = {
"tag": 123,
"traceId": "@trace123",
"cmd": "initialize",
"accessToken": Helper.get_anonymous_token()
}
ws.send(json.dumps(init_request))
init_data = ws.recv()
init_result = json.loads(init_data)
self.assertEqual(init_result["evt"], "initialized")
ws.send("""{
"tag" : 123,
"traceId" : "@trace123",
"cmd" : "create",
"r" : "/users/",
"body" : {
"firstName": "Ahmed",
"age": 18
}
}""")
create_data= ws.recv()
create_result = json.loads(create_data)
self.assertEqual(create_result["body"]["firstName"], "Ahmed")
示例2: test_valid_initialize
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import get_anonymous_token [as 别名]
def test_valid_initialize(self):
ws = websocket.create_connection(Helper.really_server)
request = {
"tag": 123,
"traceId": "@trace123",
"cmd": "initialize",
"accessToken": Helper.get_anonymous_token()
}
ws.send(json.dumps(request))
result_data = ws.recv()
ws.close()
result = json.loads(result_data)
self.assertEqual(result["tag"] ,123)
self.assertEqual(result["error"] , None)
self.assertEqual(result["evt"] ,"initialized")
self.assertEqual(result["body"]["authType"] ,"anonymous")
self.assertEqual(result["evt"] ,"initialized")
示例3: test_valid_get
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import get_anonymous_token [as 别名]
def test_valid_get(self):
ws = websocket.create_connection(Helper.really_server)
init_request = {
"tag": 123,
"traceId": "@trace123",
"cmd": "initialize",
"accessToken": Helper.get_anonymous_token()
}
ws.send(json.dumps(init_request))
init_data = ws.recv()
init_result = json.loads(init_data)
self.assertEqual(init_result["evt"], "initialized")
ws.send("""{
"tag" : 123,
"traceId" : "@trace123",
"cmd" : "create",
"r" : "/users/",
"body" : {
"firstName": "Hatem",
"lastName" : "AlSum"
}
}""")
create_data= ws.recv()
create_result = json.loads(create_data)
self.assertEqual(create_result["body"]["firstName"], "Hatem")
get_request = {
"tag": 1,
"cmd": "get",
"cmdOpts": {
"fields": []
},
"r": create_result["r"]
}
ws.send(json.dumps(get_request))
get_data= ws.recv()
ws.close()
get_result = json.loads(get_data)
self.assertEqual(get_result["body"]["firstName"], "Hatem")
self.assertEqual(get_result["body"]["lastName"], "AlSum")
示例4: test_valid_create
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import get_anonymous_token [as 别名]
def test_valid_create(self):
ws = websocket.create_connection(Helper.really_server)
init_request = {
"tag": 123,
"traceId": "@trace123",
"cmd": "initialize",
"accessToken": Helper.get_anonymous_token()
}
ws.send(json.dumps(init_request))
init_data = ws.recv()
init_result = json.loads(init_data)
self.assertEqual(init_result["evt"], "initialized")
ws.send("""{
"tag" : 123,
"traceId" : "@trace123",
"cmd" : "create",
"r" : "/users/",
"body" : {
"firstName": "Hatem",
"lastName" : "AlSum"
}
}""")
create_data= ws.recv()
print("Creation Result {}".format(create_data))
create_result = json.loads(create_data)
self.assertEqual(create_result["body"]["firstName"], "Hatem")
#
# update_request = {
# "tag": 1,
# "cmd": "update",
# "cmdOpts": {
# },
# "r": create_result["r"],
# "rev": 1,
# "body": {
# "ops": [
# {
# "op": "set",
# "key": "firstName",
# "value": "Nadeen"
# }
# ]
# }
# }
# ws.send(json.dumps(update_request))
# update_data= ws.recv()
# print("Update Result {}".format(update_data))
# update_result=json.loads(update_data)
# self.assertEqual(update_result["r"] ,create_result["r"])
# self.assertEqual(update_result["rev"] ,2)
#
# #TODO : sleep should be removed
# time.sleep(5)
subscribe_request = {
"tag": 123,
"cmd": "subscribe",
"body": {
"subscriptions": [
{
"r": str(create_result["r"]),
"rev": 1,
"fields": ["firstName"]
}
]
}
}
print(subscribe_request)
ws.send(json.dumps(subscribe_request))
get_data= ws.recv()
print("subscribe Result {}".format(get_data))
ws.close()
subscribe_result = json.loads(get_data)
self.assertEqual(subscribe_result["body"]["subscriptions"], [ str(create_result["r"])] )
示例5: test_valid_update_one_ops
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import get_anonymous_token [as 别名]
def test_valid_update_one_ops(self):
ws = websocket.create_connection(Helper.really_server)
init_request = {
"tag": 123,
"traceId": "@trace123",
"cmd": "initialize",
"accessToken": Helper.get_anonymous_token()
}
ws.send(json.dumps(init_request))
init_data = ws.recv()
init_result = json.loads(init_data)
self.assertEqual(init_result["evt"], "initialized")
ws.send("""{
"tag" : 123,
"traceId" : "@trace123",
"cmd" : "create",
"r" : "/users/",
"body" : {
"firstName": "Hatem",
"lastName" : "AlSum"
}
}""")
create_data= ws.recv()
create_result = json.loads(create_data)
self.assertEqual(create_result["body"]["firstName"], "Hatem")
update_request = {
"tag": 1,
"cmd": "update",
"cmdOpts": {
},
"r": create_result["r"],
"rev": 1,
"body": {
"ops": [
{
"op": "set",
"key": "firstName",
"value": "Nadeen"
}
]
}
}
ws.send(json.dumps(update_request))
update_data= ws.recv()
update_result=json.loads(update_data)
self.assertEqual(update_result["r"] ,create_result["r"])
self.assertEqual(update_result["rev"] ,2)
#TODO : sleep should be removed
time.sleep(5)
get_request = {
"tag": 1,
"cmd": "get",
"cmdOpts": {
"fields": []
},
"r": create_result["r"]
}
ws.send(json.dumps(get_request))
get_data= ws.recv()
print("Read Result {}".format(get_data))
ws.close()
get_result = json.loads(get_data)
self.assertEqual(get_result["body"]["firstName"], "Nadeen")