Exemple #1
0
def cas_post(args):

    filename = os.path.join(args['file_path'], f'{uuid.uuid4()}.jpg')
    with open(filename, 'wb') as new_file:
        new_file.write(os.urandom(args['payload_size']))

    start = time.perf_counter()
    timestamp = datetime.datetime.now()
    req = args['req']
    sess = requests.session()
    sess.mount('http://', args['adapter'])
    resp = sess.request(req.method,
                        req.url,
                        params=req.params,
                        data=req.data,
                        headers=req.headers,
                        files=[('filename', filename)],
                        auth=req.auth,
                        cookies=req.cookies,
                        verify=req.verify,
                        timeout=30)
    resp.raise_for_status()
    elapsed = time.perf_counter() - start

    os.remove(filename)

    return request_generator.Result(req.url,
                                    resp.status_code,
                                    len(resp.content),
                                    timestamp=timestamp,
                                    elapsed_time=elapsed)
Exemple #2
0
def api_call(args):

    req = args['req']

    sess = requests.session()
    if req.http2:
        from hyper.contrib import HTTP20Adapter
        sess.mount('https://', HTTP20Adapter())

    timestamp = datetime.datetime.now()
    resp = sess.request(req.method,
                        req.url,
                        params=req.params,
                        data=req.data,
                        headers=req.headers,
                        files=req.files,
                        auth=req.auth,
                        cookies=req.cookies,
                        verify=req.verify)
    resp.raise_for_status()

    return request_generator.Result(req.url,
                                    resp.status_code,
                                    len(resp.content),
                                    timestamp=timestamp)
Exemple #3
0
def write_and_delete(args):

    filename = os.path.join(args['file_path'], f'{uuid.uuid4()}.jpg')
    with open(filename, 'wb') as new_file:
        new_file.write(os.urandom(args['payload_size']))
    os.remove(filename)

    return request_generator.Result(filename, 200, 0)
Exemple #4
0
def hooyu_get(args):
    req = args['req']
    sess = requests.session()
    sess.mount('http://', args['adapter'])
    resp = sess.request(req.method,
                        req.url,
                        params=req.params,
                        json=req.data,
                        headers=req.headers,
                        auth=req.auth,
                        cookies=req.cookies,
                        verify=req.verify)
    return request_generator.Result(req.url, resp.status_code,
                                    len(resp.content))
Exemple #5
0
def frontend_get_posts(args):
    req = args['req']
    sess = requests.session()
    sess.mount('http://', args['adapter'])
    resp = sess.request(req.method,
                        req.url,
                        params=req.params,
                        data=req.data,
                        headers=req.headers,
                        files=req.files,
                        auth=req.auth,
                        cookies=req.cookies,
                        verify=req.verify,
                        timeout=30)
    return request_generator.Result(req.url, resp.status_code,
                                    len(resp.content))
Exemple #6
0
def private_signing_post_transaction(args):
    json_data = {
        "transaction": {
            "actions": [{
                "account":
                "signup.b1",
                "name":
                "cnfrmphone",
                "authorization": [{
                    "actor": "signup.b1",
                    "permission": "active",
                }],
                "data": {
                    "reference": random.randint(0, 1000000),
                }
            }]
        }
    }
    start = time.perf_counter()
    timestamp = datetime.datetime.now()
    req = args['req']
    sess = requests.session()
    sess.mount('http://', args['adapter'])
    resp = sess.request(req.method,
                        req.url,
                        params=req.params,
                        json=json_data,
                        headers=req.headers,
                        files=None,
                        auth=req.auth,
                        cookies=req.cookies,
                        verify=req.verify,
                        timeout=5)
    resp.raise_for_status()
    elapsed = time.perf_counter() - start

    return request_generator.Result(req.url,
                                    resp.status_code,
                                    len(resp.content),
                                    timestamp=timestamp,
                                    elapsed_time=elapsed)
Exemple #7
0
def cas_get(args):
    start = time.perf_counter()
    timestamp = datetime.datetime.now()
    req = args['req']
    sess = requests.session()
    sess.mount('http://', args['adapter'])
    resp = sess.request(req.method,
                        req.url,
                        params=req.params,
                        data=req.data,
                        headers=req.headers,
                        files=req.files,
                        auth=req.auth,
                        cookies=req.cookies,
                        verify=req.verify,
                        timeout=30)
    elapsed = time.perf_counter() - start

    return request_generator.Result(req.url,
                                    resp.status_code,
                                    len(resp.content),
                                    timestamp=timestamp,
                                    elapsed_time=elapsed)
Exemple #8
0
def public_api_get_categories(args):

    start = time.perf_counter()
    timestamp = datetime.datetime.now()
    req = args['req']
    sess = requests.session()
    sess.mount('http://', args['adapter'])
    resp = sess.request(req.method,
                        req.url,
                        params=req.params,
                        json=req.data,
                        headers=req.headers,
                        files=None,
                        auth=req.auth,
                        cookies=req.cookies,
                        verify=req.verify)
    resp.raise_for_status()
    elapsed = time.perf_counter() - start

    return request_generator.Result(req.url,
                                    resp.status_code,
                                    len(resp.content),
                                    timestamp=timestamp,
                                    elapsed_time=elapsed)
Exemple #9
0
def sleepy(args):
    time.sleep(args['sleeptime'])
    return request_generator.Result(f'id:{uuid.uuid4()}', 200, 0)