Пример #1
0
 def test_app_login_SMS(self):
     """短信快捷登录"""
     phone = user_login['username']
     url_get_SMS = self.ym + '/app/user/getLoginAuthCode.html'
     data_get_SMS = {'phone': phone}
     res_get_SMS = self.session.request(method='post',
                                        url=url_get_SMS,
                                        params=dict(self.signature,
                                                    **data_get_SMS))
     print()
     # print(dict(self.signature, **data_get_SMS))
     # pprint(res_get_SMS.json())
     self.assertEqual('9999', res_get_SMS.json()['res_code'])
     with UseDataBase() as cursor:
         sql_verify_code = "SELECT receive_user, receive_addr, `code` from rd_notice where receive_addr = %s and nid = 'login_auth_code' ORDER BY id DESC limit 1;"
         cursor.execute(sql_verify_code, args=(phone, ))
         contents = cursor.fetchall()
         # pprint(contents)
         if contents:
             verify_code = contents[-1]['code']
         else:
             raise Exception('数据库内没有验证码记录')
         url_login_authcode = self.ym + '/app/user/loginByAuthCode.html'
         data_login_authcode = {
             'phone': phone,
             'authCode': verify_code,
         }
         data_login_authcode = dict(data_login_authcode, **self.signature)
         res_login_authcode = self.session.request(
             method='post',
             url=url_login_authcode,
             params=data_login_authcode)
         pprint(res_login_authcode.json())
         self.assertEqual('登录成功', res_login_authcode.json()['res_msg'])
Пример #2
0
 def tearDown(self):
     sql_user_id = 'select user_id from rd_user where mobile_phone = %s'
     with UseDataBase() as cursor:
         cursor.execute(sql_user_id, args=(user_register['username'], ))
         contents = cursor.fetchall()
         if contents:
             user_id = contents[-1]['user_id']
             sql_delete_user = '******'
             sql_delete_account = 'DELETE FROM rd_account where user_id = %s'
             cursor.execute(sql_delete_user, args=(user_id, ))
             cursor.execute(sql_delete_account, args=(user_id, ))
Пример #3
0
    def test_article_query(self):
        """文章查询"""
        url = self.ip + '/cms/article/query/enableArticles'
        menuCode = {
            'site_notice': '网站公告',  # 图片类型
            'media_report': '媒体报道',
        }
        data_search_article = {
            'menuCode': '',
            'pageIndex': '1',
            'pageSize': '5',
        }

        for k, v in menuCode.items():
            print(v + ': ')
            data_search_article['menuCode'] = k
            res = self.session.request(method='get',
                                       url=url,
                                       params=data_search_article)
            self.assertEqual(200, res.status_code)
            articles = res.json()['data'][k]['articleDtoList']
            num = 0
            for article in articles:
                pprint(article)
                # print('-----------------------------------------------------------------------------------------------------------------------------')
                num += 1  # 统计出 接口返回的列表内有几条数据
            sql = "SELECT COUNT(*) AS NUM from tn_cms_article where menu_code = %s;"
            with UseDataBase() as cursor:
                cursor.execute(sql, args=(k, ))
                contents = cursor.fetchall()
            sql_num = contents[-1]['NUM']  # sql_num:数据库中的条数;num:接口返回的条数
            print('sql_num数据库中的总条数:', sql_num)

            pagesize = int(data_search_article['pageSize'])  # 每页想要的条数
            pageindex = int(
                data_search_article['pageIndex'])  # 接口传参-【想要】显示的是第几页
            sql_index = int(sql_num / pagesize)  # 算出能全显示条数的页数
            print('sql_index能全显示条数的页数:', sql_index)
            print('pagesize想要显示几条数据:', pagesize)
            yushu = int(sql_num % pagesize)
            print('余数:', yushu)

            if k == 'media_report':
                if yushu != 0 and (
                        pageindex - sql_index
                ) == 1:  # 逻辑:以数据库查出14条数据为例,请求参数为每页5条数据,那么第一第二页都能按照要求显示5条,但最后一页就只能显示最后剩下的4条
                    self.assertEqual(yushu, num)
                elif (pageindex - sql_index) > 1:  # 超过最后一页的页数时,空列表
                    self.assertEqual(0, num)
                else:
                    self.assertEqual(pagesize, num)
Пример #4
0
def borr_timelimit():
    """查询现有的可投状态的标的天数,随机生成标的天数,确保发标必定在前端页面上出现【可供后续投资用】"""
    with UseDataBase() as cursor:
        sql = "SELECT `name`, `status`, category, time_limit FROM rd_borrow WHERE `status` = 1;"
        cursor.execute(sql)
        contents = cursor.fetchall()
        time_limit = set()
        for borr in contents:
            time_limit.add(borr['time_limit'])
        x = random.randint(31, 360)
        while x <= 360:
            if x in time_limit:
                x = random.randint(31, 360)
            else:
                print('最终生成的随机标的天数为:', x)
                break
        return x
Пример #5
0
    def test_recommended_product(self):
        """有推荐标时检查推荐标列表是否为空"""
        url_index = 'https://www-t.jfcaifu.com/app/v500/index.html'
        data_index = self.signature.copy()
        data_index['user_id'] = self.login().json()['res_data']['user_id']
        res_recommend = self.session.request(method='get', url=url_index, params= data_index,)
        if res_recommend.status_code == 200:
            rec_pro = res_recommend.json()['res_data']['fixBorrowList']
            pprint(rec_pro)
        else:
            raise Exception('首页接口翻车')

        with UseDataBase() as cursor:
            _sql = "SELECT * from rd_borrow where `status` = 1 and is_recommend = 1;"
            cursor.execute(_sql)
            contents = cursor.fetchall()
        if contents:
            self.assertNotEqual([], rec_pro)
Пример #6
0
    def test_register_without_channelcode(self):
        """注册活动(带渠道码)"""
        session = self.session
        path_register = '/activity/flying.html'
        path_code = '/wap/user/getActivityCode.html'

        channelCode = '40409'
        response_code = session.request(method='post', params={'mobilePhone': self.register_phone}, url=self.yuming + path_code)
        if response_code.status_code == 200:
            print('获取验证码接口:', end=' ')
            pprint(response_code.json())
        else:
            print('验证码接口翻车!!!')

        data_login = {'channelCode': channelCode,
                      'pwd': self.register_pwd,
                      'mobilePhone': self.register_phone,
                      'code': '888888'}
        response_login = session.request(method='get', url=self.yuming + path_register, params=data_login)
        if response_login.status_code == 200:
            self.assertEqual('领取成功!', response_login.json()['msg'])
            print('注册接口返回json:', end=' ')
            pprint(response_login.json())
            with UseDataBase() as cursor:
                # _SQL = "select user_id, user_name, pwd, mobile_phone, channel_type from rd_user where mobile_phone = %s" % self.phone
                # cursor.execute(_SQL)

                _SQL = "select user_id, user_name, pwd, mobile_phone, channel_type from rd_user where mobile_phone = %s"
                cursor.execute(_SQL, args=(self.register_phone))

                contents = cursor.fetchall()
                print('contents: ', contents)
                for data in contents:
                    print('注册用户sql信息:')
                    pprint(data)

                res_login = self.login(phone=self.register_phone, pwd=self.register_pwd)
                pprint(res_login.json())
                self.assertEqual(res_login.status_code, 200)
                self.assertEqual('登录成功!', res_login.json()['msg'])          # 验证一下 注册成功后的账号能否正常登陆

        else:
            raise Exception('注册流程失败')
Пример #7
0
 def tearDown(self):
     with UseDataBase() as cursor:
         cursor.execute("DELETE from rd_user where mobile_phone = %s", args=(self.register_phone,))
         cursor.execute("DELETE from rd_notice where receive_addr = %s and nid = 'notice_reg';",
                        args=(self.register_phone,))
Пример #8
0
    def test_picture_query(self):
        """图片查询"""
        url = self.ip + '/cms/images/queryEnableImages'
        data = {
            'source': 'baidu',
        }
        imageTypes = {
            'index_loop_banner_mb': '移动首页轮播图',
            'index_float_icon_mb': '移动首页悬浮ICON图',
            'index_up_banner_mb': '首页固定图(上)',
            'index_down_banner_mb': '首页固定图(下)',
            'index_bank_manage_banner': '首页银行存管图',
            'prd_loop_banner_mb': '产品轮播图',
            'find_loop_banner_mb': '发现页轮播图',
            'find_center_banner': '发现页央企图',
            'find_icon_mb': '发现页icon图',
            'app_start_banner': 'app启动图',
        }  # 各个参数值代表的含义
        print(
            '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~传source(渠道号)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        )
        for k, v in imageTypes.items():
            data['imageTypes'] = k
            print('传参: ', data)
            res = self.session.request(method='post', url=url, params=data)
            self.assertEqual(200, res.status_code, msg='响应状态码非200!')
            pprint(res.json())
            dt = res.json()['data']  # 图片数据字典

            if dt:  #检查是否是空字典
                try:
                    with UseDataBase() as cursor:
                        sql = "SELECT * from tn_cms_images where hide_time > NOW() and show_time < NOW() and apply_status = 1 and image_type = %s;"
                        cursor.execute(sql, args=(k, ))
                        contents = cursor.fetchall()
                        if contents:
                            self.assertNotEqual([],
                                                dt[k],
                                                msg='数据库有数据,但是给的列表为空!')

                except Exception as err:
                    raise Exception(err)
            print(
                '===============================================以上是【' + v +
                '】的内容========================================================='
            )

        print()
        print()
        print(
            '************************************不传source(渠道号)******************************************'
        )
        for k, v in imageTypes.items():
            data_kong = {}
            data_kong['imageTypes'] = k
            print('传参: ', data_kong)
            res_kong = self.session.request(method='post',
                                            url=url,
                                            params=data_kong)
            self.assertEqual(200, res_kong.status_code, msg='响应状态码非200!')
            pprint(res_kong.json())
            dt_kong = res_kong.json()['data']  # 图片数据字典
            if dt_kong:
                try:
                    with UseDataBase() as cursor:
                        sql = "SELECT * from tn_cms_images where hide_time > NOW() and show_time < NOW() and apply_status = 1 and image_type = %s and source is NULL ;"
                        cursor.execute(sql, args=(k, ))
                        contents = cursor.fetchall()
                        if contents:
                            self.assertNotEqual([],
                                                dt_kong[k],
                                                msg='数据库有数据,但是给的列表为空!')

                except Exception as err:
                    raise Exception(err)
            print(
                '===============================================以上是【' + v +
                '】的内容========================================================='
            )
Пример #9
0
    def test_Fabiao(self):
        """发标"""
        driver = self.driver
        try:
            self.login()
            for x in driver.find_elements_by_css_selector(
                    '.panel-title.panel-with-icon'):
                if x.text == '借贷管理':
                    x.click()
            time.sleep(2)
            driver.find_element_by_partial_link_text(u'借款初审').click()
            # ===============================================================================================================================================
            iframe_jiekuanchushen = 'src="/modules/loan/borrow/verifyBorrowManager.html"'
            driver.switch_to.frame(
                driver.find_element_by_css_selector(
                    '[%s]' % iframe_jiekuanchushen))  # 跳转到借款初审页面的iframe框架内
            driver.find_element_by_id("a").click()  # 发标
            time.sleep(1)

            iframe_tankuang = 'src="/modules/loan/borrow/borrowAddPage.html?type=112"'
            driver.switch_to.frame(
                driver.find_element_by_css_selector(
                    '[%s]' % iframe_tankuang))  # 跳转到弹框页面(ifram嵌套,从第一层跳到第二层)
            # -----------------------------------发标表单------------------------------------------------------------------------------------------------------

            type = driver.find_elements_by_css_selector(
                '.layui-unselect.layui-form-radio')
            for a in type:  # 标的类型
                if a.text[1:] == self.config['type']:
                    a.click()

            activity_list = self.config['activity']  # 运营活动
            activity = driver.find_elements_by_css_selector(
                '.layui-unselect.layui-form-checkbox')
            for a in activity:
                if a.text.split('\n')[0] in activity_list:
                    a.click()
            print('--------------------------------------------')

            if self.config['is_recommend'] != '置顶':
                pass
            else:
                driver.find_element_by_css_selector(
                    '[placeholder="不置顶"]').click()
                time.sleep(1)
                top = driver.find_elements_by_css_selector('[lay-value="1"]')
                for i in top:
                    if i.text[:2] == '置顶':
                        i.click()

            driver.find_element_by_id("ads").send_keys(self.config['bm'])  # 标名
            driver.find_element_by_css_selector('[name="borrowNo"]').send_keys(
                self.config['product_number'])  # 项目编号

            if self.config['type'] != '新手标':
                red_path = '//*[@lay-value="%s"]' % self.config['redpacket']
                coupon_path = '//*[@lay-value="%s"]' % self.config['coupon']
                if self.config['redpacket'] != '':
                    driver.find_element_by_css_selector(
                        '[value="请选择红包方案"]').click()  # 弹出红包方案下拉框
                    time.sleep(0.5)
                    driver.find_element_by_xpath(red_path).click()

                if self.config['coupon'] != '':
                    driver.find_element_by_css_selector(
                        '[value="请选择加息券方案"]').click()  # 弹出加息券方案下拉框
                    time.sleep(0.5)
                    driver.find_element_by_xpath(coupon_path).click()
            else:
                pass

            driver.find_element_by_id("account").send_keys(
                self.config['money'])  # 标的金额
            driver.find_element_by_id("apr").send_keys(
                self.config['apr'])  # 年利率
            driver.find_element_by_id("timeLimit").send_keys(
                self.config['timelimit'])  # 标的天数
            if self.config['increaseRate'] == 0:
                pass
            else:
                driver.find_element_by_css_selector(
                    '[placeholder="请填写加息比例"]').clear()
                driver.find_element_by_css_selector(
                    '[placeholder="请填写加息比例"]').send_keys(
                        self.config['increaseRate'])  # 显示加息率
            driver.find_element_by_id("putStartTime").click()  # 开标时间
            driver.find_element_by_xpath(".//*[@id='laydate_ok']").click()
            time.sleep(0.5)

            paytype = self.config['paytype']
            if paytype == '一次性还款':
                try:
                    driver.find_element_by_css_selector(
                        '[value="10天派息1次"]').click()
                    time.sleep(0.5)

                    chq = driver.find_elements_by_css_selector(
                        '.layui-anim.layui-anim-upbit>dd')
                    for a in chq:
                        if a.text == paytype:
                            a.click()
                except Exception as err:
                    print(err)
            else:
                print('当前发标配置属性选择为10天派息,默认为10天派息,不进行更改')

            # huankuan = WebDriverWait(driver, 2, 0.5).until(
            #     EC.presence_of_element_located((By.CSS_SELECTOR, '[value="一次性还款"]')))

            driver.find_element_by_xpath("//*[@placeholder='请选择客服']").click()
            time.sleep(0.5)
            driver.find_element_by_xpath(
                "//*[@lay-value='kefu123']").click()  # 客服
            driver.find_element_by_xpath(
                '//*[@placeholder="请选择借款人邮箱"]').click()
            time.sleep(0.5)
            driver.find_element_by_xpath(
                "//*[@lay-value='*****@*****.**']").click()  # 借款人
            driver.find_element_by_xpath(
                "//*[@lay-filter='save']").click()  # 确定,创建标完成
            time.sleep(4)

            # =========================================初审=========================================================================
            driver.switch_to.default_content()  # 切回主菜单
            driver.switch_to.frame(
                driver.find_element_by_css_selector(
                    '[%s]' % iframe_jiekuanchushen))  # 跳转到借款初审页面的iframe框架内
            above = driver.find_element_by_css_selector(
                '.datagrid-cell.datagrid-cell-c1-action')
            ActionChains(driver).move_to_element(
                above).perform()  # 悬停在“操作栏”,展开选项
            time.sleep(1)
            driver.find_element_by_link_text(u'初审').click()
            driver.switch_to.default_content()
            time.sleep(1)
            check_status = self.config['check_status']
            if check_status == '通过':
                driver.find_element_by_css_selector('[value="1"]').click()
            elif check_status == '不通过':
                driver.find_element_by_css_selector('[value="0"]').click()
            else:
                driver.find_element_by_css_selector('[value="101"]').click()
            driver.find_element_by_link_text(u"确定").click()  # 建标完成
            time.sleep(2)
            driver.find_element_by_link_text(u"确定").click()  # 关闭弹窗:操作成功!
            time.sleep(2)
        except Exception as err:
            picture_path = parent_dir + '/Picture'
            filename = picture_path + '/%s.jpg' % time.strftime(
                "%Y.%m.%d %H.%M.%S", time.localtime())
            print('出错时的截图: ', filename)
            driver.save_screenshot(filename)
            print(err)
            raise Exception(err)
        with UseDataBase() as cursor:
            sql = "select `name`, `status`, time_limit from rd_borrow where `status` = 1 and time_limit = %s and `name` = %s;"
            cursor.execute(sql,
                           args=(
                               self.config['timelimit'],
                               self.config['bm'],
                           ))
            contents = cursor.fetchall()
            try:
                borr = contents[-1]
                want_data = {
                    'name': self.config['bm'],
                    'status': 1,
                    'time_limit': self.config['timelimit']
                }
                self.assertEqual(want_data, borr)
            except Exception as err:
                raise Exception('数组越界,sql查询标的结果为空(发标失败):', err)