mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +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 yaml
|
||||
import os.path
|
||||
import random
|
||||
import string
|
||||
|
||||
import yaml
|
||||
|
||||
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):
|
||||
with open(yaml_file, 'r+') as stream:
|
||||
return yaml.load(stream)
|
||||
|
||||
10
test/base.py
10
test/base.py
@@ -1,10 +1,8 @@
|
||||
import hashlib
|
||||
import multiprocessing
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from ate import utils
|
||||
from . import api_server
|
||||
|
||||
|
||||
@@ -29,11 +27,9 @@ class ApiServerUnittest(unittest.TestCase):
|
||||
|
||||
def prepare_headers(self, data=""):
|
||||
token = api_server.TOKEN
|
||||
random_str = ''.join(
|
||||
random.choice(string.ascii_uppercase + string.digits) for _ in range(5))
|
||||
random_str = utils.gen_random_string(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 = {
|
||||
'authorization': authorization,
|
||||
'random': random_str
|
||||
|
||||
Reference in New Issue
Block a user