def test_add_two_users_with_same_email(self, api_client: ApiClient):
        """Test that it is impossible to create two users with same email

        Steps:
            - Make request to application with path /api/add_user and JSON in valid format
            - Make another request to application with path /api/add_user
              but different username and password
        Expected results:
            Status code for the first request is in 200-300 range
            Status code for the first request is in 400-500 range
        """
        username, email, password = make.auth_data()
        username2, _, password2 = make.auth_data(email=email)
        with allure.step(
                'Add the first user and check status code is in range 200 to 300'
        ):
            response = api_client.add_user(username=username,
                                           email=email,
                                           password=password)
            attach_http(response, '1')
            assert response.status_code in range(200, 300)
        with allure.step(
                'Add the second user and check status code is in range 400 to 500'
        ):
            response2 = api_client.add_user(username=username2,
                                            email=email,
                                            password=password2)
            attach_http(response2, '2')
            assert response2.status_code in range(400, 500)
def test_source_links(authorization_page: AuthorizationPage):
    """Test all pages' sources exist

    Steps:
        - Open authorization page and collect all links to sources
        - Check sources one by one
        - Open registration page and collect all links to sources
        - Check sources one by one
        - Pass registration and enter main page, collect all links to sources
        - Check sources one by one

    Expected results:
        Each source response status code is 200

    Note: pytest_check functions can't be used inside function decorated by allure.step()
    because of allure.step() design. So allure report show status for each source,
    but pytest summary show only FAILURE for registration, authorization and main pages
    """
    with check.check:
        check_all_sources_exist(authorization_page, 'authorization page',
                                'some urls are invalid')
    registration_page = authorization_page.create_an_account()
    with check.check:
        check_all_sources_exist(registration_page, 'registration page',
                                'some urls are invalid')
    username, email, password = make.auth_data()
    main_page = registration_page.pass_registration(username=username,
                                                    email=email,
                                                    password=password)
    with check.check:
        check_all_sources_exist(main_page, 'main page',
                                'some urls are invalid')
    def test_authorize_after_add(self, authorization_page: AuthorizationPage,
                                 api_client: ApiClient):
        """Test that user, created by API, can authorize properly

        Steps:
            - Make request to application with path /api/add_user and JSON in valid format
            - Try to authorize with the same credentials

        Expected results:
            Response status code is 200 for API request
            User succeed to authorize
        """
        username, email, password = make.auth_data()
        response = api_client.add_user(username=username,
                                       email=email,
                                       password=password)
        assert response.status_code in range(200, 300)
        try:
            authorization_page.authorize(username=username, password=password)
        except WebDriverException as err:
            raise AssertionError from err
Пример #4
0
    def test_scenario_single_user(self, api_client: ApiClient,
                                  mysql_client: MysqlClient,
                                  authorization_page: AuthorizationPage):
        """Test scenario for API

        Steps:
            0 Generate credentials
            1 Add user via API
            2 Delete user via API
            3 Add user via API
            4 Accept user via API
            5 Block user via API
            6 Accept user via API
            7 Authorize user via API
            8 Logout
            9 Block user via API
            0 Try to authorize user
        Expected results:
            Step 1: database table has record with these credentials and values `access` = 1,
              `active` = 0, `start_active_time` = None
            Step 2: record does not exist for this username
            Steps 3-4: database table has record with these credentials and values `access` = 1,
              `active` = 0, `start_active_time` = None
            Step 5: `access` = 0, no other changes
            Step 6: `access` = 1, no other changes
            Step 7: User succeeds to authorize, `active` changed to 1, start_active_time changed
            and almost equal time.time(), no other changes
            Step 8: `active` = 0, no other changes
            Step 9: `access` = 0, no other changes
            Step 10: User doesn't succeed to authorize, the record doesn't changed
        """
        username, email, password = make.auth_data()
        with allure.step('Add user'):
            api_client.add_user(username=username,
                                email=email,
                                password=password)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 1, 0, None)
        with allure.step('Del user'):
            api_client.del_user(username=username)
            assert mysql_client.get_record(
                username) is None  # record not exists
        with allure.step('Add user'):
            api_client.add_user(username=username,
                                email=email,
                                password=password)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 1, 0, None)
        with allure.step('Accept user'):
            api_client.accept_user(username=username)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 1, 0,
                                    None)  # no changes
        with allure.step('Block user'):
            api_client.block_user(username=username)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 0, 0,
                                    None)  # access = 0
        with allure.step('Accept user'):
            api_client.accept_user(username=username)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 1, 0, None)
        with allure.step('Authorize user'):
            main_page = authorization_page.authorize(username, password)
            record = mysql_client.get_record(username)
            start_time = time.time()
            assert record is not None
            assert record == Record(username, email, password, 1, 1,
                                    start_time)  # active = 1
        with allure.step('Logout'):
            main_page.logout()
            assert record is not None
            assert record == Record(username, email, password, 1, 0,
                                    start_time)  # active = 0
        with allure.step('Block user'):
            api_client.block_user(username=username)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 0, 0,
                                    start_time)  # access = 0
        with allure.step('Authorize user (who is blocked)'):
            with pytest.raises(AuthorizationError):
                authorization_page.authorize(username, password)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 0, 0,
                                    start_time)  # no changes
Пример #5
0
    def test_scenario_single_user_2(self, api_client: ApiClient,
                                    mysql_client: MysqlClient,
                                    registration_page: RegistrationPage):
        """Test scenario for API

                Steps:
                    0 Generate credentials
                    1 Pass registration with these credentials
                    2 Block user via API
                    3 Refresh page
                    4 Try to authorize to the site
                    5 Accept user via API
                    6 Try to authorize user
                Expected results:
                    Step 1: database table has record with these credentials and values `access` = 1,
                      `active` = 1, `start_active_time` ~ time.time()
                    Step 2: `access` = 0, no other changes
                    Step 3: user is redirected to authorization page, `access` = 0, `active` = 0
                    Step 4: user doesn't succeed to authorize,
                    Step 6: `access` = 1, no other changes
                    Step 7: User succeeds to authorize, `active` changed to 1, start_active_time changed
                    and almost equal time.time(), no other changes
                    Step 8: `active` = 0, no other changes
                    Step 9: `access` = 0, no other changes
                    Step 10: User doesn't succeed to authorize, the record doesn't changed
                """
        username, email, password = make.auth_data()
        with allure.step('Register user'):
            main_page = registration_page.pass_registration(
                username, email, password)
            start_time = time.time()
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 1, 1,
                                    start_time)  # access = 1, active = 1
        with allure.step('Block user'):
            api_client.block_user(username=username)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 0, 0,
                                    start_time)  # access = 0, active = 0
        with allure.step('Refresh page'):
            main_page.refresh()
            assert not MainPage.is_opened(main_page.driver)
            assert AuthorizationPage.is_opened(main_page.driver)  # logout
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 0, 0,
                                    start_time)  # no change
        authorization_page = AuthorizationPage(main_page.driver,
                                               main_page.settings)
        with allure.step('Authorize user (who is blocked)'):
            with pytest.raises(AuthorizationError):
                authorization_page.authorize(username, password)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 0, 0,
                                    start_time)  # no change
        with allure.step('Accept user'):
            api_client.block_user(username=username)
            record = mysql_client.get_record(username)
            assert record is not None
            assert record == Record(username, email, password, 1, 0,
                                    start_time)  # access = 1
        with allure.step('Authorize user (who was accepted)'):
            authorization_page.authorize(username, password)
            record = mysql_client.get_record(username)
            start_time = time.time()
            assert record is not None
            assert record == Record(username, email, password, 1, 1,
                                    start_time)  # active = 1
Пример #6
0
def test_scenario1(registration_page: RegistrationPage, api_client: ApiClient):
    """Test how API functions influence user

    Steps:
        1 Pass registration with generated credentials
        2 Block user via block_user API function
        3 Refresh page
        4 Open registration page and try to register with the same credentials again
        5 Open authorization page and try to authorize to the site with the same credentials
        6 Accept user via accept_user API function
        7 Refresh page
        8 Delete user via del_user API function
        9 Refresh page
        0 Open authorization page and try to authorize to the site with the same credentials
        1 Open registration page and register with same credentials again
    Expected results:
        Steps 1-2 succeed
        Step 3 redirect to authrization page
        Steps 4-5 fail, pytest.raises catch Exception
        Step 6 succeed
        Step 7 redirect to main page
        Step 8 succeed
        Step 9 redirect to authorization page
        Step 10 fail, pytest.raises catch Exception
        Step 11 succeed
    """
    username, email, password = make.auth_data()
    with allure.step("Pass registration"):
        main_page = registration_page.pass_registration(username=username,
                                                        password=password,
                                                        email=email)
        assert 'welcome' in urlparse(main_page.current_url).path
    with allure.step(f"Block user {username}"):
        response = api_client.block_user(username)
        attach_http(response)
    with allure.step("Refresh page"):
        main_page.refresh()
        assert 'welcome' not in urlparse(main_page.current_url).path
    with allure.step(
            "Open registration page and try to register with same credentials again"
    ):
        registration_page.make_request()
        with pytest.raises(RegistrationError):
            registration_page.pass_registration(username=username,
                                                email=email,
                                                password=password)
    with allure.step("Try to authorize"):
        authorization_page = registration_page.go_to_authorization_page()
        with pytest.raises(AuthorizationError):
            authorization_page.authorize(username=username, password=password)
    with allure.step("Accept user"):
        response = api_client.accept_user(username)
        attach_http(response)
    with allure.step('User was redirected to main page after refresh'):
        authorization_page.refresh()
        assert 'welcome' in urlparse(authorization_page.current_url).path
    with allure.step("Delete user"):
        api_client.del_user(username)
        attach_http(response)
    with allure.step("User was redirected from main page after refresh"):
        main_page.refresh()
        assert 'welcome' not in urlparse(authorization_page.current_url).path
    with allure.step("Try to authorize"):
        authorization_page.make_request()
        with pytest.raises(AuthorizationError):
            authorization_page.authorize(username=username, password=password)
    with allure.step("Pass registration"):
        registration_page.make_request()
        registration_page.pass_registration(username=username,
                                            email=email,
                                            password=password)
def main_page(registration_page: RegistrationPage):
    username, email, password = make.auth_data()
    return registration_page.pass_registration(username=username,
                                               email=email,
                                               password=password)
 def main_page(self, registration_page: RegistrationPage):
     """Fixture-helper to open main page of new user"""
     username, email, password = make.auth_data()
     return registration_page.pass_registration(username=username, email=email,
                                                password=password)