def test_motivation(self, db_session, login_page, tst_username, tst_email,
                        tst_password):
        """Testing:
        that main page motivation message id displayed

        Steps:
        - get logged main page

        Expected result:
        - main page footer motivation message id displayed
        """
        try:
            db_session.add(
                User(username=tst_username,
                     password=tst_password,
                     email=tst_email,
                     access=1,
                     active=0))
            db_session.commit()
        except IntegrityError:
            raise UnexpectedDBData()
        self.page = login_page
        self.page.login(tst_username, tst_password)
        motivation = self.page.find(MainLocators.TEXT_MOTIVATION)
        # delete test data from DB
        db_session.query(User).filter_by(username=tst_username).delete()
        db_session.commit()
        assert motivation is not None
    def test_main_without_vk_id(self, login_page, db_session, tst_username,
                                tst_email, tst_password):
        """Testing:
        that main page displays "LOGGED as: <username>" and no vk_id because it's unavailable

        Steps:
        - get logged main page

        Expected result:
        - main page displays "LOGGED as: <username>" and no vk_id
        """
        try:
            db_session.add(
                User(username=tst_username,
                     password=tst_password,
                     email=tst_email,
                     access=1,
                     active=0))
            db_session.commit()
        except IntegrityError:
            raise UnexpectedDBData()
        self.page = login_page
        self.page.login(tst_username, tst_password)
        test_user = db_session.query(User).filter_by(
            username=tst_username).first()
        db_session.commit()
        # delete test data from DB
        db_session.query(User).filter_by(username=tst_username).delete()
        db_session.commit()
        assert self.driver.current_url == URL_MAIN and self.page.find(
            MainLocators.TEXT_VKID)
示例#3
0
    def test_del_user(self, api_client, db_session, tst_username, tst_email, tst_password):
        """Testing:
        that user is deleted after request

        Steps:
        - add user with <username> to DB
        - send GET http://<APP_HOST>:<APP_PORT>/api/del_user/<username> request
        - check that user with <username> is removed from DB
        - delete test data from DB

        Expected result:
        - Resp code 204
        - No user in DB with <username>
        """
        try:
            db_session.add(
                User(username=tst_username, password=tst_password, email=tst_email))
            db_session.commit()
        except IntegrityError:
            raise UnexpectedDBData()
        test_user = db_session.query(User).filter_by(username=tst_username).first()
        db_session.commit()
        if test_user is None:
            raise DBDataNotFound()
        deleting = api_client.del_user(tst_username)
        test_user = db_session.query(User).filter_by(username=tst_username).first()
        # delete test data from DB if it is still there
        if test_user is not None:
            db_session.query(User).filter_by(username=tst_username).delete()
            db_session.commit()
        assert test_user is None and deleting.status == 204
示例#4
0
    def test_accept_accepted_user(self, api_client, db_session, tst_username, tst_email, tst_password):
        """Testing:
        accepting user that already is accepted

        Steps:
        - add user with <username> to DB
        - accept user with <username>
        - send GET http://<APP_HOST>:<APP_PORT>/api/accept_user/<username> request
        - check that user with <username> is still accepted
        - delete test data from DB

        Expected result:
        - Resp code 304
        - 'access' filed for <username> is 1
        """
        try:
            db_session.add(
                User(username=tst_username, password=tst_password, email=tst_email, access=1))
            db_session.commit()
        except IntegrityError:
            raise UnexpectedDBData()
        test_user = db_session.query(User).filter_by(username=tst_username).first()
        db_session.commit()
        if test_user is None:
            raise DBDataNotFound()
        accepting = api_client.accept_user(tst_username)
        # delete test data from DB
        db_session.query(User).filter_by(username=tst_username).delete()
        db_session.commit()
        assert test_user.access == 1 and accepting.status == 304
示例#5
0
    def test_add_valid_user(self, api_client, db_session, tst_username, tst_email, tst_password):
        """Testing:
        that user with <username>, <password>, <email> is added after request
        Test is parametrized to check data validation

        Steps:
        - send POST http://<APP_HOST>:<APP_PORT>/api/add_user request
        with
        Content-Type: application/json
        Body:
        {
           "username": "******",
           "password": "******",
           "email": "<email>"
        }
        - check that user with <username>, <password>, <email> is added to DB
        - delete test data from DB

        Expected result:
        - Resp code 201
        - User is added to DB
        """
        test_user = db_session.query(User).filter_by(username=tst_username).first()
        db_session.commit()
        if test_user is not None:
            raise UnexpectedDBData()
        adding = api_client.add_user(tst_username, tst_email, tst_password)

        test_user = db_session.query(User).filter_by(username=tst_username).first()
        db_session.commit()
        # delete test data from DB
        db_session.query(User).filter_by(username=tst_username).delete()
        db_session.commit()
        assert test_user is not None and test_user.username == tst_username and adding.status == 201
示例#6
0
    def test_block_user(self, api_client, db_session, tst_username, tst_email, tst_password):
        """Testing:
        that user is blocked after request

        Steps:
        - add user with <username> to DB
        - check that user with <username> is not blocked
        - send GET http://<APP_HOST>:<APP_PORT>/api/block_user/<username> request
        - check that user with <username> is blocked
        - delete test data from DB

        Expected result:
        - Resp code 200
        - 'access' filed for <username> is 0
        """
        try:
            db_session.add(
                User(username=tst_username, password=tst_password, email=tst_email, access=1))
            db_session.commit()
        except IntegrityError:
            raise UnexpectedDBData()
        test_user = db_session.query(User).filter_by(username=tst_username).first()
        db_session.commit()
        if test_user is None:
            raise DBDataNotFound()
        blocking = api_client.block_user(tst_username)
        # delete test data from DB
        db_session.query(User).filter_by(username=tst_username).delete()
        db_session.commit()
        assert test_user.access == 0 and blocking.status == 200
示例#7
0
    def test_accept_non_existing_user(self, api_client, db_session, tst_username):
        """Testing:
        accepting of non existing user

        Steps:
        - check that there's no user with <username> in DB
        - send GET http://<APP_HOST>:<APP_PORT>/api/accept_user/<username> request

        Expected result:
        Resp code 404
        """
        test_user = db_session.query(User).filter_by(username=tst_username).first()
        db_session.commit()
        if test_user is not None:
            raise UnexpectedDBData()
        accepting = api_client.accept_user(tst_username)
        assert accepting.status == 404
    def test_login_allowed_user(self, login_page, db_session, tst_username,
                                tst_email, tst_password):
        """Testing:
        that user with valid <username>, <password> is logged after submitting form

        Steps:
        - add test user to DB
        - fill login form with correct data
        - submit login
        (Done via fixtures so test may look confusing)
        - delete test data from DB

        Expected result:
        - Page with .../welcome/ url is opened
        - <username> access and active status in DB is 1
        - "Logged as <username>" message is displayed TODO may be wrong if main page work wrong even if login page is OK
        TODO check start_active_time updating in DB
        """
        try:
            db_session.add(
                User(username=tst_username,
                     password=tst_password,
                     email=tst_email,
                     access=1,
                     active=0))
            db_session.commit()
        except IntegrityError:
            raise UnexpectedDBData()
        self.page = login_page
        self.page.login(tst_username, tst_password)
        test_user = db_session.query(User).filter_by(
            username=tst_username).first()
        db_session.commit()
        # delete test data from DB
        db_session.query(User).filter_by(username=tst_username).delete()
        db_session.commit()
        assert test_user.access == 1 and test_user.active == 1 and self.driver.current_url == URL_MAIN \
               and tst_username in self.page.find(MainLocators.TEXT_USERNAME).text
    def test_login_disallowed_active_user(self, login_page, db_session,
                                          tst_username, tst_email,
                                          tst_password):
        """Testing:
        that user with access status 0 but active 1 and <username>, <password> is not authorized after submitting form

        Steps:
        - add test user to DB
        - fill login form with test data
        - submit login
        (Done via fixtures so test may look confusing)

        Expected result:
        - Block hint is displayed
        - <username> access and active status in DB is 0
        """
        hint_msg = 'Ваша учетная запись заблокирована'
        try:
            db_session.add(
                User(username=tst_username,
                     password=tst_password,
                     email=tst_email,
                     access=0,
                     active=1))
            db_session.commit()
        except IntegrityError:
            raise UnexpectedDBData()
        self.page = login_page
        self.page.login(tst_username, tst_password)
        test_user = db_session.query(User).filter_by(
            username=tst_username).first()
        db_session.commit()
        # delete test data from DB
        db_session.query(User).filter_by(username=tst_username).delete()
        db_session.commit()
        assert test_user.access == 0 and test_user.active == 1 and self.driver.current_url == URL_LOGIN\
               and hint_msg in self.page.find(LoginLocators.TEXT_HINT).text