2 Star 3 Fork 0

disenQF/django2102_auth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_api.py 3.95 KB
一键复制 编辑 原始数据 按行查看 历史
import base64
import requests
from unittest import TestCase
from urllib.parse import urljoin
# resp = requests.get('api/users/1/')
# print(resp.text)
base_url = 'http://localhost:8000'
def url(path):
return urljoin(base_url, path)
class LoginUserCase(TestCase):
def test_get_loginuser(self):
# auth 指定当前请求的身份信息
# 格式: (username, password) 用户名必须是auth_user表。
resp = requests.get(url('/api/users/'), auth=('admin', 'admin123'))
print(resp.json())
def test_post(self):
resp = requests.post(base_url+"/api/users/", json={'phone': '90991919919','pwd':'123'})
print(resp.json())
def test_get_cates(self):
resp = requests.get(url('/cates/'))
print(resp.json())
def test_post_cates_icon(self):
with open(r'd:\TV.png', 'rb') as f:
resp = requests.post(url('/cates/'),
data={'name':'华为电视ABC', 'ord_nm': 2, 'parent_id': 999},
files={'icon': f})
print(resp.text)
def test_post_cates(self):
resp_ = requests.get(url('/cates/'))
print('get->', resp_.json())
resp = requests.post(url('/cates/'),
data={'name':'华为平板', 'ord_nm': 3, 'parent_id': 2},
auth=('admin', 'admin123'))
print('post->', resp.json())
def test_sysuser_login(self):
resp = requests.post(url('/syslogin/'),
json={'username': 'disenqf', 'password': 'disen123'})
print(resp.text, resp.status_code)
def test_get_cate(self):
credentials = 'ZGlzZW5xZjpkaXNlbjEyMw=='
headers = {
'Authorization': f'Basic {credentials}'
}
resp = requests.get(url('/cate/3/'), headers=headers)
print(resp.json())
def test_get_cate_by_token(self):
token = 'ed18b7fdc2924c7a8ecc72e833102ff8'
headers = {
'Authorization': f'Token {token}'
}
resp = requests.get(url('/cate/3/'), headers=headers)
print(resp.json())
def test_logout_by_token(self):
token = 'ed18b7fdc2924c7a8ecc72e833102ff8'
headers = {
'Authorization': f'Token {token}'
}
resp = requests.get(url('/logout/'), headers=headers)
print(resp.text)
def test_put_cate(self):
with open(r'd:\phone.webp', 'rb') as f:
resp = requests.put(url('/cate/3/'),
data={'ord_nm': 3, 'name': '手机品牌'},
files={'icon': f})
print(resp.text)
def test_put2_cate(self):
resp = requests.put(url('/cate/3/'),
data={'ord_nm': 5, 'name': '老人手机'},
auth=('disenqf', 'disen123'))
print(resp.text)
def test_delete_cate(self):
resp = requests.delete(url('/cate/12/'), auth=('disenqf', 'disen123'))
# resp.status_code == 204 操作成功,但没有内容
print(resp.text)
def test_login(self):
resp = requests.post(url('/login/'), json={'phone': '123'})
print(resp.text)
def test_all_goods(self):
resp = requests.get(url('/allgoods/'))
print(resp.text)
def test_detail_goods(self):
for i in range(200):
resp = requests.get(url('/detail/1/'))
print(i, resp.text)
def test_update_sysuser_pwd(self):
token = 'ab97fe1bf25f48eabb9ff58dd9662142'
headers = {
'Authorization': f'Token {token}'
}
for old_, new_ in [
('disen666', 'disen123'),
('disen123', 'disen666'),
('disen666', 'disen123'),
('disen123', 'disen666')
]:
resp = requests.put(url('/updatepwd/'),
json={'old_': old_, 'new_': new_},
headers=headers)
print(resp.text)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/disenQF/django2102_auth.git
[email protected]:disenQF/django2102_auth.git
disenQF
django2102_auth
django2102_auth
master

搜索帮助