mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
change: remove unused imports
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
import os
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from httprunner import (__version__, exceptions, loader, logger, parser,
|
from httprunner import (__version__, exceptions, loader, logger, parser,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ Built-in dependent functions used in YAML/JSON testcases.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
@@ -13,10 +12,11 @@ import string
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import filetype
|
import filetype
|
||||||
from httprunner.compat import basestring, builtin_str, integer_types, str
|
|
||||||
from httprunner.exceptions import ParamsError
|
|
||||||
from requests_toolbelt import MultipartEncoder
|
from requests_toolbelt import MultipartEncoder
|
||||||
|
|
||||||
|
from httprunner.compat import basestring, builtin_str, integer_types
|
||||||
|
from httprunner.exceptions import ParamsError
|
||||||
|
|
||||||
PWD = os.getcwd()
|
PWD = os.getcwd()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import time
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
import urllib3
|
import urllib3
|
||||||
from httprunner import logger
|
|
||||||
from httprunner.utils import lower_dict_keys, omit_long_data
|
|
||||||
from requests import Request, Response
|
from requests import Request, Response
|
||||||
from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema,
|
from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema,
|
||||||
RequestException)
|
RequestException)
|
||||||
|
|
||||||
|
from httprunner import logger
|
||||||
|
from httprunner.utils import lower_dict_keys, omit_long_data
|
||||||
|
|
||||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import collections
|
|
||||||
import copy
|
|
||||||
import csv
|
import csv
|
||||||
import importlib
|
import importlib
|
||||||
import io
|
import io
|
||||||
@@ -8,7 +6,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from httprunner import built_in, exceptions, logger, parser, utils, validator
|
|
||||||
|
from httprunner import built_in, exceptions, logger, utils, validator
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# PyYAML version >= 5.1
|
# PyYAML version >= 5.1
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from httprunner.logger import color_print
|
from httprunner.logger import color_print
|
||||||
from httprunner import loader
|
|
||||||
|
|
||||||
|
|
||||||
def parse_locustfile(file_path):
|
def parse_locustfile(file_path):
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ from collections import Iterable
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from httprunner import __version__, loader, logger
|
|
||||||
from httprunner.compat import basestring, bytes, json, numeric_types
|
|
||||||
from jinja2 import Template, escape
|
from jinja2 import Template, escape
|
||||||
|
|
||||||
|
from httprunner import __version__, logger
|
||||||
|
from httprunner.compat import basestring, bytes, json, numeric_types
|
||||||
|
|
||||||
|
|
||||||
def get_platform():
|
def get_platform():
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
import json
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import jsonpath
|
import jsonpath
|
||||||
|
|
||||||
from httprunner import exceptions, logger, utils
|
from httprunner import exceptions, logger, utils
|
||||||
from httprunner.compat import OrderedDict, basestring, is_py2
|
from httprunner.compat import OrderedDict, basestring, is_py2
|
||||||
|
|
||||||
|
|
||||||
text_extractor_regexp_compile = re.compile(r".*\(.*\).*")
|
text_extractor_regexp_compile = re.compile(r".*\(.*\).*")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import itertools
|
|||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
import string
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from httprunner import exceptions, logger
|
from httprunner import exceptions, logger
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import types
|
|||||||
|
|
||||||
from httprunner import exceptions, logger
|
from httprunner import exceptions, logger
|
||||||
|
|
||||||
|
|
||||||
""" validate data format
|
""" validate data format
|
||||||
TODO: refactor with JSON schema validate
|
TODO: refactor with JSON schema validate
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def is_testcase(data_structure):
|
def is_testcase(data_structure):
|
||||||
""" check if data_structure is a testcase.
|
""" check if data_structure is a testcase.
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import json
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from flask import Flask, make_response, request
|
from flask import Flask, make_response, request
|
||||||
|
|
||||||
from httprunner.built_in import gen_random_string
|
from httprunner.built_in import gen_random_string
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -53,6 +54,7 @@ def get_sign(*args):
|
|||||||
sign = hmac.new(sign_key, content, hashlib.sha1).hexdigest()
|
sign = hmac.new(sign_key, content, hashlib.sha1).hexdigest()
|
||||||
return sign
|
return sign
|
||||||
|
|
||||||
|
|
||||||
def gen_md5(*args):
|
def gen_md5(*args):
|
||||||
return hashlib.md5("".join(args).encode('utf-8')).hexdigest()
|
return hashlib.md5("".join(args).encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ import time
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from tests.api_server import FLASK_APP_PORT, HTTPBIN_HOST, HTTPBIN_PORT
|
from tests.api_server import FLASK_APP_PORT, HTTPBIN_HOST, HTTPBIN_PORT
|
||||||
from tests.api_server import app as flask_app
|
from tests.api_server import app as flask_app
|
||||||
from tests.api_server import gen_md5, gen_random_string, get_sign, httpbin_app
|
from tests.api_server import gen_random_string, get_sign, httpbin_app
|
||||||
|
|
||||||
|
|
||||||
def run_flask():
|
def run_flask():
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
@@ -8,12 +7,15 @@ from tests.api_server import HTTPBIN_SERVER, gen_md5, get_sign
|
|||||||
|
|
||||||
BASE_URL = "http://127.0.0.1:5000"
|
BASE_URL = "http://127.0.0.1:5000"
|
||||||
|
|
||||||
|
|
||||||
def get_httpbin_server():
|
def get_httpbin_server():
|
||||||
return HTTPBIN_SERVER
|
return HTTPBIN_SERVER
|
||||||
|
|
||||||
|
|
||||||
def get_base_url():
|
def get_base_url():
|
||||||
return BASE_URL
|
return BASE_URL
|
||||||
|
|
||||||
|
|
||||||
def get_default_request():
|
def get_default_request():
|
||||||
return {
|
return {
|
||||||
"base_url": BASE_URL,
|
"base_url": BASE_URL,
|
||||||
@@ -22,9 +24,11 @@ def get_default_request():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def sum_two(m, n):
|
def sum_two(m, n):
|
||||||
return m + n
|
return m + n
|
||||||
|
|
||||||
|
|
||||||
def sum_status_code(status_code, expect_sum):
|
def sum_status_code(status_code, expect_sum):
|
||||||
""" sum status code digits
|
""" sum status code digits
|
||||||
e.g. 400 => 4, 201 => 3
|
e.g. 400 => 4, 201 => 3
|
||||||
@@ -35,34 +39,42 @@ def sum_status_code(status_code, expect_sum):
|
|||||||
|
|
||||||
assert sum_value == expect_sum
|
assert sum_value == expect_sum
|
||||||
|
|
||||||
|
|
||||||
def is_status_code_200(status_code):
|
def is_status_code_200(status_code):
|
||||||
return status_code == 200
|
return status_code == 200
|
||||||
|
|
||||||
|
|
||||||
os.environ["TEST_ENV"] = "PRODUCTION"
|
os.environ["TEST_ENV"] = "PRODUCTION"
|
||||||
|
|
||||||
|
|
||||||
def skip_test_in_production_env():
|
def skip_test_in_production_env():
|
||||||
""" skip this test in production environment
|
""" skip this test in production environment
|
||||||
"""
|
"""
|
||||||
return os.environ["TEST_ENV"] == "PRODUCTION"
|
return os.environ["TEST_ENV"] == "PRODUCTION"
|
||||||
|
|
||||||
|
|
||||||
def get_user_agent():
|
def get_user_agent():
|
||||||
return ["iOS/10.1", "iOS/10.2"]
|
return ["iOS/10.1", "iOS/10.2"]
|
||||||
|
|
||||||
|
|
||||||
def gen_app_version():
|
def gen_app_version():
|
||||||
return [
|
return [
|
||||||
{"app_version": "2.8.5"},
|
{"app_version": "2.8.5"},
|
||||||
{"app_version": "2.8.6"}
|
{"app_version": "2.8.6"}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_account():
|
def get_account():
|
||||||
return [
|
return [
|
||||||
{"username": "user1", "password": "111111"},
|
{"username": "user1", "password": "111111"},
|
||||||
{"username": "user2", "password": "222222"}
|
{"username": "user2", "password": "222222"}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_account_in_tuple():
|
def get_account_in_tuple():
|
||||||
return [("user1", "111111"), ("user2", "222222")]
|
return [("user1", "111111"), ("user2", "222222")]
|
||||||
|
|
||||||
|
|
||||||
def gen_random_string(str_len):
|
def gen_random_string(str_len):
|
||||||
random_char_list = []
|
random_char_list = []
|
||||||
for _ in range(str_len):
|
for _ in range(str_len):
|
||||||
@@ -72,12 +84,15 @@ def gen_random_string(str_len):
|
|||||||
random_string = ''.join(random_char_list)
|
random_string = ''.join(random_char_list)
|
||||||
return random_string
|
return random_string
|
||||||
|
|
||||||
|
|
||||||
def setup_hook_add_kwargs(request):
|
def setup_hook_add_kwargs(request):
|
||||||
request["key"] = "value"
|
request["key"] = "value"
|
||||||
|
|
||||||
|
|
||||||
def setup_hook_remove_kwargs(request):
|
def setup_hook_remove_kwargs(request):
|
||||||
request.pop("key")
|
request.pop("key")
|
||||||
|
|
||||||
|
|
||||||
def teardown_hook_sleep_N_secs(response, n_secs):
|
def teardown_hook_sleep_N_secs(response, n_secs):
|
||||||
""" sleep n seconds after request
|
""" sleep n seconds after request
|
||||||
"""
|
"""
|
||||||
@@ -86,12 +101,15 @@ def teardown_hook_sleep_N_secs(response, n_secs):
|
|||||||
else:
|
else:
|
||||||
time.sleep(n_secs)
|
time.sleep(n_secs)
|
||||||
|
|
||||||
|
|
||||||
def hook_print(msg):
|
def hook_print(msg):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
|
||||||
def modify_request_json(request, os_platform):
|
def modify_request_json(request, os_platform):
|
||||||
request["json"]["os_platform"] = os_platform
|
request["json"]["os_platform"] = os_platform
|
||||||
|
|
||||||
|
|
||||||
def setup_hook_httpntlmauth(request):
|
def setup_hook_httpntlmauth(request):
|
||||||
if "httpntlmauth" in request:
|
if "httpntlmauth" in request:
|
||||||
from requests_ntlm import HttpNtlmAuth
|
from requests_ntlm import HttpNtlmAuth
|
||||||
@@ -99,6 +117,7 @@ def setup_hook_httpntlmauth(request):
|
|||||||
request["auth"] = HttpNtlmAuth(
|
request["auth"] = HttpNtlmAuth(
|
||||||
auth_account["username"], auth_account["password"])
|
auth_account["username"], auth_account["password"])
|
||||||
|
|
||||||
|
|
||||||
def alter_response(response):
|
def alter_response(response):
|
||||||
response.status_code = 500
|
response.status_code = 500
|
||||||
response.headers["Content-Type"] = "html/text"
|
response.headers["Content-Type"] = "html/text"
|
||||||
@@ -108,6 +127,7 @@ def alter_response(response):
|
|||||||
"key": 123
|
"key": 123
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def alter_response_error(response):
|
def alter_response_error(response):
|
||||||
# NameError
|
# NameError
|
||||||
not_defined_variable
|
not_defined_variable
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import random
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from tests.base import ApiServerUnittest
|
from tests.base import ApiServerUnittest
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from httprunner.client import HttpSession
|
from httprunner.client import HttpSession
|
||||||
from httprunner.compat import bytes
|
|
||||||
from tests.api_server import HTTPBIN_SERVER
|
from tests.api_server import HTTPBIN_SERVER
|
||||||
from tests.base import ApiServerUnittest
|
from tests.base import ApiServerUnittest
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
|
||||||
|
|
||||||
from httprunner import context, exceptions, loader, parser, runner
|
from httprunner import context, exceptions, loader, parser, runner
|
||||||
from tests.base import ApiServerUnittest, gen_md5, gen_random_string
|
from tests.api_server import gen_md5
|
||||||
|
from tests.base import ApiServerUnittest, gen_random_string
|
||||||
|
|
||||||
|
|
||||||
class TestContext(ApiServerUnittest):
|
class TestContext(ApiServerUnittest):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from httprunner import exceptions, loader, validator
|
from httprunner import exceptions, loader
|
||||||
|
|
||||||
|
|
||||||
class TestFileLoader(unittest.TestCase):
|
class TestFileLoader(unittest.TestCase):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from httprunner import built_in, exceptions, loader, response
|
from httprunner import built_in, exceptions, loader, response
|
||||||
from httprunner.compat import basestring, bytes
|
from httprunner.compat import basestring, bytes
|
||||||
from tests.api_server import HTTPBIN_SERVER
|
from tests.api_server import HTTPBIN_SERVER
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import io
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from httprunner import exceptions, loader, parser, utils
|
from httprunner import exceptions, loader, utils
|
||||||
from tests.base import ApiServerUnittest
|
from tests.base import ApiServerUnittest
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user