Exemple #1
0
    def setup(self, session):
        """
        SETUP funcion for TestUser class, this function is executed for each function in this TestClass
        """
        user_types = []
        user_types.append(UserType("ADMIN", 2))
        user_types.append(UserType("GUEST", 0))
        user_types.append(UserType("USER", 1))

        user_type_db = UserType.query.all()

        for user in user_type_db:
            for seedUser in user_types:
                if (user.name == seedUser.name):
                    user_types.remove(seedUser)

        for user_type in user_types:
            self.user_type_list.append(user_type)
            session.add(user_type)
            session.commit()

        user = User("Admin", "*****@*****.**", "SuperSecret", None, None,
                    True)
        user.user_type_id = UserType.get_type_by_name('ADMIN').id
        user.activated = True
        session.add(user)
        session.commit()
        ttoken = str(user.id).zfill(10) + str(uuid.uuid4())
        #Check if token is unique
        while (UserToken.query.filter_by(token=ttoken).count() != 0):
            ttoken = str(user.id).zfill(10) + str(uuid.uuid4())

        ttoken = UserToken(user_id=user.id, token=ttoken)
        ttoken.update = datetime.utcnow()
        ttoken.created = datetime.utcnow()
        session.add(ttoken)
        session.commit()
        self.token_list.append(ttoken.token)
        self.user_list.append(user.id)
        user = User("Test", "*****@*****.**", "SuperSecret", None, None, True)
        session.add(user)
        session.commit()
        ttoken = str(user.id).zfill(10) + str(uuid.uuid4())
        #Check if token is unique
        while (UserToken.query.filter_by(token=ttoken).count() != 0):
            ttoken = str(user.id).zfill(10) + str(uuid.uuid4())

        ttoken = UserToken(user_id=user.id, token=ttoken)
        ttoken.update = datetime.utcnow()
        ttoken.created = datetime.utcnow()
        session.add(ttoken)
        session.commit()
        self.token_list.append(ttoken.token)
        self.user_list.append(user.id)

        yield
        session.query(User).delete()
        session.query(UserType).delete()
        session.query(UserToken).delete()
        session.commit()
Exemple #2
0
    def setup(self, session):
        """
        SETUP funcion for TestUser class, this function is executed for each function in this TestClass
        """
        user_types = []
        user_types.append(UserType("ADMIN", 2))
        user_types.append(UserType("GUEST", 0))
        user_types.append(UserType("USER", 1))

        user_type_db = UserType.query.all()

        for user in user_type_db:
            for seedUser in user_types:
                if (user.name == seedUser.name):
                    user_types.remove(seedUser)

        for user_type in user_types:
            session.add(user_type)
            session.commit()

        user = User("Admin", "*****@*****.**", "SuperSecret", None, None,
                    True)
        user.user_type_id = UserType.get_type_by_name('ADMIN').id
        user.activated = True
        session.add(user)
        session.commit()
        self.userList.append(user)
        yield
        session.query(User).delete()
        session.query(UserType).delete()
        session.commit()
        self.userList[:] = []
Exemple #3
0
    def test_get_user_all(self, session):
        """Test method get_user_all in User"""

        users = User.get_user_all()
        assert len(users) == len(self.userList)
        assert users[0].id == self.userList[0].id
        assert users[0].name == self.userList[0].name
        assert users[0].email == self.userList[0].email
        assert users[0].password == self.userList[0].password

        user = User("DUMMY", "*****@*****.**", "hackPr00f", None, None,
                    True)
        user.user_type_id = UserType.get_type_by_name('USER').id
        user.activated = True
        session.add(user)
        session.commit()
        self.userList.append(user)

        users = User.get_user_all()
        assert len(users) == len(self.userList)

        session.query(User).delete()
        session.commit()

        users = User.get_user_all(False)
        assert users == []

        #Test something that really shouldn't be there
        with pytest.raises(DbException) as err:
            User.get_user_all()
        assert str(err.value) == "(404, 'No user found.')"
Exemple #4
0
def __userInsert():
    userList = []
    userAdmin = User("Admin", "*****@*****.**", "SuperSecret", None, None,
                     True)
    userAdmin.user_type_id = UserType.get_type_by_name('ADMIN').id
    userAdmin.activated = True
    userList.append(userAdmin)

    userEntities = User.query.all()

    for user in userEntities:
        for seedUser in userList:
            if (user.name == seedUser.name):
                userList.remove(seedUser)

    for seedUser in userList:
        db.session.add(seedUser)
        db.session.commit()
        print("Inserting: ")
        print(seedUser.name)
Exemple #5
0
    def test_update_user_by_id_from_array(self, session):
        """Test method update_user_by_id_from_array in User"""
        array = {
            'name': 'kektimusMaximusPrime',
            'email': '*****@*****.**',
            'password': '******',
            'user_type_id': 2
        }

        #Test something that really shouldn't be there
        with pytest.raises(DbException) as err:
            User.update_user_by_id_from_array(0, array)
        assert str(err.value) == "(404, 'User not found.')"

        user = User("DUMMY", "*****@*****.**", "hackPr00f", None, None,
                    True)
        user.user_type_id = UserType.get_type_by_name('GUEST').id
        user.activated = True
        session.add(user)
        session.commit()
        self.userList.append(user)

        assert len(self.userList) == 2

        User.update_user_by_id_from_array(self.userList[1].id, array)
        user = User.get_user_by_id(self.userList[1].id)
        assert user.id == self.userList[1].id
        assert user.name == 'kektimusMaximusPrime'
        assert user.email == '*****@*****.**'
        assert user.confirm_password('passwd')
        assert user.user_type_id == 2

        array = {}
        User.update_user_by_id_from_array(self.userList[1].id, array)
        user = User.get_user_by_id(self.userList[1].id)
        assert user.id == self.userList[1].id
        assert user.name == 'kektimusMaximusPrime'
        assert user.email == '*****@*****.**'
        assert user.confirm_password('passwd')
        assert user.user_type_id == 2

        array = {'kek': 123, 'token': '01235'}
        User.update_user_by_id_from_array(self.userList[1].id, array)
        user = User.get_user_by_id(self.userList[1].id)
        assert user.id == self.userList[1].id
        assert user.name == 'kektimusMaximusPrime'
        assert user.email == '*****@*****.**'
        assert user.confirm_password('passwd')
        assert user.user_type_id == 2

        array = {'name': 'kektimusMaximusPrime'}
        with pytest.raises(DbException) as err:
            User.update_user_by_id_from_array(self.userList[0].id, array)
        assert str(err.value) == "(400, 'username')"

        array = {'email': '*****@*****.**'}
        with pytest.raises(DbException) as err:
            User.update_user_by_id_from_array(self.userList[0].id, array)
        assert str(err.value) == "(400, 'email')"

        array = {'user_type_id': 200}
        with pytest.raises(DbException) as err:
            User.update_user_by_id_from_array(self.userList[0].id, array)
        assert str(err.value) == "(400, 'usertype')"

        array = {'name': 'kektimusMaximusPrime', 'password': '******'}
        with pytest.raises(DbException) as err:
            User.update_user_by_id_from_array(self.userList[0].id, array)
        assert str(err.value) == "(400, 'username')"
        user = User.get_user_by_id(self.userList[0].id)
        assert not user.confirm_password('passwd')

        array = {'email': '*****@*****.**', 'password': '******'}
        with pytest.raises(DbException) as err:
            User.update_user_by_id_from_array(self.userList[0].id, array)
        assert str(err.value) == "(400, 'email')"
        user = User.get_user_by_id(self.userList[0].id)
        assert not user.confirm_password('passwd')

        array = {'user_type_id': 200, 'password': '******'}
        with pytest.raises(DbException) as err:
            User.update_user_by_id_from_array(self.userList[0].id, array)
        assert str(err.value) == "(400, 'usertype')"
        user = User.get_user_by_id(self.userList[0].id)
        assert not user.confirm_password('passwd')
Exemple #6
0
    def setup(self, session):
        """
        SETUP funcion for TestUser class, this function is executed for each function in this TestClass
        """
        user_types = []
        user_types.append(UserType("ADMIN", 2))
        user_types.append(UserType("GUEST", 0))
        user_types.append(UserType("USER", 1))

        user_type_db = UserType.query.all()

        for user in user_type_db:
            for seedUser in user_types:
                if (user.name == seedUser.name):
                    user_types.remove(seedUser)

        for user_type in user_types:
            session.add(user_type)
            session.commit()

        user = User("GUEST", "*****@*****.**", "GUEST", None, None, True)
        user.user_type_id = UserType.get_type_by_name('GUEST').id
        user.activated = True
        user1 = User("USER", "*****@*****.**", "USER", None, None, True)
        user1.user_type_id = UserType.get_type_by_name('USER').id
        user1.activated = True
        user2 = User("Admin", "*****@*****.**", "SuperSecret", None, None,
                     True)
        user2.user_type_id = UserType.get_type_by_name('ADMIN').id
        user2.activated = True
        session.add(user)
        session.add(user1)
        session.add(user2)
        session.commit()
        self.userList.append(user)
        self.userList.append(user1)
        self.userList.append(user2)

        #make initial project
        session.add(Project.create_project('DummyProject_01'))
        session.add(Project.create_project('DummyProject_02'))
        session.commit()

        self.projectList = Project.query.all()

        session.add(
            Module(Project.get_project_by_name('DummyProject_01').id, 'M11'))
        session.add(
            Module(Project.get_project_by_name('DummyProject_01').id, 'M12'))
        session.add(
            Module(Project.get_project_by_name('DummyProject_01').id, 'M13'))
        session.add(
            Module(Project.get_project_by_name('DummyProject_01').id, 'read'))
        session.add(
            Module(Project.get_project_by_name('DummyProject_01').id, 'write'))
        session.add(
            Module(Project.get_project_by_name('DummyProject_01').id, 'share'))
        session.add(
            Module(Project.get_project_by_name('DummyProject_01').id, 'own'))
        session.commit()

        self.moduleList = Module.query.all()

        perm0 = ModulePerm(self.userList[0].id, self.moduleList[0].id, 15)
        perm1 = ModulePerm(self.userList[0].id, self.moduleList[1].id, 8)
        perm2 = ModulePerm(self.userList[0].id, self.moduleList[2].id, 0)

        session.add(perm0)
        session.add(perm1)
        session.add(perm2)
        session.commit()

        self.permList.append(perm0)
        self.permList.append(perm1)
        self.permList.append(perm2)

        yield
        session.query(ModulePerm).delete()
        self.permList[:] = []

        session.query(Module).delete()
        session.query(Project).delete()
        session.commit()
        self.moduleList[:] = []
        self.projectList[:] = []

        session.query(User).delete()
        session.query(UserType).delete()
        session.commit()
        self.userList[:] = []