import unittest import requests import yaml class testlogin(unittest.TestCase): def test001(self): """登录后获取token,并写入config.yaml文件中""" #登录获取token url = 'http://192.168./login' data = {"username": "admin", "password": "POiWCUX8MwxKNcu/MJ", "code": "123456", "egj5": "code-key-11111"} result = requests.post(url, json=data) a = result.json() b = a['token'] #c = "Bearer" #self.assertIn(c, b, msg=None) aproject = {"authorization": b} #登录后token写入config.yaml文件中 with open('''F:\python_job\pythonProject2\config\config.yaml''', 'w') as f2: yaml.dump(aproject, f2, default_flow_style=False) #写入config.yaml后,读取token with open('''F:\python_job\pythonProject2\config\config.yaml''') as f: read_data = yaml.load(f, Loader=yaml.FullLoader) d = read_data['authorization'] #断言token读取成功 c = "Bearer" self.assertIn(c, d, msg=None) if __name__ == '__main__': unittest.main()
python登录后获取token,并写入config.yaml文件中
最新推荐文章于 2024-01-09 12:37:34 发布