예제 #1
0
    def test_redirect_correct_location_url(self):
        """
        Шаги:
            1. Отправляем запрос http://httpbin.org/redirect/10

        Ожидаемый результат: каждый редирект перенаправляет запрос на адрес http://httpbin.org/redirect/:n-1
        """
        url = "http://httpbin.org/redirect/10"
        with allure.step("Отправляем запрос %s" % url):
            response = requests.get(url, timeout=60)
            response.raise_for_status()
            log_response(response)

        assert response.history, "No one redirect did not happen"
        assert len(
            response.history
        ) > 1, "Count of redirects must be higher than 1. Current count of redirects = %s" % len(
            response.history)
        logging.info("Request was redirected")
        with allure.step(
                "Проверяем, что Location каждого url содержит :n = n-1"):
            for resp in response.history:
                location = resp.headers['Location']
                if location == '/get':
                    break
                location_redirect_id = re.match('.*redirect/(\d+)',
                                                location).group(1)
                resp_url_n = re.match('.*redirect/(\d+)', resp.url).group(1)
                assert int(location_redirect_id) == int(resp_url_n) - 1
예제 #2
0
    def test_status_list_of_codes_with_invalid_weight(self, method):
        """
        Шаги:
            1. Отправляем запрос со списком кодов состояния и с указанием невалидного веса http://httpbin.org/status/401:asd,300:1

        Ожидаемый результат: ответ содержит код ошибки - 400
        """
        with allure.step(
                "Отправляем запрос %s на адрес 'http://httpbin.org/status/401:asd,300:1'"
                % method):
            response = requests.request(
                method, 'http://httpbin.org/status/401:asd,300:1', timeout=60)
            log_response(response)
        with allure.step("Проверяем, что вернулся код ошибки 400"):
            assert response.status_code == 400
예제 #3
0
    def test_status_list_of_codes(self, method):
        """
        Шаги:
            1. Отправляем запрос со списком кодов состояния http://httpbin.org/status/401,402,202

        Ожидаемый результат: ответ содержит один из кодов состояния - 401,402,202
        """
        with allure.step(
                "Отправляем запрос %s на адрес 'http://httpbin.org/status/401,402,202'"
                % method):
            response = requests.request(
                method, 'http://httpbin.org/status/401,402,202', timeout=60)
            log_response(response)
        with allure.step(
                "Проверяем, что вернулся один из кодов состояния 401,402,202"):
            assert response.status_code in (401, 402, 202)
예제 #4
0
    def test_status_with_invalid_code(self, method):
        """
        Шаги:
            1. Отправляем запрос с невалидным статусом http://httpbin.org/status/3-1

        Ожидаемый результат: ответ содержит код ошибки - 400
        """
        with allure.step(
                "Отправляем запрос %s на адрес 'http://httpbin.org/status/3-1'"
                % method):
            response = requests.request(method,
                                        'http://httpbin.org/status/3-1',
                                        timeout=60)
            log_response(response)
        with allure.step("Проверяем, что код состояния равен 400"):
            assert response.status_code == 400
예제 #5
0
    def test_status_one_code_with_weight(self, method):
        """
        Шаги:
            1. Отправляем запрос с кодом состояния с указанием веса http://httpbin.org/status/401:2

        Ожидаемый результат: ответ содержит код ошибки - 400
        """
        with allure.step(
                "Отправляем запрос %s на адрес 'http://httpbin.org/status/401:2'"
                % method):
            response = requests.request(method,
                                        'http://httpbin.org/status/401:2',
                                        timeout=60)
            log_response(response)
        with allure.step("Проверяем, что вернулся код ошибки 400"):
            assert response.status_code == 400
예제 #6
0
    def test_redirect_status(self):
        """
        Шаги:
            1. Отправляем запрос http://httpbin.org/redirect/10

        Ожидаемый результат: каждый редирект содержит код состояния 302
        """
        url = "http://httpbin.org/redirect/10"
        with allure.step("Отправляем запрос %s" % url):
            response = requests.get(url, timeout=60)
            response.raise_for_status()
            log_response(response)
        assert response.history, "No one redirect did not happen"
        with allure.step("Проверяем, что код состояния для каждого url - 302"):
            for resp in response.history:
                logging.debug("Response code: %s for url %s" %
                              (resp.status_code, resp.url))
                assert resp.status_code == 302, "Code not corresponds to redirect code - 302."
예제 #7
0
    def test_status_list_of_codes_with_negative_weight(self):
        """
        Шаги:
            1. Отправляем запрос со списком кодов состояния и с указанием невалидного веса http://httpbin.org/status/401:-2,300:1

        Ожидаемый результат: ответ содержит код ошибки - 400

        P.S.: На самом деле при указании отрицательного веса возвращается ошибка - 500 (Внутрення ошибка сервера).
              Покопавшись в исходном коде httpbin, выяснил что действительно в сервере вылетает ислючение IndexError.
              Судя по коду я решил что более целесообразным было бы выбрасывать ошибку 400 и не поддерживать отрицательные веса.
        """
        with allure.step(
                "Отправляем запрос на адрес 'http://httpbin.org/status/401:-2,300:1'"
        ):
            response = requests.get('http://httpbin.org/status/401:-2,300:1',
                                    timeout=60)
            log_response(response)
        with allure.step("Проверяем, что вернулся код ошибки 400"):
            assert response.status_code == 400
예제 #8
0
    def test_count_of_redirect(self):
        """
        Шаги:
            1. Отправляем запрос http://httpbin.org/redirect/10

        Ожидаемый результат: выполненное количество редиректов равно запрашиваемому количеству
        """
        n = 10
        url = "http://httpbin.org/redirect/%s" % n
        with allure.step("Отправляем запрос %s" % url):
            response = requests.get(url, timeout=60)
            response.raise_for_status()
            log_response(response)
        with allure.step(
                "Проверяем, что количество выполненых редиректов равно %s" %
                n):
            assert len(
                response.history
            ) == 10, "Length of redirects not corresponds expected length = %s" % n
예제 #9
0
    def test_headers_content_type_equal_custom_content_type(self):
        """
        Шаги тест кейса:
            1. Отправляем запрос на адресс http://httpbin.org/headers с заголовком content-type=custom_content_type

        Ожидание:
            В теле ответа будет содержаться заголовок content-type=custom_content_type
        """
        with allure.step(
                "Отправляем запрос на адресс http://httpbin.org/headers с заголовком content-type=custom_content_type"
        ):
            response = requests.get(
                "http://httpbin.org/headers",
                headers={"content-type": 'custom_content_type'},
                timeout=30)
            log_response(response)
        with allure.step(
                "Проверяем что в теле ответа содержится заголовок content-type=custom_content_type"
        ):
            assert response.json()["headers"][
                "Content-Type"] == "custom_content_type", "Content-Type not corresponds to %s" % "custom_content_type"
예제 #10
0
    def test_last_redirect_must_be_get(self):
        """
        Шаги:
            1. Отправляем запрос http://httpbin.org/redirect/1

        Ожидаемый результат: Location будет равен /get
        """
        url = "http://httpbin.org/redirect/1"
        with allure.step("Отправляем запрос %s" % url):
            response = requests.get(url, timeout=60)
            response.raise_for_status()
            log_response(response)
        assert response.history, "No one redirect did not happen"
        assert len(
            response.history
        ) == 1, "Redirect should be only one. Current count of redirects = %s" % len(
            response.history)
        expected_location_url = '/get'
        with allure.step("Проверяем, что Location равен %s" %
                         expected_location_url):
            location = response.history[0].headers['Location']
            assert location == expected_location_url, "Location must be equal '%s'. Current Location = %s" % (
                expected_location_url, location)