Esempio n. 1
0
def test_post_headers(headers_add, ini):
    """
        **test_post_headers**

        This checks negative scenario (unsupported operation "POST").

        Expected result: 405 status-code

        Pytest marks: "headers", "negative"
    """
    resp = requests.post(str(get_url(ini) + '/headers'), headers=headers_add)
    logging.info("Response: {}".format(resp.text))
    assert resp.status_code == 405, "Wrong status code of response."
Esempio n. 2
0
def test_post_redirect(ini, count):
    """
        **test_post_redirect**

        This checks negative scenario about POST request redirect.

        Expected result: 405 status-code.

        Pytest marks: "redirect", "negative"
    """
    logging.info("Count: {}".format(count))
    resp = requests.post(str(get_url(ini) + '/redirect/' + count))
    logging.info("Response: {}".format(resp.text))
    assert resp.status_code == 405, "Wrong status code of response."
Esempio n. 3
0
def test_get_redirect(ini, count):
    """
        **test_get_redirect**

        This checks different scenarios about getting request redirects.

        Expected result: 200 status-code and correct number of redirections.

        Available parameters sets:
        1 - 6) Positive parameters
        7 - 11) Simulation: we suppose (just for example, it is obviously wrong) that these parameters should be valid,
        but now they fail test.

        Pytest marks: "redirect", "positive"
    """
    logging.info("Count: {}".format(count))
    resp = requests.get(str(get_url(ini) + '/redirect/' + str(count)))
    logging.info("Response: {}".format(resp.text))
    assert resp.status_code == 200, "Wrong status code of response."
    assert len(resp.history) == int(count), "Wrong redirection number."
Esempio n. 4
0
def status(ini, operation, code):
    """
        **status**

        This creates request for status endpoint based on received parameters.

        :param ini: config file
        :param operation : type of operation
        :type operation : str
        :param code: status-code of request
        :type code : int
        :return: status-code of response


    """
    logging.info("Operation: {}".format(operation))
    logging.info("Code: {}".format(code))
    resp = requests.request(operation, str(get_url(ini) + '/status/' + str(code)),
                            timeout=int(get_conf(ini)["timeouts"]["timeout"]))
    logging.info("Response: {}".format(resp.request))
    logging.info("Status code: {}".format(resp.status_code))
    return resp.status_code
Esempio n. 5
0
def test_get_headers(headers_add, ini):
    """
        **test_get_headers**

        This checks different positive scenarios about getting request headers.

        Expected result: 200 status-code and correct list of headers.

        Available parameters sets:
        1) Empty header list
        2) 1 Non-default header
        3) 2 Non-default headers
        4) 1 default header
        5) 1 default header and 1 non-default header

        Pytest marks: "headers", "positive"
    """
    headers_default = {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Host": "httpbin.org",
        "User-Agent": "python-requests/2.22.0"
    }
    headers_unite = {**headers_default, **headers_add}
    logging.info("Headers for addition: {}".format(headers_add))
    logging.info("Headers default: {}".format(headers_default))

    resp = requests.get(str(get_url(ini) + '/headers'), headers=headers_add)

    logging.info("Response: {}".format(resp.text))

    assert resp.status_code == 200, "Wrong status code of response."
    resp_body = resp.json()['headers']
    for key in headers_unite:
        assert key in resp_body, "Header key from request doesn't exist in response."
        assert str(resp_body[key]) == str(
            headers_unite[key]), "Wrong value of key in response."