本文整理汇总了Python中taiga.auth.tokens.get_token_for_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_token_for_user函数的具体用法?Python get_token_for_user怎么用?Python get_token_for_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_token_for_user函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _execute_requests
def _execute_requests(self, reqs):
admin = User.objects.get(username="admin")
user = User.objects.get(id=USER_ID)
user.token = "password-token"
user.email_token = "email-token"
user.new_email = "[email protected]"
user.save()
user_token = get_token_for_user(user, "authentication")
admin_token = get_token_for_user(admin, "authentication")
os.environ["AUTH_TOKEN"] = user_token
os.environ["ADMIN_AUTH_TOKEN"] = admin_token
host = "http://localhost:8000"
for (key, req) in reqs.items():
print("Generate", key)
cmd_path = os.path.join("output", key + "-cmd.adoc")
os.makedirs("output", exist_ok=True)
curl_cmd = self._build_curl_cmd(host, req)
with open(cmd_path, "w") as fd:
fd.write("[source,bash]\n")
fd.write("----\n")
fd.write(curl_cmd.replace("$$INCLUDE_FILE$$", "@"))
fd.write("\n----\n")
if req['method'] == "DELETE":
continue
curl_cmd = curl_cmd.replace("$$INCLUDE_FILE$$", "@{}/".format(os.path.dirname(__file__)))
output_path = os.path.join("output", key + "-output.adoc")
if "response" in req:
response_data = req['response']
else:
result = subprocess.run(curl_cmd + " -f", shell=True, stdout=subprocess.PIPE)
if result.returncode != 0:
result = subprocess.run(curl_cmd, shell=True, stdout=subprocess.PIPE)
print("ERROR on key: ", key)
print(result)
if result.stdout == b'':
response_data = None
else:
response_data = json.loads(result.stdout.decode('utf-8'))
if req.get('index', None) is not None:
response_data = response_data[req['index']]
if not response_data:
continue
with open(output_path, "w") as fd:
fd.write("[source,json]\n")
fd.write("----\n")
json.dump(response_data, fd, sort_keys=True, indent=4)
fd.write("\n----\n")
示例2: test_cancel_self_user_with_valid_token
def test_cancel_self_user_with_valid_token(client):
user = f.UserFactory.create()
url = reverse('users-cancel')
cancel_token = get_token_for_user(user, "cancel_account")
data = {"cancel_token": cancel_token}
client.login(user)
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 204
user = models.User.objects.get(pk=user.id)
assert user.full_name == "Deleted user"
示例3: test_response_200_in_public_registration
def test_response_200_in_public_registration(client, settings):
settings.PUBLIC_REGISTER_ENABLED = True
form = {
"type": "public",
"username": "mmcfly",
"full_name": "martin seamus mcfly",
"email": "[email protected]",
"password": "password",
}
response = client.post(reverse("auth-register"), form)
assert response.status_code == 201
assert response.data["username"] == "mmcfly"
assert response.data["email"] == "[email protected]"
assert response.data["full_name"] == "martin seamus mcfly"
assert len(mail.outbox) == 1
assert mail.outbox[0].subject == "You've been Taigatized!"
user = models.User.objects.get(username="mmcfly")
cancel_token = get_token_for_user(user, "cancel_account")
cancel_url = resolve_front_url("cancel-account", cancel_token)
assert mail.outbox[0].body.index(cancel_url) > 0
示例4: save
def save(self, *args, **kwargs):
get_token_for_user(self, "cancel_account")
super().save(*args, **kwargs)
示例5: test_invalid_token_scope
def test_invalid_token_scope():
user = f.UserFactory.create(email="[email protected]")
token = get_token_for_user(user, "testing_scope")
get_user_for_token(token, "testing_invalid_scope")
示例6: test_invalid_token_expiration
def test_invalid_token_expiration():
user = f.UserFactory.create(email="[email protected]")
token = get_token_for_user(user, "testing_scope")
get_user_for_token(token, "testing_scope", max_age=1)
示例7: test_valid_token
def test_valid_token():
user = f.UserFactory.create(email="[email protected]")
token = get_token_for_user(user, "testing_scope")
user_from_token = get_user_for_token(token, "testing_scope")
assert user.id == user_from_token.id