mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 07:21:23 +08:00
move public functions to utils.py
This commit is contained in:
16
ate/utils.py
16
ate/utils.py
@@ -1,8 +1,22 @@
|
|||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import yaml
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
from ate.exception import ParamsError
|
from ate.exception import ParamsError
|
||||||
|
|
||||||
|
|
||||||
|
def gen_random_string(str_len):
|
||||||
|
return ''.join(
|
||||||
|
random.choice(string.ascii_letters + string.digits) for _ in range(str_len))
|
||||||
|
|
||||||
|
def gen_md5(str_list):
|
||||||
|
authorization_str = "".join(str_list)
|
||||||
|
return hashlib.md5(authorization_str.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
def load_yaml_file(yaml_file):
|
def load_yaml_file(yaml_file):
|
||||||
with open(yaml_file, 'r+') as stream:
|
with open(yaml_file, 'r+') as stream:
|
||||||
return yaml.load(stream)
|
return yaml.load(stream)
|
||||||
|
|||||||
10
test/base.py
10
test/base.py
@@ -1,10 +1,8 @@
|
|||||||
import hashlib
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import random
|
|
||||||
import string
|
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from ate import utils
|
||||||
from . import api_server
|
from . import api_server
|
||||||
|
|
||||||
|
|
||||||
@@ -29,11 +27,9 @@ class ApiServerUnittest(unittest.TestCase):
|
|||||||
|
|
||||||
def prepare_headers(self, data=""):
|
def prepare_headers(self, data=""):
|
||||||
token = api_server.TOKEN
|
token = api_server.TOKEN
|
||||||
random_str = ''.join(
|
random_str = utils.gen_random_string(5)
|
||||||
random.choice(string.ascii_uppercase + string.digits) for _ in range(5))
|
authorization = utils.gen_md5([token, data, random_str])
|
||||||
|
|
||||||
authorization_str = "".join([token, data, random_str])
|
|
||||||
authorization = hashlib.md5(authorization_str.encode('utf-8')).hexdigest()
|
|
||||||
headers = {
|
headers = {
|
||||||
'authorization': authorization,
|
'authorization': authorization,
|
||||||
'random': random_str
|
'random': random_str
|
||||||
|
|||||||
Reference in New Issue
Block a user