class Test_login(): def setup_class(self): self.logobj = Mtx_Login() #正向case @pytest.mark.parametrize('account,pwd', [('zhang', '123456'), ('li2', '123456')]) def test_login(self, account, pwd): res = self.logobj.login(account, pwd) assert res['msg'] == '登录成功' #密码不正确 @pytest.mark.parametrize('account,pwd', [('zhang', '234567')]) def test_case2(self, account, pwd): res = self.logobj.login(account, pwd) assert res['msg'] == '密码错误' #用户名不存在 @pytest.mark.parametrize('account,pwd', [('吗云', '123456')]) def test_case3(self, account, pwd): res = self.logobj.login(account, pwd) pytest.assume(res['msg'] == '帐号不存在') #密码位数不及6位或大于18位 @pytest.mark.parametrize('account,pwd', [('zhang', '1234'), ('zhang', '12345678909876543212345')]) def test_case4(self, account, pwd): res = self.logobj.login(account, pwd) pytest.assume(res['msg'] == '密码格式 6~18 个字符之间') pytest.assume(res['code'] == -2)
class Test_Buy(): def setup_class(self): self.logobj = Mtx_Login() self.buyobj = Mtx_Buy() #登录操作 @pytest.mark.parametrize('account,pwd', [('li', '123456')]) def test_case1(self, account, pwd): self.logobj.login(account, pwd) # 正向case @pytest.mark.parametrize( 'goods_id,buy_type,stock,spec,ids,address_id,payment_id,user_note,site_model',\ [(5,'goods',1,'','',1380,2,'',0)] ) def test_case2(self, goods_id, buy_type, stock, spec, ids, address_id, payment_id, user_note, site_model): data = { 'goods_id': goods_id, 'buy_type': buy_type, 'stock': stock, 'spec': spec, 'ids': ids, 'address_id': address_id, 'payment_id': payment_id, 'user_note': user_note, 'site_model': site_model } res = self.buyobj.buy(data) pytest.assume(res['msg'] == '提交成功') # goods为空 @pytest.mark.parametrize( 'goods_id,buy_type,stock,spec,ids,address_id,payment_id,user_note,site_model', \ [('', 'goods', 1, '', '', 1380, 2, '', 0)] ) def test_case3(self, goods_id, buy_type, stock, spec, ids, address_id, payment_id, user_note, site_model): data = { 'goods_id': goods_id, 'buy_type': buy_type, 'stock': stock, 'spec': spec, 'ids': ids, 'address_id': address_id, 'payment_id': payment_id, 'user_note': user_note, 'site_model': site_model } res = self.buyobj.buy(data) print(res) pytest.assume(res['msg'] == '商品id有误')
class Test_Safe(): def setup_class(self): self.loginobj = Mtx_Login() self.logerobj = Logger().get_logger() self.safeobj = Mtx_Safe() #登录 @pytest.mark.parametrize('account,pwd', [('li40', '123456')]) def test_login(self, account, pwd): res = self.loginobj.login(account, pwd) pytest.assume(res['msg'] == '登录成功') self.logerobj.info('登录操作') #正向case @pytest.mark.parametrize('my,new,confirm', [('123456', '123456', '123456')]) def test_safe(self, my, new, confirm): res = self.safeobj.safe(my, new, confirm) pytest.assume(res['msg'] == '修改成功') pytest.assume(res['code'] == 0) self.logerobj.info('修改密码') # 密码错误 @pytest.mark.parametrize('my,new,confirm', [('234567', '123456', '123456')]) def test_safe_pwdisfalse(self, my, new, confirm): res = self.safeobj.safe(my, new, confirm) pytest.assume(res['msg'] == '当前密码错误') pytest.assume(res['code'] == -4) self.logerobj.info('密码错误')
class Test_PersonalSave(): def setup_class(self): self.loginobj = Mtx_Login() self.perobj = Mtx_PersonalSave() self.getlogger = Logger().get_logger() self.getlogger.info('个人信息初始化') #登录 @pytest.mark.parametrize('account,pwd', [('li40', '123456')]) def test_case_1(self, account, pwd): res = self.loginobj.login(account, pwd) assert res['msg'] == '登录成功' self.getlogger.info('登录') @pytest.mark.parametrize('nickname,gender,birthday', [('li40', 2, '2015-09-12')]) def test_case_2(self, nickname, gender, birthday): data = {'nickname': nickname, 'gender': gender, 'birthday': birthday} res = self.perobj.persave(data) assert res['msg'] == '编辑成功' self.getlogger.info('编辑个人信息') @pytest.mark.parametrize('nickname,gender,birthday', [('', '', '')]) def test_case_3(self, nickname, gender, birthday): data = {'nickname': nickname, 'gender': gender, 'birthday': birthday} res = self.perobj.persave(data) print(res) assert res['msg'] == '编辑成功' self.getlogger.info('错误编辑个人信息')
class Test_Addaddress(): def setup_class(self): self.logobj = Mtx_Login() self.addobj = Mtx_Addadress() @pytest.mark.parametrize('accounts,pwd',[('zhang','123456')]) def test_case1(self,accounts,pwd): res = self.logobj.login(accounts,pwd) print(res) pytest.assume(res['msg']=='登录成功') @pytest.mark.parametrize('name,tel,address,id,province,city,county,is_default',\ [('li','137123212321','动车98号','',6,112,1567,0)]) def test_case2(self,name,tel,address,id,province,city,county,is_default): data = { 'name': name, 'tel': tel, 'address': address, 'id': id, 'province': province, 'city': city, 'county': county, 'is_default': is_default } res = self.addobj.address(data) print(res) pytest.assume(res['msg']=='新增成功')
class Test_Footstep(): def setup_class(self): self.loginobj = Mtx_Login() self.loggerinobj = Logger().get_logger() self.footobj = Mtx_Footstep() self.loggerinobj.info('初始化') def test_login(self): res = self.loginobj.login('li40', '123456') pytest.assume(res['msg'] == '登录成功') self.loggerinobj.info('登录') @pytest.mark.parametrize('kw', [('手机', '')]) def test_footstep(self, kw): res = self.footobj.footstep_search(kw) pytest.assume('我的足迹 - 码同学实战系统' in res) self.loggerinobj.info('搜索')
class Test_Jifen: def setup_class(self): self.jifenobj = Mtx_Jifen() self.loggerobj = Logger().get_logger() self.loginobj = Mtx_Login() self.loggerobj.info('初始化') @pytest.mark.parametrize('account,pwd', [('li40', '123456')]) def test_login(self, account, pwd): res = self.loginobj.login(account, pwd) pytest.assume(res['msg'] == '登录成功') self.loggerobj.info('登录') @pytest.mark.parametrize('kw,type', [('手机', '-1')]) def test_jifen(self, kw, type): res = self.jifenobj.jifen(kw, type) pytest.assume('我的积分 - 码同学实战系统' in res) self.loggerobj.info('我的积分')
class Test_Collection(): def setup_class(self): self.colltionobj = Mtx_Colletion() self.loggerobj = Logger().get_logger() self.loginobj = Mtx_Login() @pytest.mark.parametrize('account,pwd',[('li40','123456')]) def test_case_login(self,account,pwd): res = self.loginobj.login(account,pwd) pytest.assume(res['msg']=='登录成功') self.loggerobj.info('登录操作') def test_case_collection(self): res = self.colltionobj.colletion() # print(res) # assert "我的收藏 - 码同学实战系统" in res.text pytest.assume('我的收藏 - 码同学实战系统' in res.text) self.loggerobj.info('收藏列表页')
class Test_Info(): def setup_class(self): self.loginobj = Mtx_Login() self.loggerobj = Logger().get_logger() self.infoobj = Mtx_Info() @pytest.mark.parametrize('account,pwd',[('li40','123456')]) def test_login(self,account,pwd): res = self.loginobj.login(account,pwd) if pytest.assume(res['msg']=='登录成功'): self.loggerobj.info('登录断言成功') else: self.loggerobj.info('登录断言失败') def test_info(self): res = self.infoobj.get_info() if pytest.assume('我的消息 - 码同学实战系统' in res.text): self.loggerobj.info('消息模块查询成功') else: self.loggerobj.info('消息模块查询失败')
class Test_OrderLater(): def setup_class(self): self.laterobj = Mtx_OrderLater() self.loginobj = Mtx_Login() self.loggerobj = Logger().get_logger() self.loggerobj.info("初始化") @pytest.mark.parametrize('accuont,pwd', [('li40', '123456')]) def test_login(self, accuont, pwd): res = self.loginobj.login(accuont, pwd) try: assert res['msg'] == '登录成功' self.loggerobj.info('登录成功') except Exception as e: self.loggerobj.error(f'错误信息提示:{e}') @pytest.mark.parametrize('kw,more,type,status,refundent', [('124', 0, 0, 0, 1)]) def test_orderlater(self, kw, more, type, status, refundent): res = self.laterobj.orderlater(kw, more, type, status, refundent) try: pytest.assume('订单售后 - 码同学实战系统' in res) self.loggerobj.info('断言成功') except Exception as e: self.loggerobj.error(f'断言失败{e}') # @pytest.mark.skip() def test_case_3(self): kw = '123' a = {'is_more': 1, 'type': 0, 'status': 0, 'refundment': 1} res = self.laterobj.orderlaters(kw, **a) # print(res) try: assert '订单售后 - 码同学实战系统' in res self.loggerobj.info('断言成功') except Exception as e: self.loggerobj.error(f'断言失败{e}')