示例#1
0
    def create_purchase(self):
        session = HttpSession(self.base_url)
        # self.client.post('/api/v0.9/reservation/', reservation_body)
        reservation_response = session.post('/api/v0.9/reservation/',
                                            data=reservation_body)

        if reservation_response.status_code != 201:
            return

        if reservation_response.status_code == 409:
            raise StopLocust('No available tickets.')

        checkout_response = session.post('/api/v0.9/reservation/_checkout',
                                         data=checkout_body)

        if checkout_response.status_code != 200:
            return

        purchase = checkout_response.json()['purchase']
        completion_response = session.post(
            '/api/v0.9/purchases/_complete',
            json.dumps(
                dict(purchase_id=purchase['purchase_id'],
                     hash=purchase['completion_params']['hash'],
                     processor=purchase['completion_params']['processor'],
                     payment_ref=purchase['completion_params']['order_ref'])))
示例#2
0
    def create_purchase(self):
        session = HttpSession(self.base_url)
        # self.client.post('/api/v0.9/reservation/', reservation_body)
        reservation_response = session.post("/api/v0.9/reservation/", data=reservation_body)

        if reservation_response.status_code != 201:
            return

        if reservation_response.status_code == 409:
            raise StopLocust("No available tickets.")

        checkout_response = session.post("/api/v0.9/reservation/_checkout", data=checkout_body)

        if checkout_response.status_code != 200:
            return

        purchase = checkout_response.json()["purchase"]
        completion_response = session.post(
            "/api/v0.9/purchases/_complete",
            json.dumps(
                dict(
                    purchase_id=purchase["purchase_id"],
                    hash=purchase["completion_params"]["hash"],
                    processor=purchase["completion_params"]["processor"],
                    payment_ref=purchase["completion_params"]["order_ref"],
                )
            ),
        )
示例#3
0
    def create_purchase(self):
        session = HttpSession(self.base_url)
        # self.client.post('/api/v0.9/reservation/', reservation_body)
        reservation_response = session.post('/api/v0.9/reservation/', data=reservation_body)

        if reservation_response.status_code != 201:
            return

        checkout_response = session.post('/api/v0.9/reservation/_checkout', data=checkout_body)
示例#4
0
    def create_purchase(self):
        session = HttpSession(self.base_url)
        # self.client.post('/api/v0.9/reservation/', reservation_body)
        reservation_response = session.post('/api/v0.9/reservation/',
                                            data=reservation_body)

        if reservation_response.status_code != 201:
            return

        checkout_response = session.post('/api/v0.9/reservation/_checkout',
                                         data=checkout_body)
class StableCoinUser(User):
    wait_time = constant(0)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # client
        self.node_session = HttpSession(
            base_url="http://128.199.13.131:9000",
            request_success=self.environment.events.request_success,
            request_failure=self.environment.events.request_failure,
        )

        # platform
        self.platform_session = HttpSession(
            base_url="http://128.199.14.196:80",
            request_success=self.environment.events.request_success,
            request_failure=self.environment.events.request_failure,
        )

    @task
    def transfer(self):
        # 1) prepare (and sign) HSC transfer transaction
        hsc_transaction, operator, valid_start = prepare_hsc_transfer_transaction(
        )

        # 2) sign Hedera (HCS) transaction
        response = self.platform_session.post("/hedera/transaction",
                                              data=hsc_transaction)

        # 3) submit Hedera (HCS) transaction (x1000)
        send_hedera_transaction(response.content)

        # 4) wait for confirmation
        wait_for_confirmation(self.node_session, operator, valid_start)
示例#6
0
    def test_token_work(self,count):
        mobiles =self.get_mobile(count)
        Worktoken = list()
        Lovetoken = list()
        lifetoken = list()
        url = "http://"+K8sServer+":10001"
        t = HttpSession(url)
        header = {"Content-Type": "application/json"}
        for i in mobiles:
            data = {"Uid": "string", "DeviceName": "string", "Lat": 0, "Lon": 0, "Mobile": i, "Password": 123456}
            obj = t.post('/v1/logins/users', data=json.dumps(data), headers=header)
            WorkAuthorization = json.loads(obj.text).get('WorkAuthorization')
            if WorkAuthorization:
                Worktoken.append(WoAuthorization)
                Worktoken.append('\n')
            LoveAuthorization = json.loads(obj.text).get('LoveAuthorization')
            if LoveAuthorization:
                Lovetoken.append(LoAuthorization)
                Lovetoken.append('\n')
            LifeAuthorization = json.loads(obj.text).get('LifeAuthorization')
            if  LoveAuthorization:
                lifetoken.append(LiAuthorization)
                lifetoken.append('\n')

        with open('token/WoAuthorization.txt', 'w') as f:
            f.writelines(Wotoken)

        with open('token/LoAuthorization.txt','w') as l:
            l.writelines(Lotoken)

        with open('token/LiAuthorization.txt', 'w') as i:
            i.writelines(litoken)
示例#7
0
 def test_post_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect"
     r = s.post(url)
     assert 200 == r.status_code
     post_stats = global_stats.get(url, method="POST")
     get_stats = global_stats.get(url, method="GET")
     assert 1 == post_stats.num_requests
     assert 0 == get_stats.num_requests
示例#8
0
 def test_post_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect"
     r = s.post(url)
     self.assertEqual(200, r.status_code)
     post_stats = global_stats.get(url, method="POST")
     get_stats = global_stats.get(url, method="GET")
     self.assertEqual(1, post_stats.num_requests)
     self.assertEqual(0, get_stats.num_requests)
示例#9
0
 def test_post_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect"
     r = s.post(url)
     self.assertEqual(200, r.status_code)
     post_stats = global_stats.get(url, method="POST")
     get_stats = global_stats.get(url, method="GET")
     self.assertEqual(1, post_stats.num_requests)
     self.assertEqual(0, get_stats.num_requests)
示例#10
0
 def post(port, url, data, au):
     http = HttpSession(base + ":" + port)
     data = http.post(url,
                      data=json.dumps(data),
                      headers={
                          'Authorization': au,
                          'Content-Type': 'application/json',
                          'accept': 'application/json'
                      })
     return data
示例#11
0
    def create_purchase(self):
        session = HttpSession(self.base_url)
        # self.client.post('/api/v0.9/reservation/', reservation_body)
        reservation_response = session.post('/api/v0.9/reservation/', data=reservation_body)

        if reservation_response.status_code != 201:
            return

        checkout_response = session.post('/api/v0.9/reservation/_checkout', data=checkout_body)

        if checkout_response.status_code != 200:
            return

        purchase = checkout_response.json()['purchase']
        completion_response = session.post('/api/v0.9/purchases/_complete', json.dumps(dict(
            purchase_id=purchase['purchase_id'],
            hash=purchase['completion_params']['hash'],
            processor=purchase['completion_params']['processor'],
            payment_ref=purchase['completion_params']['order_ref']
        )))
示例#12
0
 def login(self):
     payload = "username=user&password=user&grant_type=password&client_id=envoy"
     headers = {
         'Content-Type': "application/x-www-form-urlencoded",
     }
     client = HttpSession(
         base_url=os.environ.get("JWT_URL", "http://localhost:8080"))
     response = client.post(
         '/auth/realms/envoy/protocol/openid-connect/token',
         payload,
         headers=headers)
     self.auth_token = "Bearer " + json.loads(response.text)['access_token']
示例#13
0
class DrawTask(TaskSet):
    session = None

    def on_start(self):
        host = 'https://passport.tuandai.com'
        # 设置sesssion
        self.session = HttpSession(self.host)
        res = self.session.get(
            url=host +
            '/2login?ret=http://at.tuandai.com/userActivity/midAutumn/we/index'
        )
        print(res.cookies.values())
        params = {
            'un': '15866660001',
            'pd': '123456a',
            'loadType': 2,
            'encrypt': 0,
            't': 65446446
        }
        url = '/2login'
        # 使用 session 来登录
        response = self.session.post(url=host + url, data=params)
        print("login_result:", response.status_code, response.text)

    def on_stop(self):
        pass

    @task(1)
    def FIRST_ROUND(self):
        response = self.session.get(
            url=web + '/huodong/answerQuestion/drawPrize',
            params='drawFlag=ANSWER_QUESTION_FIRST_ROUND')
        print("FIRST_ROUND:", response.status_code, response.text)

    @task(1)
    def SECOND_ROUND(self):
        response = self.session.get(
            url=web + '/huodong/answerQuestion/drawPrize',
            params='drawFlag=ANSWER_QUESTION_SECOND_ROUND')
        print("SECOND_ROUND:", response.status_code, response.text)

    @task(1)
    def THIRD_ROUND(self):
        response = self.session.get(
            url=web + '/huodong/answerQuestion/drawPrize',
            params='drawFlag=ANSWER_QUESTION_THIRD_ROUND')
        print("THIRD_ROUND:", response.status_code, response.text)
示例#14
0
 def post(port, url, data, au):
     # data = requests.post(url, data, headers={'Authorization': au, 'Content-Type': 'application/json',
     #                                          'accept': 'application/msgpack'})
     http = HttpSession(base + ":" + port)
     data = http.post(url,
                      data=json.dumps(data),
                      headers={
                          'Authorization': au,
                          'Content-Type': 'application/json',
                          'accept': 'application/msgpack'
                      })
     #return msgpack.unpackb(data.content, encoding="utf8")
     if data.status_code == 204:
         return data
     elif data.content == b'':  #返回值为空
         return data
     else:
         return Http_esponseDecode(data)
示例#15
0
 def create_purchase(self):
     session = HttpSession(self.base_url)
     reservation_response = session.post('/api/v0.9/reservation/',
                                         data=reservation_body)
示例#16
0
 def post(self):
     session = HttpSession(self.base_url)
     reservation_response = session.post('/prod/insert-product', data=body)
示例#17
0
    def Logout( self,access_token):
        s = HttpSession("https://qa-api.aswat.co")
        response = s.post("https://qa-api.aswat.co/auth/logout", headers = {"api_key":access_token})
        return response

						
示例#18
0
 def loginposition( self,api_key,cclogin,):
     s = HttpSession("https://qa-api.aswat.co")
     request="https://qa-api.aswat.co/integrations/cti/agents/"+cclogin+"/login/agent-"+cclogin
     print(request)
     response = s.post(request, headers = {"api_key":api_key, "Content-Type":"application/json"})
     return response
示例#19
0
 def login( self,userName,passWord):
     s = HttpSession("https://qa-api.aswat.co")
     response = s.post("https://qa-api.aswat.co/auth/login", {"username":userName, "password":passWord})
     return response
示例#20
0
 def create_purchase(self):
     session = HttpSession(self.base_url)
     reservation_response = session.post('/api/v0.9/reservation/', data=reservation_body)
示例#21
0
 def test_cookie(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     r = s.post("/set_cookie?name=testcookie&value=1337")
     self.assertEqual(200, r.status_code)
     r = s.get("/get_cookie?name=testcookie")
     self.assertEqual('1337', r.content.decode())
示例#22
0
 def test_cookie(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     r = s.post("/set_cookie?name=testcookie&value=1337")
     self.assertEqual(200, r.status_code)
     r = s.get("/get_cookie?name=testcookie")
     self.assertEqual('1337', r.content.decode())
示例#23
0
class loginHttpSession(TaskSet):
    # 登录并购买商品压力测试

    def on_start(self):
        """
        测试数据初始化
        1.创建session会话,提供给后面的请求
        2.初始化请求头的信息
        3.初始化用户信息(用户信息参数化)
        4.引用自定义日志
        """
        self.session = HttpSession(base_url="http://*****:*****@qq.com", "123456"],
            1: ["*****@*****.**", "123456"],
            2: ["*****@*****.**", "123456"]
        }

        self.log = MyLog.MyLog().get_logger()

    def get_user_info(self):
        # 获取随机用户ID
        user_id = random.randint(0, len(self.userinfo) - 1)
        return user_id

    def index(self):
        # 打开商城首页
        return self.session.get("/")

    def input_username(self, loginToken, uname):
        # 进入输入用户名页面
        # 需要传送session和登录token值
        # 返回响应信息response,和userId
        input_url = "index.php"
        param = {
            "con": "ajax",
            "act": "account",
            # "account":"*****@*****.**"
            "account": uname,  # 参数化用户名信息
        }

        # self.log.debug("[input_username]:userId=%s" %userId)   #打印日志
        # response=self.session.post(input_url,params=param,headers=self.header)
        with self.session.post(input_url,
                               params=param,
                               headers=self.header,
                               catch_response=True) as response:
            # 获取请求详情数据,并设置检查点
            print(response.text)
            response_value = response.text
            print(type(response_value))
            # 由于返回的数据是unicode类型,也就是字符串,所以只能截取有效数据进行后面的检查点的判断
            status = response_value[response_value.find('"status":') +
                                    len('"status":'):response_value.find(",")]
            msg = response_value[response_value.find('"msg":"') +
                                 len('"msg":"'):response_value.find('"}')]
            if status != "false":
                response.failure("input_username: status error!")
            elif msg != "\u6b64\u7528\u6237\u5df2\u7ecf\u6ce8\u518c":
                response.failure("input_username: msg error!")

            return response, uname

    def submit_login(self, loginToken, uname, upwd):
        # 输入用户名和密码提交登录
        # 需要传递loginToken,和userId用于用户登录
        # 返回响应信息response,和userId
        login_url = "index.php?con=simple&act=login_act"

        bodys = {
            "redirectURL": "/tshop/",
            # "account":"*****@*****.**",
            # "password":"******",
            "account": uname,  # 参数化用户名
            "password": upwd,  # 参数化密码
            "tiny_token_login": loginToken,
        }
        # self.log.debug("[submit_login]:userId=%s" %userId)

        with self.session.post(login_url,
                               data=bodys,
                               headers=self.header,
                               catch_response=True) as response:
            text = response.text
            page_text = re.compile(r'<div class="sub-1">(.+)?-')
            page_userinfo = page_text.search(text)
            userinfo = page_userinfo.group(1)
            print(userinfo)
            print(uname)
            if userinfo.find(
                    uname
            ) < 0:  # str的find方法如果找不到元素,返回值为-1,所以判断小于0表示,在userinfo中无登录的用户名
                response.failure("submit_login: not found username in page!")
            return response, uname

    def go_goods_details(self):
        # 进入商品详情页面
        # 返回响应数据
        goodsDetails_url = "index.php"
        params = {"con": "index", "act": "product", "id": "16"}

        # response=self.session.get(goodsDetails_url,data=params,headers=self.header)
        with self.session.get(goodsDetails_url,
                              data=params,
                              headers=self.header,
                              catch_response=True) as response:
            text = response.text
            page_text = re.compile(
                r'</span><b class="cart-total red" >(.+)?</b></span></span></div>'
            )
            page_price = page_text.search(text)
            price = page_price.group(1)
            if price < 100:
                response.failure("go_goods_details: not found price!")

            return response

    def add_goods_tips(self, loginToken=None):
        # 在商品详情页面,点击进入到确认订单页面
        # 返回用户购物车清单的商品信息
        goods_tips_url = "index.php?con=index&act=goods_add&id=61&num=3"
        with self.session.get(goods_tips_url,
                              headers=self.header,
                              catch_response=True) as response:
            text = response.text
            page_text = re.compile(r"<li >(.+)?<em></em><i></i></li>")
            page_info = page_text.search(text)
            value = page_info.group(1)
            if value != "4、订购完成":
                response.failure("add_goods_tips: not found 4、订购完成")
            return response

    def fill_order_info(self):
        # 进入到填写订单信息页面
        # 使用正则表达式,抓取页面返回的order_Token
        # 返回响应数据与order_Token

        fill_order_url = "index.php?con=simple&act=order&cart_type=cart"

        with self.session.get(fill_order_url,
                              headers=self.header,
                              catch_response=True) as response:
            order_re = re.compile(r"'tiny_token_order' value='(.+)?'/>")
            order_token = None  # order_token赋默认值为None,如果取不到order_token以便下面进行判断,为None则抛出错误
            order_token = order_re.search(response.text).group(1)
            if order_token == None:
                response.failure("fill_order_info: not found order_token")

            return response, order_token

    def submit_order(self, orderToken, uname):
        # 提交订单
        # 需传递填写订单信息页面的orderToken,对提交订单进行参数化
        # 根据userId,登录的userId来区分不同用户的收货地址id
        # 返回响应信息,与orderToken
        sub_order_url = "index.php?con=simple&act=order_act"

        bodys = {
            "address_id": "30",
            "payment_id": "1",
            "user_remark": "",
            "invoice_type": "0",
            "invoice_title": "",
            "cart_type": "",
            "tiny_token_order": orderToken
        }

        # 根据不同的userId更新参数中的地址id,确保每个用户的收货地址正确
        if uname == "*****@*****.**":
            bodys["address_id"] = "30"
        elif uname == "*****@*****.**":
            bodys["address_id"] = "31"
        elif uname == "*****@*****.**":
            bodys["address_id"] = "32"
        else:
            print("userId not found !!!")
        # self.log.debug("[submit_order]:userId=%s,address_id=%s" %(userId,bodys["address_id"]))

        with self.session.post(sub_order_url,
                               data=bodys,
                               headers=self.header,
                               catch_response=True) as response:
            text = response.text
            textview = re.compile(
                r'<span><i class="icon-success-48"></i>(.+)?</span>')
            re_result = textview.search(text)
            page_info = re_result.group(1)
            # if page_info!="订单已成功提交!":
            #   response.failure("submit_order:not found 订单已成功提交!")
            return response, orderToken

    def logout(self):
        # 下单成功后,退出登录
        logout_url = "index.php?con=simple&act=logout"
        with self.session.get(logout_url, headers=self.header) as response:
            return response

    @task
    def go_shopping(self):
        # 购买商品流程:登录->进入商品详情页面->将商品添加到购物车->进入填写订单信息页面->提交订单

        user_id = self.get_user_info()  # 获取用户id
        username = self.userinfo[user_id][0]
        upassword = self.userinfo[user_id][1]

        self.index()  # 进入商城首页

        laster_url = "index.php?con=simple&act=login"

        first_reponse = self.session.get(laster_url, headers=self.header)
        lg_page = first_reponse.text

        re_token = re.compile(r"name='tiny_token_login' value='(.+)?'/>")

        # 通过正则表达式获取登录页面的token信息
        re_result = re_token.search(lg_page)
        lg_token = None
        if re_result:
            lg_token = re_result.group(1)

        # #输入用户名页面,并获取login_token 信息
        inp_username_response = self.input_username(loginToken=lg_token,
                                                    uname=username)
        inp_username_userId = inp_username_response[1]  # 返回输入用户名时,参数化的userId

        # # #输入账号、密码,并提交登录
        sub_login_response = self.submit_login(loginToken=lg_token,
                                               uname=username,
                                               upwd=upassword)
        sub_login_userId = sub_login_response[1]  # 返回用户登录时,参数化的userId

        # #进入到商品详情页面
        goods_details_response = self.go_goods_details()
        # # print goods_details_response.text

        # #进入购物车清单页面
        goods_tips_response = self.add_goods_tips()
        # # print goods_tips_response.text

        # #点击购物车清单页面的-【立即支付】,跳转到填写订单信息页面
        fill_order_response = self.fill_order_info()
        orderToken_value = fill_order_response[1]

        # #点击填写订单信息页面【确认支付】按钮
        sub_order_response = self.submit_order(orderToken=orderToken_value,
                                               uname=username)

        # 退出用户登录状态
        logout = self.logout()
示例#24
0
class LoadLocust(TaskSet):
    def on_start(self):
        self.session = HttpSession('http://bms-3.yzwill.cn')

    @seq_task(1)
    def test_00_login(self):
        t= DataSource().getAllyaml('Logining')
        url = str(t.get('urls'))
        data = dict(t.get('data'))
        try:
            data['mobile']=self.locust.queueData.get()
            print(data)
        except queue.Empty:
            print('no data exit')
            exit(0)
        headers = {
                  "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8',
                  "Host": 'bms-3.yzwill.cn',
                  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
                  }
        response = self.session.post(url=url,data=data, headers=headers,verify=False)
        if response.status_code == 200:
            print("success")
        else:
            print("fails")

    def test_0_getGkOpenEnrollCityInfo(self):
        '''随机获取国开报读城市'''
        intFile = YamlParser('StudentInfo')
        case = TestCaseAssembly().setAipParam('getGkOpenEnrollCityInfo', (intFile.getYamlParms(('GK', 'grade'),), intFile.getYamlParms(('GK', 'level'))),
                                              (('data', 'ext2'), ('data', 'ext1')))

        headers = {
                  "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8',
                  "Host": 'bms-3.yzwill.cn',
                  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
                  }

        response = self.session.post(url=case[2], data=case[3], headers=headers, verify=False)
        if response.status_code == 200:
            print("success")
        else:
            print("fails")
        '''提取参数'''
        AfterParamCom().saveParam(response.text, 'getGkOpenEnrollCityInfo', ('GStudent', 'city'))


    def test_1_sUnvs(self):
        '''随机获取国开院校ID'''
        intFile = YamlParser('StudentInfo')
        case = TestCaseAssembly().setAipParam('sUnvs', (intFile.getYamlParms(('GK', 'recruitType')),), ('data', 'ext1'))

        headers = {
                  "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8',
                  "Host": 'bms-3.yzwill.cn',
                  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
                  }
        response = self.session.post(url=case[2], data=case[3], headers=headers, verify=False)
        if response.status_code == 200:
            print("success")
        else:
            print("fails")
        '''提取参数'''
        AfterParamCom().saveParam(response.text, 'sUnvs', ('GStudent', 'unvsId'))


    def test_2_getOpenTestAreaByCity(self):
        '''随机获取国开报读考区ID+考区名称'''
        intFile = YamlParser('StudentInfo')
        extFile = YamlParser('LearnInfo')
        case = TestCaseAssembly().setAipParam('getOpenTestAreaByCity', (
        intFile.getYamlParms(('GK', 'level')), intFile.getYamlParms(('GK', 'grade')), extFile.getYamlParms(('GStudent', 'city'))),
                                              (('data', 'ext2'), ('data', 'ext3'), ('data', 'ext1')))

        headers = {
                  "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8',
                  "Host": 'bms-3.yzwill.cn',
                  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
                  }
        response = self.session.post(url=case[2], data=case[3], headers=headers, verify=False)
        if response.status_code == 200:
            print("success")
        else:
            print("fails")
        '''提取参数'''
        AfterParamCom().saveParam(response.text, 'getOpenTestAreaByCity', (('GStudent', 'taId'), ('GStudent', 'taName')))

    def test_3_getOpenPfsnByTaId(self):
        '''随机获取国开报读专业pfsnId+专业名称pfsnName+专业编号pfsnCode'''
        intFile = YamlParser('StudentInfo')
        extFile = YamlParser('LearnInfo')
        case = TestCaseAssembly().setAipParam('getOpenPfsnByTaId', (
        intFile.getYamlParms(('GK', 'level')), intFile.getYamlParms(('GK', 'grade')), extFile.getYamlParms(('GStudent', 'taId'))),
                                              (('data', 'ext2'), ('data', 'ext3'), ('data', 'ext1')))
        headers = {
                  "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8',
                  "Host": 'bms-3.yzwill.cn',
                  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
                  }
        response = self.session.post(url=case[2], data=case[3], headers=headers, verify=False)
        if response.status_code == 200:
            print("success")
        else:
            print("fails")
        '''提取参数'''
        AfterParamCom().saveParam(response.text, 'getOpenPfsnByTaId', (('GStudent', 'pfsnId'), ('GStudent', 'pfsnName'), ('GStudent', 'pfsnCode')))

    def test_4_showFeeList(self):
        '''获取国开报读收费标准信息'''
        intFile = YamlParser('StudentInfo')
        extFile = YamlParser('LearnInfo')
        case = TestCaseAssembly().setAipParam('showFeeList', (
        intFile.getYamlParms(('GK', 'recruitType')), intFile.getYamlParms(('GK', 'scholarships')), extFile.getYamlParms(('GStudent', 'pfsnId')),
        extFile.getYamlParms(('GStudent', 'taId'))), (('data', 'recruitType'), ('data', 'scholarship'), ('data', 'pfsnId'), ('data', 'taId')))

        headers = {
                  "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8',
                  "Host": 'bms-3.yzwill.cn',
                  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
                  }
        response = self.session.post(url=case[2], data=case[3], headers=headers, verify=False)
        if response.status_code == 200:
            print("success")
        else:
            print("fails")
        '''提取参数'''
        AfterParamCom().saveJson(response.text, (('body', 'feeInfo', 'feeId'),), (('GStudent', 'feeId'),))
        AfterParamCom().saveParam(response.text, 'showFeeList', ('GStudent', 'feeList'))


    def test_5_gk_normal_register(self):
        '''随机录入国开类型学员学员'''
        intFile = YamlParser('StudentInfo')
        extFile = YamlParser('LearnInfo')
        '''从配置文件获取参数'''
        grade = intFile.getYamlParms(('GK', 'grade'))
        recruitType = intFile.getYamlParms(('GK', 'recruitType'))
        scholarship = intFile.getYamlParms(('GK', 'scholarships'))
        '''从参数文件获取参数'''
        city = extFile.getYamlParms(('GStudent', 'city'))
        unvsId = extFile.getYamlParms(('GStudent', 'unvsId'))
        feeId = extFile.getYamlParms(('GStudent', 'feeId'))
        feeList = extFile.getYamlParms(('GStudent', 'feeList'))
        pfsnCode = extFile.getYamlParms(('GStudent', 'pfsnCode'))
        pfsnId = extFile.getYamlParms(('GStudent', 'pfsnId'))
        pfsnName = extFile.getYamlParms(('GStudent', 'pfsnName'))
        taId = extFile.getYamlParms(('GStudent', 'taId'))
        taName = extFile.getYamlParms(('GStudent', 'taName'))
        mobile =BeforeParamCom().getPhone()
        idCard =BeforeParamCom().getCard()
        BeforeParamCom().setLearn((('GStudent', 'mobile'),), mobile)
        BeforeParamCom().setLearn((('GStudent', 'idCard'),), idCard)

        pfsnLevel = intFile.getYamlParms(('GK', 'pfsnLevel'))

        '''将参数组合到接口文件'''
        values = (str(grade),str(recruitType),str(scholarship),str(city),str(unvsId),str(feeList),str(pfsnCode),
                  str(pfsnId),str(pfsnName),str(taId),str(taName),mobile,idCard,str(pfsnLevel),str(feeId))
        keys = (('data', 'grade'),('data', 'recruitType'),('data', 'scholarship'),('data', 'city'),('data', 'unvsId'),
                ('data', 'feeList'), ('data', 'pfsnCode'), ('data', 'pfsnId'), ('data', 'pfsnName'), ('data', 'taId'),
                ('data', 'taName'),('data', 'mobile'),('data', 'idCard'),('data', 'pfsnLevel'),('data', 'feeId'))
        case = TestCaseAssembly().setAipParam('GrecruitAdd',values,keys,'regiester')
        data = MultipartEncoder(fields=case[3])

        headers = {
                  "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8',
                  "Host": 'bms-3.yzwill.cn',
                  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
                  }
        headers["Content-Type"] = data.content_type

        response = self.session.post(url=case[2], data=case[3], headers=headers, verify=False)
        if response.status_code == 200:
            print("success")
        else:
            print("fails")

    @seq_task(2)
    def test_01_gkregister(self):
        self.test_0_getGkOpenEnrollCityInfo()
        self.test_1_sUnvs()
        self.test_2_getOpenTestAreaByCity()
        self.test_3_getOpenPfsnByTaId()
        self.test_4_showFeeList()
        self.test_5_gk_normal_register()
示例#25
0
class LoadLocust(TaskSequence):
    def on_start(self):
        self.session = HttpSession(base_url='http://bms-3.yzwill.cn')

    @seq_task(1)
    def test_00_login(self):
        t = DataSource().getAllyaml('Logining')
        url = str(t.get('urls'))
        data = dict(t.get('data'))
        try:
            data['mobile'] = self.locust.queueData.get()
            print(data)
        except queue.Empty:
            print('no data exit')
            exit(0)
        headers = {
            "Content-Type":
            'application/x-www-form-urlencoded; charset=UTF-8',
            "Host":
            'bms-3.yzwill.cn',
            "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
        }
        response = self.session.post(url=url,
                                     data=data,
                                     headers=headers,
                                     verify=False)
        if response.status_code == 200:
            print("login success")
        else:
            print("login fails")

    def test_0_getGkOpenEnrollCityInfo(self):
        '''随机获取国开报读城市'''
        intFile = YamlParser('StudentInfo')
        case = TestCaseAssembly().setAipParam(
            'getGkOpenEnrollCityInfo', (intFile.getYamlParms(
                ('GK', 'grade'), ), intFile.getYamlParms(
                    ('GK', 'level'))), (('data', 'ext2'), ('data', 'ext1')))

        headers = {
            "Content-Type":
            'application/x-www-form-urlencoded; charset=UTF-8',
            "Host":
            'bms-3.yzwill.cn',
            "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
        }

        response = self.session.get(url=case[2],
                                    data=case[3],
                                    headers=headers,
                                    verify=False)
        if response.status_code == 200:
            print("getGkOpenEnrollCityInfo success")
        else:
            print("getGkOpenEnrollCityInfo fails")
        '''提取参数city'''
        Result = DataExtraction().extRegxParam(response.text,
                                               'getGkOpenEnrollCityInfo')
        city = Result[random.randint(0, len(Result) - 1)]
        return city

    def test_1_sUnvs(self):
        '''随机获取国开院校ID'''
        intFile = YamlParser('StudentInfo')
        case = TestCaseAssembly().setAipParam('sUnvs', (intFile.getYamlParms(
            ('GK', 'recruitType')), ), ('data', 'ext1'))
        headers = {
            "Content-Type":
            'application/x-www-form-urlencoded; charset=UTF-8',
            "Host":
            'bms-3.yzwill.cn',
            "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
        }
        response = self.session.get(url=case[2],
                                    data=case[3],
                                    headers=headers,
                                    verify=False)
        if response.status_code == 200:
            print("sUnvs success")
        else:
            print("sUnvs fails")
        '''提取参数unvsId'''
        Result = DataExtraction().extRegxParam(response.text, 'sUnvs')
        unvsId = Result[random.randint(0, len(Result) - 1)]
        return unvsId

    def test_2_getOpenTestAreaByCity(self, city):
        '''随机获取国开报读考区ID+考区名称'''
        intFile = YamlParser('StudentInfo')
        case = TestCaseAssembly().setAipParam(
            'getOpenTestAreaByCity', (intFile.getYamlParms(
                ('GK', 'level')), intFile.getYamlParms(('GK', 'grade')), city),
            (('data', 'ext2'), ('data', 'ext3'), ('data', 'ext1')))

        headers = {
            "Content-Type":
            'application/x-www-form-urlencoded; charset=UTF-8',
            "Host":
            'bms-3.yzwill.cn',
            "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
        }
        response = self.session.get(url=case[2],
                                    data=case[3],
                                    headers=headers,
                                    verify=False)
        if response.status_code == 200:
            print("getOpenTestAreaByCity success")
        else:
            print("getOpenTestAreaByCity fails")
        '''提取参数taId+taName'''
        Result = DataExtraction().extRegxParam(response.text,
                                               'getOpenTestAreaByCity')
        ta = Result[random.randint(0, len(Result) - 1)]
        taId = ta[0]
        taName = ta[1]
        return taId, taName

    def test_3_getOpenPfsnByTaId(self, taId):
        '''随机获取国开报读专业pfsnId+专业名称pfsnName+专业编号pfsnCode'''
        intFile = YamlParser('StudentInfo')
        case = TestCaseAssembly().setAipParam(
            'getOpenPfsnByTaId', (intFile.getYamlParms(
                ('GK', 'level')), intFile.getYamlParms(('GK', 'grade')), taId),
            (('data', 'ext2'), ('data', 'ext3'), ('data', 'ext1')))
        headers = {
            "Content-Type":
            'application/x-www-form-urlencoded; charset=UTF-8',
            "Host":
            'bms-3.yzwill.cn',
            "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
        }
        response = self.session.get(url=case[2],
                                    data=case[3],
                                    headers=headers,
                                    verify=False)
        if response.status_code == 200:
            print("getOpenPfsnByTaId success")
        else:
            print("getOpenPfsnByTaId fails")
        '''提取参数'''
        Result = DataExtraction().extRegxParam(response.text,
                                               'getOpenPfsnByTaId')
        pfsn = Result[random.randint(0, len(Result) - 1)]
        pfsnId = pfsn[0]
        pfsnName = pfsn[1]
        pfsnCode = pfsn[2]
        return pfsnId, pfsnName, pfsnCode

    def test_4_showFeeList(self, pfsnId, taId):
        '''获取国开报读收费标准信息'''
        intFile = YamlParser('StudentInfo')
        case = TestCaseAssembly().setAipParam(
            'showFeeList', (intFile.getYamlParms(('GK', 'recruitType')),
                            intFile.getYamlParms(
                                ('GK', 'scholarships')), pfsnId, taId),
            (('data', 'recruitType'), ('data', 'scholarship'),
             ('data', 'pfsnId'), ('data', 'taId')))

        headers = {
            "Content-Type":
            'application/x-www-form-urlencoded; charset=UTF-8',
            "Host":
            'bms-3.yzwill.cn',
            "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/73.0.3683.86 Safari/537.36"
        }
        response = self.session.post(url=case[2],
                                     data=case[3],
                                     headers=headers,
                                     verify=False)
        if response.status_code == 200:
            print("showFeeList success")
        else:
            print("showFeeList fails")
        '''提取参数'''
        feeId = getJsonParm(response.text)['body']['feeInfo']['feeId']
        Result = DataExtraction().extRegxParam(response.text, 'showFeeList')
        feeList = Result[random.randint(0, len(Result) - 1)]
        return feeId, feeList

    @seq_task(2)
    def test_5_gk_normal_register(self):
        '''随机录入国开类型学员学员'''
        city = self.test_0_getGkOpenEnrollCityInfo()
        unvsId = self.test_1_sUnvs()
        ta = self.test_2_getOpenTestAreaByCity(city)
        pfsn = self.test_3_getOpenPfsnByTaId(ta[0])
        pfsnId = pfsn[0]
        pfsnCode = pfsn[1]
        free = self.test_4_showFeeList(pfsn[0], ta[0])
        feeId = free[0]
        feeList = free[1]
        taId = ta[0]
        taName = ta[1]
        pfsnName = pfsn[2]
        intFile = YamlParser('StudentInfo')
        '''从配置文件获取参数'''
        grade = intFile.getYamlParms(('GK', 'grade'))
        recruitType = intFile.getYamlParms(('GK', 'recruitType'))
        scholarship = intFile.getYamlParms(('GK', 'scholarships'))
        '''从参数文件获取参数'''
        mobile = DataSource().getMobile()
        idCard = DataSource().getIdcard()
        pfsnLevel = intFile.getYamlParms(('GK', 'pfsnLevel'))
        '''将参数组合到接口文件'''
        values = (str(grade), str(recruitType), str(scholarship), str(city),
                  str(unvsId), str(feeList), str(pfsnCode), str(pfsnId),
                  str(pfsnName), str(taId), str(taName), mobile, idCard,
                  str(pfsnLevel), str(feeId))
        keys = (('data', 'grade'), ('data', 'recruitType'), ('data',
                                                             'scholarship'),
                ('data', 'city'), ('data', 'unvsId'), ('data', 'feeList'),
                ('data', 'pfsnCode'), ('data', 'pfsnId'), ('data', 'pfsnName'),
                ('data', 'taId'), ('data', 'taName'), ('data', 'mobile'),
                ('data', 'idCard'), ('data', 'pfsnLevel'), ('data', 'feeId'))
        case = TestCaseAssembly().setAipParam('GrecruitAdd', values, keys)
        data = MultipartEncoder(fields=case[3])
        headers = {'Content-Type': ''}
        headers["Content-Type"] = data.content_type
        response = self.session.post(url=case[2], data=data, headers=headers)
        if response.status_code == 200:
            print("gkregister success")
        else:
            print("gkregister fails")

    def on_stop(self):
        print("=============================")
示例#26
0
 def post(self):
   session = HttpSession(self.base_url)
   reservation_response = session.post('/prod/insert-product', data=body)