zoukankan      html  css  js  c++  java
  • day12_框架二test_reg.py代码

    import unittest
    from conf.settings import HOST_INFO
    from lib.tools import my_request, my_md5, my_mysql


    class Reg(unittest.TestCase):
    def setUp(self):
    self.url = HOST_INFO + '/api/user/user_reg' # 接口请求地址

    def test_01_reg_success(self):
    """正常注册"""
    data = {'username': 'sunyy101', 'pwd': '123456aA', 'cpwd': '123456aA'}
    res = my_request('post', self.url, data)
    print(res)
    self.assertIsInstance(res, dict) # 校验类型,是否是字典,只有是字典才能进行继续判断,.json()返回字典
    self.assertEqual(0, res.get('error_code')) # 注册成功校验error_code是否是1000
    self.assertEqual('注册成功!', res.get('msg')) # 注册成功校验msg是否是注册成功!
    sql = 'delete from user_info where username = "sunyy101";' # 删除注册过的用户名,运行N次都OK
    my_mysql.other_sql(sql)

    def test_02_reg_exist(self):
    """测试已经存在的"""
    sql = 'insert into user_info (username,pwd) VALUE ("sunsj567","%s")' % my_md5('123456')
    my_mysql.other_sql(sql)
    data = {'username': 'sunsj567', 'pwd': '123456aA', 'cpwd': '123456aA'}
    res = my_request('post', self.url, data)
    print(res)
    self.assertIsInstance(res, dict)
    self.assertEqual(3005, res.get('error_code'))
    self.assertEqual('用户已存在', res.get('msg'))
    delete_sql = 'delete from user_info where username = "sunsj567";'
    my_mysql.other_sql(delete_sql)
    # 为防止插入sql报错,要执行删除操作,把sql插入的用户删除,再insert就不会报错了
    # 如果没有删除操作就会报下面的错误
    # sql执行失败(1062, "Duplicate entry 'sunsj567' for key 'username'")


    if __name__ == '__main__':
    unittest.main()
  • 相关阅读:
    新浪微博评论抓取
    ubuntu下ssh登录特别慢的问题
    在ubuntu13.04上安装Mac主题
    ubuntu修复grub
    linux卸载自己编译安装的内核
    ubuntu下搭建sublime text2的java开发环境
    CentOS防火墙对特定端口允许
    python笔记:python的表达式
    python笔记一:python变量
    python笔记一:python初步
  • 原文地址:https://www.cnblogs.com/laosun0204/p/8640632.html
Copyright © 2011-2022 走看看