예제 #1
0
    def test_extend_with_api(self):
        loader.load_project_tests(os.path.join(os.getcwd(), "tests"))
        raw_testinfo = {
            "name": "get token",
            "base_url": "https://debugtalk.com",
            "api": "api/get_token.yml",
        }
        api_def_dict = loader.load_teststep(raw_testinfo)
        test_block = {
            "name": "override block",
            "times": 3,
            "variables": [
                {"var": 123}
            ],
            "base_url": "https://httprunner.org",
            'request': {
                'url': '/api/get-token',
                'method': 'POST',
                'headers': {'user_agent': '$user_agent', 'device_sn': '$device_sn', 'os_platform': '$os_platform', 'app_version': '$app_version'},
                'json': {'sign': '${get_sign($user_agent, $device_sn, $os_platform, $app_version)}'}
            },
            'validate': [
                {'eq': ['status_code', 201]},
                {'len_eq': ['content.token', 32]}
            ]
        }

        extended_block = parser._extend_with_api(test_block, api_def_dict)
        self.assertEqual(extended_block["base_url"], "https://debugtalk.com")
        self.assertEqual(extended_block["name"], "override block")
        self.assertEqual({'var': 123}, extended_block["variables"])
        self.assertIn({'check': 'status_code', 'expect': 201, 'comparator': 'eq'}, extended_block["validate"])
        self.assertIn({'check': 'content.token', 'comparator': 'len_eq', 'expect': 32}, extended_block["validate"])
        self.assertEqual(extended_block["times"], 3)
예제 #2
0
 def test_load_teststep_api(self):
     raw_test = {
         "name": "create user (override).",
         "api": "api/create_user.yml",
         "variables": [{
             "uid": "999"
         }]
     }
     teststep = loader.load_teststep(raw_test)
     self.assertEqual("create user (override).", teststep["name"])
     self.assertIn("api_def", teststep)
     api_def = teststep["api_def"]
     self.assertEqual(api_def["name"], "create user")
     self.assertEqual(api_def["request"]["url"], "/api/users/$uid")
예제 #3
0
 def test_load_teststep_testcase(self):
     raw_test = {
         "name": "setup and reset all (override).",
         "testcase": "testcases/setup.yml",
         "variables": [{
             "device_sn": "$device_sn"
         }]
     }
     testcase = loader.load_teststep(raw_test)
     self.assertEqual("setup and reset all (override).", testcase["name"])
     tests = testcase["testcase_def"]["teststeps"]
     self.assertEqual(len(tests), 2)
     self.assertEqual(tests[0]["name"], "get token (setup)")
     self.assertEqual(tests[1]["name"], "reset all users")