代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。