def test_address_01(self): """新增地址--合法数据""" #测试之前先查看数量 sql = "select count(*) from ecs_user_address where user_id = (select user_id from ecs_users where user_name = 'hxj123456')" datas = self.db.one(sql) num = datas['count(*)'] add_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/add" #新增地址的网址 method = "post" add_data = { "address": { "default_address": 0, "consignee": "han123", "tel": "13350438199", "zipcode": "620042", "country": "1", "city": "37", "id": 0, "email": "*****@*****.**", "address": "121321", "province": "2", "district": "404", "mobile": "" }, "session": self.session } Interface.add_dress(method=method, url=add_url, data=add_data) #请求新增地址的接口 """新增之后查看数量""" datas_2 = self.db.one(sql) new_num = datas_2['count(*)'] self.assertEqual(new_num, num + 1)
def test_address_05(self, data): """修改收货地址---非法数据""" id = self.address_03() sql = f'select consignee from ecs_user_address where address_id = "{id}"' old = self.db.one(sql) olds = old['consignee'] upd_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/update" #修改收货地址的网址 method = "post" upd_data = { "address": { "default_address": 0, "consignee": f"{data['consignee']}", "tel": f"{data['tel']}", "zipcode": "", "country": "1", "city": "151", "id": 0, "email": f"{data['email']}", "address": f"{data['address']}", "province": "14", "district": "1603", "mobile": "" }, "address_id": f"{id}", "session": self.session } Interface.upd_dress(method=method, url=upd_url, data=upd_data) data = self.db.one(sql) news = data['consignee'] self.assertEqual(olds, news, msg="修改收货地址--使用非法数据修改成功")
def test_address_02(self, data): """新增收货地址---非法数据""" sql = "select count(*) from ecs_user_address where user_id = (select user_id from ecs_users where user_name = 'hxj123456')" datas = self.db.one(sql) old = datas['count(*)'] add_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/add" # 新增地址的网址 method = "post" add_data = { "address": { "default_address": 0, "consignee": f"{data['consignee']}", "tel": f"{data['tel']}", "zipcode": "", "country": "1", "city": "151", "id": 0, "email": f"{data['email']}", "address": f"{data['address']}", "province": "14", "district": "1603", "mobile": "" }, "session": self.session } Interface.upd_dress(method=method, url=add_url, data=add_data) data = self.db.one(sql) news = data['count(*)'] self.assertEqual(old, news, msg="新增地址用非法数据新增成功")
def test_address_04(self): """修改收货地址""" id = self.address_03() print(id) upd_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/update" #修改收货地址的网址 method = "post" consignee = '韩小居' upd_data = { "address": { "default_address": 0, "consignee": f"{consignee}", "tel": "12315456", "zipcode": "", "country": "1", "city": "151", "id": 0, "email": "*****@*****.**", "address": "天府新谷1", "province": "14", "district": "1603", "mobile": "" }, "address_id": f"{id}", "session": self.session } Interface.upd_dress(method=method, url=upd_url, data=upd_data) sql = f'select consignee from ecs_user_address where address_id = "{id}"' data = self.db.one(sql) name = data['consignee'] self.assertEqual(consignee, name)
class CreateOrder: def __init__(self): self.itf = Interface() def create_order(self, **params): # (self,exchange, symbol, side, type, price, quantity): self.itf.create_order(data=params)
def __init__(self): """ Instantiate the plugin and all its modules. """ self._core = Core(self) self._interface = Interface(self) self._network = Network(self)
def main(): info("Starting main loop") # initialize modules info("Initializing modules") interface, engine, cmdcenter = Interface(), Engine(), CmdCenter() Globals().init(cmdcenter, interface, engine) interface.init() and engine.init() and cmdcenter.init() # start main loop info("Starting CmdCenter") cmdcenter.start() info("Main loop completed")
def test_address_06(self): """删除收货地址""" #删除之前查看数量 id = self.address_03() sql = "select count(*) from ecs_user_address where user_id = (select user_id from ecs_users where user_name = 'hxj123456')" datas = self.db.one(sql) num = datas['count(*)'] del_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/delete" #删除地址的网址 method = "post" del_data = {"address_id": f"{id}", "session": self.session} Interface.del_dress(method=method, url=del_url, data=del_data) #删除之后查看数量 datas_2 = self.db.one(sql) new_num = datas_2['count(*)'] #断言,查看删除前和删除后是否一致 self.assertEqual(new_num, num - 1, msg="删除数据失败")
def setUp(self) -> None: self.empire = empire.Empire(races.ORCS, start_resources=100) self.other_empire = empire.Empire(races.ELVES) Interface(self.empire, self.other_empire) Game(self.empire, self.other_empire) self.barrack = self.empire.set_city(name='test city').build_barrack(mouse_pos=(500, 500)) self.assertEqual(self.empire.resources, 80)
def test_case_01(self): """正向数据注册成功""" name = self.fk.user_name() # 姓名 email = self.fk.email() # 邮箱 phone = self.fk.phone_number() # 手机号 password = self.fk.password() # 密码 id = self.fk.pyint() # 随机整数 data = { "field": [{ "id": id, "value": f"{phone}" }], "email": f"{email}", "name": f"{name}", "password": f"{password}" } response = Interface.register(method='post', url=self.url, data=data) #查看数据库是否注册成功 sql = f"select count(*) from ecs_users where user_name = '{name}'" datas = self.db.one(sql) num = datas['count(*)'] self.assertEqual(num, 1, msg="合法数据注册失败") #将测试数据删除 del_sql = f"delete from ecs_users where user_name='{name}'" self.db.execute(del_sql)
def login(): """登录""" url = "http://ecshop.itsoso.cn/ECMobile/?url=/user/signin" method = "post" req_data = {"name": "hxj123456", "password": "******"} response = Interface.login(method=method, url=url, data=req_data) session = get_result_one(response, "session") return session
def test_collect_01(self): """收藏商品""" url = "http://ecshop.itsoso.cn/ECMobile/?url=/user/collect/create" # 添加收藏的网址 method = "post" add_collect_data = { "session": { "uid": f"{self.uid}", "sid": f"{self.sid}" }, "goods_id": 64 } Interface.add_collection(method=method, url=url, data=add_collect_data) #请求添加收藏接口 sql = 'select count(*) from ecs_collect_goods where user_id="4349" and goods_id="64"' data = self.db.one(sql) num = data['count(*)'] self.assertEqual(num, 1)
def test_03_reception(self): """接待""" header = self.token response = Interface().reception(header) result = json.dumps(response, ensure_ascii=False, indent=2) # print(result) print('对返回数据进行断言') print('新增接待成功')
def setUp(self) -> None: # 登录 self.method = "post" url = "http://ecshop.itsoso.cn/ECMobile/?url=/user/signin" data = {"name": "test", "password": "******"} response = Interface.common_method(method=self.method, url=url, data=data) self.sid = get_result_for_keyword(response, "sid") # 获取登录返回值的sid self.uid = get_result_for_keyword(response, "uid") # 获取登录返回值的uid
def address_03(self): """查看收货地址""" look_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/list"#查看收货地址的网址 method = 'post' look_data = {"session":{"uid":f"{self.uid}","sid":f"{self.sid}"}} lool_response = Interface.look_dress(method=method, url=look_url, data=look_data)#请求查看地址的接口 id = get_result_one(lool_response,"id") # print(SendMethod.response_dumps(response=lool_response)) return id
def test_collect_03(self): """删除收藏的商品""" rec_id = self.check_goods()[0] del_url = "http://ecshop.itsoso.cn/ECMobile/?url=/user/collect/delete" #删除收藏的网址 method = "post" del_data = { "session": { "uid": f"{self.uid}", "sid": f"{self.sid}" }, "rec_id": f"{rec_id}" } Interface.del_collection(method=method, url=del_url, data=del_data) sql = f'select count(*) from ecs_collect_goods where user_id="4349" and rec_id="{rec_id}"' datas = self.db.one(sql) data = datas["count(*)"] self.assertEqual(data, 0)
def test_07_verification(self): """核销""" header = self.token response = Interface().verification(header) result = json.dumps(response, ensure_ascii=False, indent=2) # print(result) res = get_result_for_keyword(response, 'msg') # if self.assertEqual(res, "操作成功") == None: print("核销成功")
def login(): """登录""" url = "http://ecshop.itsoso.cn/ECMobile/?url=/user/signin" method = "post" req_data = {"name": "lzj", "password": "******"} response = Interface.login(method=method, url=url, data=req_data) sid = get_result_one(response, "sid") uid = get_result_one(response, "uid") return sid, uid
def address_03(self): """查看收货地址""" look_url = "http://ecshop.itsoso.cn/ECMobile/?url=/address/list" #查看收货地址的网址 method = 'post' look_data = {"session": self.session} lool_response = Interface.look_dress(method=method, url=look_url, data=look_data) #请求查看地址的接口 id = get_result_one(lool_response, "id") return id
def test_03(self): """点击付款""" order_id = self.order() url = "http://ecshop.itsoso.cn/ECMobile/?url=/order/pay" method = "post" data = {"session":self.session, "order_id":order_id} response = Interface.pay(method=method, url=url, data=data) status = get_result_one(response, "succeed") self.assertEqual(status, 1,msg="付款失败")
def place_test_orders(self, arbs): interface = Interface() for product in arbs.keys(): bid_ask = arbs[product] quantity = min(bid_ask["bids"]["quantity"], bid_ask["asks"]["quantity"]) # For now just submit a limit order buy and sell at the same time. for key in bid_ask: if key == 'bids': side = 'sell' elif key == 'asks': side = 'buy' data = bid_ask[key] interface.create_test_order(data['exchange'], product, side, 'limit', quantity, price=data['price'])
def test_06_payment(self): """缴费""" header = self.token response = Interface().payment(header) result = json.dumps(response, ensure_ascii=False, indent=2) print("对缴费是否成功进行断言") # print(result) res = get_result_for_keyword(response, 'msg') # if self.assertEqual(res, "操作成功") == None: print("缴费成功")
def __init__(self) -> None: """ Initialize the `Core` object. Unlike the __init__ of `AstParser`, the internal state of _intr and _astp persists between files specified. `self._intr` contains an instance of the `Interface` object and is responsible for providing access to high level file I/O functionality. `self._astp` contains an instance of the `AstParser` object and is responsible for processing and understanding the abstract syntax tree (AST) that PycParser generates. :return: returns nothing """ self._intr = Interface() self._astp = AstParser()
def test05(self): """点击确认收货""" order_id = self.order() url = "http://ecshop.itsoso.cn/ECMobile/?url=/order/affirmReceived" method = "post" data = {"session":self.session, "order_id":order_id} response = Interface.sure_shouhuo(method=method,url=url,data=data) status = get_result_one(response, "succeed") self.assertEqual(status, 1,msg="待收货确认收货失败")
def test_05_cashier(self): """开单""" header = self.token response = Interface().cashier(header) result = json.dumps(response, ensure_ascii=False, indent=2) # print(result) print("对开单进行断言") # res = get_result_for_keyword(response, 'msg') # if self.assertEqual(res, "新建开单成功") == None: print("开单成功")
def test_02(self): """取消订单""" order_id = self.order() del_url = "http://ecshop.itsoso.cn/ECMobile/?url=/order/cancel" method = "post" del_data = {"session":self.session, "order_id":f"{order_id}"} response = Interface.del_order(method=method,url=del_url,data=del_data) status = get_result_one(response, "succeed") # print(SendMethod.response_dumps(response)) self.assertEqual(status, 1,msg="代付款取消订单失败")
def test_02_order(self): """预约""" response = Interface().order() result = json.dumps(response, ensure_ascii=False, indent=2) print(result) res = get_result_for_keyword(response, 'msg') self.assertEqual(res, '新建预约成功') # 对结果进行断言 if self.assertEqual(res, "新建预约成功") == None: print('断言成功,接口正常请求') print("预约成功") else: print('断言失败')
def order(self): """查看待付款订单""" url = "http://ecshop.itsoso.cn/ECMobile/?url=/order/list" method = "post" data = {"session":self.session, "type":"await_pay", "pagination":{"count":10,"page":1}} response = Interface.wait_pay_list(method=method,url=url,data=data) order_id = get_result_one(response,"order_id") order_sn = get_result_one(response,'order_sn') status = get_result_one(response, "succeed") self.assertEqual(status, 1) return order_id,order_sn
def setUp(self) -> None: self.empire = empire.Empire(races.DWARFS) self.other_empire = empire.Empire(races.ELVES) Interface(self.empire, self.other_empire) Game(self.empire, self.other_empire) self.warrior = warrior.OrcWarrior(empire=self.empire, cost=10, health=11, speed=10, damage=20, fight_distance=300, size=(100, 100), image=image.get_image( self.empire).WARRIOR)
def setUp(self): """ 将登录放在这里,在每次执行用例之前执行 :return: """ print("测试开始") response = Interface().login(method=self.method, url=self.url, data=self.data) # print(type(response)) # print(response) # res = json.loads(response) res = get_result_for_keyword(response, 'token') # res1 = get_results_for_keyword(response, 'id')[-1] # res2 = get_results_for_keyword(response, 'depts')[0][0] self.token = { 'Authorization': res }
def test_04_consultation(self): """ 咨询 :return: """ header = self.token response = Interface().consultation(header) result = json.dumps(response, ensure_ascii=False, indent=2) res = get_result_for_keyword(response, 'msg') if res == '已经有该客户咨询': self.assertTrue(1) print ("接口请求成功") print ("但是当前已有该客户咨询") elif res== '操作成功': print("接口请求成功") print("返回数据为:",result) else: print('断言失败')
#Criacao da camada de rede camRede = CamadaRede() #Criacao das camadas de transporte utilizadas no programa. camTransOrigem = CamadaTransporte(1, camRede) camTransDestino = CamadaTransporte(2, camRede) #Associacao da camada de rede com as camadas de transporte. camRede.origem = camTransOrigem camRede.destino = camTransDestino #Criacao das camadas de aplicacao utilizadas no programa. camAplicOrigem = CamadaAplicacao(1, camTransOrigem) camAplicDestino = CamadaAplicacao(2, camTransDestino) #Associacao das camadas de transporte com as suas camadas de aplicacao #correspondentes. camTransOrigem.camadaAplicacao = camAplicOrigem camTransDestino.camadaAplicacao = camAplicDestino #Inicializacao das camadas de aplizacao camAplicDestino.start() camAplicOrigem.start() #Criacao da interface grafica do programa. interface = Interface(camAplicOrigem, camAplicDestino) #Inicializacao da interface grafica. interface.iniciar()