class GetVoteListExportIdListOmOfficial(HttpRunner): """ Call api 'getVoteList' to add a new vote. Config Variables: - client (Client), required - account_om (Client), required - token_om (Client), required - publish_user_id (str), required - club_name (str), required - club_icon_url (str), required - club_desc (str), required - display_flag (bool), required """ config = (Config("后台获取投票列表并提取官方发布的投票Id").variables( **{ "account_id": "$account_id_om", "token": "$token_om", "page_size": 20, "page_no": 1 }).export("vote_id_list")) teststeps = [ Step(RunApiGetVoteList().request().extract().with_jmespath( "body.result.voteInfoList[?publishUserNickname=='linktestcommunity2_offical'].clubContentId", "vote_id_list").validate().assert_equal("body.code", 0)) ]
class GetFirmwareUpdateState(HttpRunner): """ Call api 'getFirmwareStatusList' to get firmware update state. Config Variables: - client (Client): required - account_id (int): required - token (str): required - cid (str): required - firmware_name (str): required Export Variables: - update_state (int) """ config = ( Config("调用 /cloud/v1/deviceManaged/getFirmwareStatusList 接口查询固件升级状态" ).export("update_state")) teststeps = [ Step(RunApiGetFirmwareStatusList().with_variables( cid_firmware_list=[{ "cid": "$cid", "pluginName": "$firmware_name" }]).request().extract().with_jmespath( jmespath, "update_state").validate().assert_equal("body.code", 0)), ]
class UpdateLikeV2(HttpRunner): """ Call api 'updateLikeV2' and make code 0 assertion. Config Variables: - client (Client): required - account_id (int): required - token (str): required - like_id (int): required - hue (int): required - saturation (int): required - value (int) :required """ config = ( Config("调用updateLikeV2接口更新特定灯光id的灯光参数") ) teststeps = [ Step( RunApiUpdateLikeV2() .request() .validate() .assert_equal("body.code", 0) ) ]
class LogOut(HttpRunner): """ Log out. Config Vars: - account_id (int): required - token (str): required - client (Client): optional, default to "${ios()}" - terms_status (bool): optional, default to True - gdpr_status (bool): optional, default to True - registration_token (str): optional, default to None """ config = (Config("用户登出").variables( **{ "client": "${ios()}", "terms_status": True, "gdpr_status": True, "registration_token": None })) teststeps = [ Step(RunApiLogout().request().update_json_object({ "termsStatus": "$terms_status", "gdprStatus": "$gdpr_status", "registrationToken": "$registration_token" }).validate().assert_equal("body.code", 0)) ]
class GetUserInfoList(HttpRunner): """ Call api 'getUserInfoList', extract and export total number. Config Variables: - client (Client): required - account_id (int): required - token (str): required - page_no (int): optional, default to 1 - page_size (str): optional, default to 10 Export Vars: - total (int) """ config = (Config("工厂用户管理-获取用户列表").variables(**{ "page_size": 10, "page_no": 1 })) teststeps = [ Step(RunApiGetUserInfoList().request().extract().with_jmespath( "body.result.total", "total").validate().assert_equal("body.code", 0)), ]
class GetOperationUserInfoList(HttpRunner): """ Call api 'getOperationUserInfoList' to export operation user id. Config Variables: - client (Client): required - account_id_om (str): required - token_om (str): required Export Variables: - operation_user_account_id (str): required """ config = (Config("获取运营后台用户列表并提取accountid").variables(**{ "account_id": "$account_id_om", "token": "$token_om" }).export("operation_user_account_id")) teststeps = [ Step(RunApiGetOperationUserInfoList().request().extract( ).with_jmespath( "body.result.operationUserInfoList[?nickName==\'linktestcommunity2_offical\'].appAccountID | [0]", "operation_user_account_id").validate().assert_equal( "body.code", 0)), ]
class DeleteStaff(HttpRunner): """ Call api 'deleteStaff' successfully. Config Variables: - account_id (int): required - token (string): required - client (Client): optional, default to "${web()}" - staff_id_list (list[int]): optional, default to [] """ config = ( Config("员工管理-删除员工账号") .variables(**{ "client": "${web()}", "staff_id_list": [] }) ) teststeps = [ Step( RunApiDeleteStaff() .request() .validate() .assert_equal("body.code", 0) ), ]
class UpdateClubContentRecommendStatus(HttpRunner): """ Call api 'updateClubContentStatus' to create a new club. Config Variables: - client (Client), required - account_om (Client), required - token_om (Client), required - id (int), required - top_position (str), required - top_order (int), required """ config = (Config("后台修改内容是否推荐状态").variables(**{ "account_id": "$account_id_om", "token": "$token_om" })) teststeps = [ Step(RunApiUpdateClubContentStatus().request().update_json_object({ "data": { "recommendStatus": "$recommend_status", } }).validate().assert_equal("body.code", 0)) ]
class Login(HttpRunner): """ Call api 'login' to log into production test tool (web), extract and export account_id, token. Config Variables: - client (Client): optional, default to "${web()}" - employee_id (str): required - password (str): required Export Variables: - account_id (str) - staff_id (str) - token (str) - menu (list[dict]) """ config = (Config("员工用户登陆产测工具").variables(**{ "client": "${web()}" }).export(*["account_id", "staff_id", "token", "menu"])) teststeps = [ Step(RunApiLogin().request().extract().with_jmespath( "body.result.accountID", "account_id").with_jmespath( "body.result.accountID", "staff_id").with_jmespath( "body.result.token", "token").with_jmespath( "body.result.menu", "menu").validate().assert_equal("body.code", 0)), ]
class WaitUntilLinkageLogListCorrect(HttpRunner): """ Polling until linkage List log were met. Config Variables: - client (Client): required - account_id (int): required - token (str): required - expected_log (list[dict]): required """ config = (Config("轮询获取联动日志并断言")) teststeps = [ Step(RunApiGetLinkageLog().retry_on_failure(10, 0.5).request( ).validate().assert_equal("body.code", 0).assert_json_contains( "body.result.linkageLogList[?linkageId==`$linkage_id`]", "$expected_log" ).assert_type_match( "body.result.linkageLogList[?linkageId==`$linkage_id`].actionList[*].actionLogId | [0][0]", int ).assert_type_match( "body.result.linkageLogList[?linkageId==`$linkage_id`].actionList[*].actionTime | [0][0]", int ).assert_type_match( "body.result.linkageLogList[?linkageId==`$linkage_id`].actionList[*].delayTimeSec | [0][0]", int ).assert_type_match( "body.result.linkageLogList[?linkageId==`$linkage_id`].logId | [0]", int ).assert_type_match( "body.result.linkageLogList[?linkageId==`$linkage_id`].executeTime | [0]", int)) ]
class TestCase查看拣货任务(HttpRunner): config = Config("testcase description").verify(False) teststeps = [ Step( RunRequest("/wms/piecepick/selectPage.do").post( "http://api.wms.jc-test.cn/wms/piecepick/selectPage.do"). with_headers( **{ "Accept": "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Content-Length": "54", "Content-Type": "application/x-www-form-urlencoded", "Host": "api.wms.jc-test.cn", "Origin": "http://pc.wms.jc-test.cn", "Referer": "http://pc.wms.jc-test.cn/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36", "loginToken": "17362313866PC269F5565F33DA9A750D44602B9A79FD7", "optDevice": "PC", }).with_data({ "reqParam": '{"pageNum":1,"pageSize":15}' }).validate().assert_equal("status_code", 200).assert_equal( 'headers."Content-Type"', "application/json;charset=UTF-8").assert_equal( "body.code", 200).assert_equal("body.msg", "成功!")), ]
class TestCaseGet_list(HttpRunner): """使用如下功能需要修改testcase中标记为2020.08.17新增""" _config = Config("list_get") _conf = _config.conf() _headers_get = _config.headers_get() _headers_post = _config.headers_post() _cookies = _config.cookies() config = _config.verify(False).variables(**_conf) teststeps = [ Step( RunRequest("/api/list/get").with_variables( **{ "length": "38", "referer": "https://${host}/list" }).post("https://${host}/api/list/get").with_headers( **{ "Content-Type": "${ContentType}", }, **_headers_post).with_cookies(**_cookies).with_data({ "folderId": "0", "sort": "time", "keywords": "", "source": "" }).validate().assert_equal( "status_code", 200).assert_equal("body.code", 0).assert_equal( "body.msg", None).assert_equal("body.data.documents[0].name", "欢迎使用幕布|入门指南")), ]
class TestCaseValidateWithFunctions(HttpRunner): config = ( Config("request methods testcase: validate with functions").variables( **{ "foo1": "session_bar1" }).base_url("https://postman-echo.com").verify(False)) teststeps = [ Step( RunRequest("get with params").with_variables( **{ "foo1": "bar1", "foo2": "session_bar2", "sum_v": "${sum_two(1, 2)}" }).get("/get").with_params(**{ "foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v" }).with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}" }).extract().with_jmespath( "body.args.foo2", "session_foo2").validate().assert_equal( "status_code", 200).assert_equal("body.args.sum_v", "3")), ]
class AssertGetLotteryAwardList(HttpRunner): """ Call api 'getLotteryAwardList' to assert the award list. Config Variables: - client (Client): required - account_id (str): required - token (str): required - awardPoolName (str): required - expected (list[dict]): required """ config = (Config("获取奖池信息并断言")) teststeps = [ Step(RunApiGetLotteryAwardList().request().validate().assert_equal( "body.code", 0).assert_json_contains( "body.result.awardList", anniversary_draw_settings.award_list).assert_json_equal( "body.result.awardList[*].awardShortName", anniversary_draw_settings.award_short).assert_json_equal( "body.result.awardList[*].awardFullName", anniversary_draw_settings.award).assert_type_match( "body.result.startTimestamp", int).assert_type_match("body.result.endTimestamp", int)), ]
class WaitUntilAppVersionUpdated(HttpRunner): """ Call api 'checkUserAppVersion' until version was updated to latest. Config Variables: - client (Client): required - account_id (int): required - token (str): required - expected_app_version (str): optional, default to "${getattr($client, client_version)}" """ config = ( Config("调用 /testSupport/v1/account/checkUserAppVersion 接口查看 app 版本" ).variables( **{ "expected_app_version": "${getattr($client, client_version)}" # type: str })) teststeps = [ Step( RunApi("checkUserAppVersion").retry_on_failure( polling_settings.times, polling_settings.interval).request().validate().assert_equal( "body.result.appVersion", "$expected_app_version")), ]
class TestCaseGetCandlestick(HttpRunner): @pytest.mark.parametrize("param", Parameters({"desc-params": "${read_yaml()}"})) def test_start(self, param): super().test_start(param) config = (Config("$desc").verify(False).base_url("${ENV(UAT_BASE_URL)")) teststeps = [ Step( RunRequest("/v2/public/get-candlestick").get( "v2/public/get-candlestick").with_params(**"$params"). with_headers( **{ "cache-control": "max-age=0", "sec-ch-ua": '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"', "sec-ch-ua-mobile": "?0", "upgrade-insecure-requests": "1", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "sec-fetch-site": "none", "sec-fetch-mode": "navigate", "sec-fetch-user": "******", "sec-fetch-dest": "document", "accept-encoding": "gzip, deflate, br", "accept-language": "zh-CN,zh;q=0.9", }).with_cookies(**{ "__cfduid": "dcb695eb677c5a40e841705ef79415c651617014441" }).validate().assert_equal("status_code", 200)), ]
class DirectAlexaUserToVesyncLoginPage(HttpRunner): """ Direct alexa user to vesync login page. Config Variables: - None """ config = (Config("打开供 Alexa app 使用的 VeSync 用户登录页面")) teststeps = [ Step( RunRequest("打开供 Alexa app 使用的 VeSync 用户登录页面").with_variables( **{ "api": "${get_api_from_orm_by_name(directAlexaUserToVesyncLoginPage)}" }).get("${getattr($api, url)}").with_params( **{ "client_id": alexa_settings.client_id, "redirect_uri": alexa_settings.redirect_uri, "response_type": "code", "scope": alexa_settings.scope, "state": "${generate_trace_id()}" }).validate().assert_equal("status_code", 200)), ]
class Online(HttpRunner): """ Call api 'online' to connect device to MQTT. Config Variables: - cid (str): required - sku (Sku): required - server_url (str): required """ config = ( Config("模拟设备上线").variables( **{ "cid": None, # type: str "sku": None, # type: Sku "server_url": None # type: str })) teststeps = [ Step( RunRequest("${getattr($api, name)}").with_variables( **{ "api": "${get_api_from_orm_by_name(online)}" }).setup_hook("${online($request, $sku, $server_url)}").post( "${getattr($api, url)}").with_params(**{ "cid": "$cid" }).with_json({}).validate().assert_equal("body.code", 0)), ]
class Connect(HttpRunner): """ Call api 'connect' to connect device to MQTT. Config Variables: - cid (str): required - sku (Sku): required - config_key (str): required - server_url (str): required """ config = ( Config("设备 connect").variables( **{ "cid": None, # type: str "sku": None, # type: Sku "config_key": None, # type: str "server_url": None # type: str })) teststeps = [ Step( RunRequest("设备连接 MQTT").with_variables(**{ "api": "${get_api_from_orm_by_name(connect)}" }).setup_hook( "${connect($request, $cid, $sku, $server_url, $config_key)}"). post("${getattr($api, url)}").with_params(**{ "cid": "$cid" }).with_json({}).validate().assert_equal("body.code", 0)), ]
class UpdateStaff(HttpRunner): """ Update staff. Config Vars: - account_id (int): required - token (str): required - id (int): required - employee_id (int): required - router_mac (str): required - can_test_product_ids (list[int]): required - name (str): optional, default to "$employee_id" - client (Client): optional, default to "${web()}" """ config = ( Config("修改 staff 信息") .variables(**{ "client": "${web()}", "name": "$employee_id" }) ) teststeps = [ Step( RunApiUpdateStaff() .request() .validate() .assert_equal("body.code", 0) ) ]
class AssertGetLotteryActivityInfo(HttpRunner): """ Call api 'getLotteryActivityInfo' to assert the awardList, activityTime, lotteryRecordList and taskList. Config Variables: - client (Client): required - account_id (str): required - award_pool_name (str): required - expected (list[dict]): required """ config = (Config("用户获取活动首页信息列表")) teststeps = [ Step(RunApiGetLotteryActivityInfo().request().validate().assert_equal( "body.code", 0).assert_json_contains( "body.result.awardList", "$expected_award_list").assert_json_contains( "body.result.taskList", "$expected_task_list"). assert_json_equal( "body.result.awardList[*].awardShortName", anniversary_draw_settings.award_short).assert_json_equal( "body.result.taskList[*].taskName", ["signUpActivity", "browseMall", "sharedActivityLink"])), ]
class GetPresetLinkage(HttpRunner): """ Call api 'getPresetLinkage' to get preset linkage list and assert Config Variables: - client (Client): required - account_id (int): required - token (str): required - sku (SKU): required - support_os (int): required 0:Android 1:all 2:iOS - showable (bool): optional 显示:true,不显示:false, 不传默认false - expected (list[dict]): optional 断言的json """ config = (Config("获取推荐联动").variables( **{ "showable": False, "config_model": "${getattr($sku, config_model)}" })) teststeps = [ Step(RunApiGetPresetLinkage().request().validate().assert_equal( "body.code", 0).assert_json_contains(jmespath_to_linkage, "$expected")) ]
class AssertContentListGotCorrect(HttpRunner): """ Call api 'getContentList' to assert content list om. Config Variables: - client (Client): required - account_id (str): required - token (str): required - content_id (int): required - $on_shelf_status (int): required """ config = ( Config("断言后台内容列表") .variables(**{ "account_id": "account_id_om", "token": "token_om", "start_timestamp": translate_datetime_to_timestamp(-1, 0, 0), "end_timestamp": translate_datetime_to_timestamp(1, 0, 0), "time_sort_type": 1, "page_no": 1, "page_size": 20 }) ) teststeps = [ Step( RunApiGetContentList() .request() .validate() .assert_equal("body.code", 0) .assert_json_contains("$jmes_path", "$expected") ), ]
class CommonSubmitOrder(HttpRunner): """ Implementing logic 'common submit order' of api 'submitOrder'. Config Variables: - client (Client): required - account_id (int): required - token (str): required - address_id (int): required - product_infos (list[dic]): required - coupon_id (int): optional, default=None - order_source (int): required - required_postage (int): required """ config = ( Config("调用接口 /vmall/v1/order/submitOrder 通过普通订单下单") .variables( **{ "coupon_id": None } ) .export("order_id") ) teststeps = [ Step( RunApiSubmitOrder() .request() .extract() .with_jmespath("body.result.orderId", "order_id") .validate() .assert_equal("body.code", 0) ) ]
class AddPlan(HttpRunner): """ Call api 'addOrUpdatePlan' to add road map. Config Variables: - client (Client): required - account_id (str): required - token (str): required - title (str): required - description (str): required - pictureUrls (str): required,default to default_picture_list Export Variables: - plan_id (int) """ config = (Config("添加规划").variables(**{ "picture_urls": default_picture_list }).export("plan_id")) teststeps = [ Step(RunApiAddOrUpdatePlan().request().extract().with_jmespath( "body.result.planId", "plan_id").validate().assert_equal("body.code", 0)), ]
class DeleteDevice(HttpRunner): """ Call api 'deleteDevice' and delete device. Config Variables: - client (Client): required - token (str): required - account_id (int): required - device_id (str): required """ config = ( Config("调用deleteDevice接口,删除公寓设备") .variables( ) ) teststeps = [ Step( RunApiDeleteDevice() .request() .validate() .assert_equal("body.code", 0) ), ]
class WaitUntilFirmwareUpdateStateRight(HttpRunner): """ Call api 'getFirmwareStatusList' until firmware update state is right. Config Variables: - client (Client): required - account_id (int): required - token (str): required - cid (str): required - firmware_name (str): required - expected_update_state (int): required """ config = ( Config("轮询 /cloud/v1/deviceManaged/getFirmwareStatusList 接口直到升级状态正确")) teststeps = [ Step(RunApiGetFirmwareStatusList().retry_on_failure( polling_settings.times, polling_settings.interval).with_variables( cid_firmware_list=[{ "cid": "$cid", "pluginName": "$firmware_name" }]).request().validate().assert_equal( "body.code", 0).assert_equal(jmespath, "$expected_update_state")), ]
class TestPublishABVersionPublicBetaBill(HttpRunner): random_str = ''.join(random.sample(string.ascii_letters + string.digits, 8)) config = (Config("P-提交A/B版本公测单成功,返回中提取公测单beta_id").variables( beta_title="test_title_" + random_str, beta_desc="test_descriptor_" + random_str, start_timestamp="${translate_datetime_to_timestamp(3,0,0)}", end_timestamp="${translate_datetime_to_timestamp(10,0,0)}", publish_type=1, phone_os="iOS", package_version_a="0.0.10", package_version_b="0.0.11", link_url_a="https://yapi.vesync.com/project/65/interface/api/8434", link_url_b="https://yapi.vesync.com/project/65/interface/api/8434", max_download_a=10000, max_download_b=10000, popup_desc="test_popup_desc_" + random_str, countries="US", target_user_group="test_group", estimate_popup_count=1000, plan_popup_count=800, test_audit_id=23, product_audit_id=42, operation_audit_id=41, creator_id=24, deal_type="publish").export("beta_id")) teststeps = [ Step( RunTestCase("调用 addOrUpdatePublicBetaBill 接口提交 Single 版本的公测单成功"). call(PublishABVersionPublicBetaBill).export("beta_id")) ]
class AssertClubContentListOm(HttpRunner): """ Call api 'getRecommendClubContentList' to get recommend club content list. Config Variables: - client (Client): required - account_id_om (str): required - token_om (str): required - club_content_id (int): required """ config = ( Config("后台获取圈子内容列表并断言") .variables(**{ "account_id": "$account_id_om", "token": "$token_om", "page_size": 20, "page_no": 1 }) ) teststeps = [ Step( RunApiGetClubContentListOm() .request() .validate() .assert_equal("body.code", 0) .assert_json_contains("$jmes_path", "$expected") ), ]
class GetVoteListExportIdOm(HttpRunner): """ Call api 'insertOrUpdateVote' to add a new vote. Config Variables: - client (Client), required - account_om (Client), required - token_om (Client), required - publish_user_id (str), required - club_name (str), required - club_icon_url (str), required - club_desc (str), required - display_flag (bool), required """ config = (Config("后台获取投票列表并提取新增的投票Id").variables(**{ "account_id": "$account_id_om", "token": "$token_om" })) teststeps = [ Step(RunApiGetVoteList().request().validate().assert_equal( "body.code", 0)) ]