示例#1
0
    def setup(self, session):
        """
        SETUP funcion for TestModule class, this function is executed for each function in this TestClass
        """
        #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.commit()

        self.moduleList = Module.query.all()

        yield
        session.query(Module).delete()
        session.query(Project).delete()
        session.commit()
        self.moduleList[:] = []
        self.projectList[:] = []
示例#2
0
    def test_get_module_all(self, session):
        """Test method get_module_all in Module"""

        modules = Module.get_module_all_by_project_id(
            Project.get_project_by_name('DummyProject_01').id)
        assert len(modules) == len(self.moduleList)
        assert modules[0].id == self.moduleList[0].id
        assert modules[0].name == self.moduleList[0].name

        module = Module(
            Project.get_project_by_name('DummyProject_01').id, 'M13')
        session.add(module)
        session.commit()
        self.moduleList.append(module)

        modules = Module.get_module_all_by_project_id(
            Project.get_project_by_name('DummyProject_01').id)
        assert len(modules) == len(self.moduleList)

        modules = Module.get_module_all_by_project_id(
            Project.get_project_by_name('DummyProject_02').id, False)
        assert modules == []

        session.query(Module).delete()
        session.commit()

        modules = Module.get_module_all_by_project_id(
            Project.get_project_by_name('DummyProject_01').id, False)
        assert modules == []
示例#3
0
    def test_get_project_by_name(self):
        """Test method get_project_by_name in Project"""
        #Test something that really shouldn't be there
        with pytest.raises(DbException) as err:
            Project.get_project_by_name('@')
        assert str(err.value) == "(404, 'Project not found.')"

        project = Project.get_project_by_name(self.projectList[0].name)
        assert project.id == self.projectList[0].id
        assert project.name == self.projectList[0].name

        assert Project.get_project_by_name('@', False) == None
示例#4
0
    def test_create_project(self):
        """Test method create_project in Project"""
        #Test something that really shouldn't be there
        with pytest.raises(DbException) as err:
            Project.create_project('DummyProject_01')
        assert str(err.value) == "(400, 'Name is already taken.')"

        project1 = Project.create_project('DummyProject_02')
        project2 = Project.get_project_by_id(project1.id)
        assert project1.id == project2.id
        assert project1.name == project2.name

        assert Project.create_project('DummyProject_02',
                                      raiseFlag=False) == None
示例#5
0
    def test_create_module(self):
        """Test method create_module in Module"""
        #Test something that really shouldn't be there
        with pytest.raises(DbException) as err:
            Module.create_module(0, 'M1111')
        assert str(err.value) == "(404, 'Project not found.')"
        with pytest.raises(DbException) as err:
            Module.create_module(
                Project.get_project_by_name('DummyProject_01').id, 'M11')
        assert str(err.value) == "(400, 'Name is already taken.')"

        created = datetime.datetime.utcnow() + datetime.timedelta(hours=-2)
        update = datetime.datetime.utcnow() + datetime.timedelta(hours=-1)
        module = Module.create_module(
            Project.get_project_by_name('DummyProject_01').id,
            name='M14',
            created=created,
            update=update,
            active=True,
            data='kektimusMaximusPrime',
            raiseFlag=True)

        assert module.project_id == Project.get_project_by_name(
            'DummyProject_01').id
        assert module.name == 'M14'
        assert module.created == created
        assert module.update == update
        assert module.active == True
        assert module.get_data() == 'kektimusMaximusPrime'

        module = Module.create_module(
            Project.get_project_by_name('DummyProject_01').id,
            name='M14',
            created=created,
            update=update,
            active=True,
            data='kektimusMaximusPrime',
            raiseFlag=False)
        assert module == None

        module = Module.create_module(1111111,
                                      name='M15',
                                      created=created,
                                      update=update,
                                      active=True,
                                      data='kektimusMaximusPrime',
                                      raiseFlag=False)
        assert module == None
示例#6
0
    def test_get_data(self):
        """Test method get_data in Module"""

        module = Module.create_or_update_module_by_id(
            Project.get_project_by_name('DummyProject_01').id,
            name='M15',
            active=False,
            data='kektimusMaximusPrime',
            raiseFlag=True)
        assert module.get_data() == 'kektimusMaximusPrime'
示例#7
0
    def test_get_project_all(self, session):
        """Test method get_project_all in Project"""

        projects = Project.get_project_all()
        assert len(projects) == len(self.projectList)
        assert projects[0].id == self.projectList[0].id
        assert projects[0].name == self.projectList[0].name

        project = Project('DummyProject_02')
        session.add(project)
        session.commit()
        self.projectList.append(project)

        projects = Project.get_project_all()
        assert len(projects) == len(self.projectList)

        session.query(Project).delete()
        session.commit()

        projects = Project.get_project_all(False)
        assert projects == []
示例#8
0
    def test_create_or_update_project_by_id(self):
        """Test method create_or_update_project_by_id in Project"""
        project1 = Project.create_or_update_project_by_id(
            None, 'DummyProject_02')
        with pytest.raises(DbException) as err:
            Project.create_or_update_project_by_id(self.projectList[0].id,
                                                   'DummyProject_02')
        assert str(err.value) == "(400, 'Name is already taken.')"

        project = Project.create_or_update_project_by_id(
            self.projectList[0].id, 'DummyProject_03')
        assert project.name == 'DummyProject_03'
        assert Project.get_project_by_id(
            self.projectList[0].id).name == 'DummyProject_03'

        created = datetime.datetime.utcnow() + datetime.timedelta(hours=-2)
        update = datetime.datetime.utcnow() + datetime.timedelta(hours=-1)
        project = Project.create_or_update_project_by_id(
            self.projectList[0].id, 'dummy', created, update, False)
        assert project.id == Project.get_project_by_id(
            self.projectList[0].id).id
        assert project.name == 'dummy'
        assert project.created == created
        assert project.update == update
        assert project.active == False

        project = Project.create_or_update_project_by_id(
            self.projectList[0].id, 'dummy', active=True)
        assert project.id == Project.get_project_by_id(
            self.projectList[0].id).id
        assert project.name == 'dummy'
        assert project.created == created
        assert project.update > update
        assert project.active == True

        assert Project.create_or_update_project_by_id(0,
                                                      'dummy',
                                                      raiseFlag=False) == None
示例#9
0
    def setup(self, session):
        """
        SETUP funcion for TestProject class, this function is executed for each function in this TestClass
        """
        #make initial project
        session.add(Project('DummyProject_01'))
        session.commit()

        self.projectList = Project.query.all()

        yield
        session.query(Project).delete()
        session.commit()
        self.projectList[:] = []
示例#10
0
    def test_create_or_update_module_by_id_from_array(self):
        """Test method create_or_update_module_by_id_from_array in Module"""

        array = {'project_id': 0, 'name': 'M1111'}

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

        array = {
            'project_id': Project.get_project_by_name('DummyProject_01').id,
            'name': 'M11'
        }

        with pytest.raises(DbException) as err:
            Module.create_or_update_module_by_id_from_array(0, array)
        assert str(err.value) == "(400, 'Name is already taken.')"

        created = datetime.datetime.utcnow() + datetime.timedelta(hours=-2)
        update = datetime.datetime.utcnow() + datetime.timedelta(hours=-1)

        array = {
            'project_id': Project.get_project_by_name('DummyProject_01').id,
            'name': 'M14',
            'created': created,
            'update': update,
            'active': True,
            'data': 'kektimusMaximusPrime'
        }

        module = Module.create_or_update_module_by_id_from_array(None, array)

        assert module.project_id == Project.get_project_by_name(
            'DummyProject_01').id
        assert module.name == 'M14'
        assert module.created == created
        assert module.update == update
        assert module.active == True

        array = {
            'project_id': Project.get_project_by_name('DummyProject_01').id,
            'name': 'M15',
            'active': False,
            'data': 'kektimusMaximusPrime'
        }

        module2 = Module.create_or_update_module_by_id_from_array(
            module.id, array)

        assert module2.project_id == Project.get_project_by_name(
            'DummyProject_01').id
        assert module2.name == 'M15'
        assert module2.created == created
        assert module2.update > update
        assert module2.active == False

        array = {'project_id': 0, 'name': 'M1111'}

        assert Module.create_or_update_module_by_id_from_array(
            0, array, raiseFlag=False) == None

        array = {
            'project_id': Project.get_project_by_name('DummyProject_01').id,
            'name': 'M15'
        }

        assert Module.create_or_update_module_by_id_from_array(
            0, array, raiseFlag=False) == None
示例#11
0
    def test_activate_project_by_id(self):
        """Test method activate_project_by_id & deactivate_project_by_id in Project"""
        #Test something that really shouldn't be there
        with pytest.raises(DbException) as err:
            Project.activate_project_by_id(0)
        assert str(err.value) == "(404, 'Project not found.')"
        with pytest.raises(DbException) as err:
            Project.deactivate_project_by_id(0)
        assert str(err.value) == "(404, 'Project not found.')"

        Project.deactivate_project_by_id(self.projectList[0].id)
        project = Project.get_project_by_id(self.projectList[0].id)
        assert not project.active

        Project.activate_project_by_id(self.projectList[0].id)
        project = Project.get_project_by_id(self.projectList[0].id)
        assert project.active

        assert not Project.deactivate_project_by_id(0, False)
        assert not Project.activate_project_by_id(0, False)
示例#12
0
    def test_create_or_update_project_by_id_array(self):
        """Test method create_or_update_project_by_id_array in Project"""
        array = {'name': 'DummyProject_02'}

        project1 = Project.create_or_update_project_by_id_array(None, array)
        with pytest.raises(DbException) as err:
            Project.create_or_update_project_by_id_array(
                self.projectList[0].id, array)
        assert str(err.value) == "(400, 'Name is already taken.')"

        array = {'name': 'DummyProject_03'}
        project = Project.create_or_update_project_by_id_array(
            self.projectList[0].id, array)
        assert project.name == 'DummyProject_03'
        assert Project.get_project_by_id(
            self.projectList[0].id).name == 'DummyProject_03'

        created = datetime.datetime.utcnow() + datetime.timedelta(hours=-2)
        update = datetime.datetime.utcnow() + datetime.timedelta(hours=-1)
        array = {
            'name': 'dummy',
            'created': created,
            'update': update,
            'active': False
        }
        project = Project.create_or_update_project_by_id_array(
            self.projectList[0].id, array)
        assert project.id == Project.get_project_by_id(
            self.projectList[0].id).id
        assert project.name == 'dummy'
        assert project.created == created
        assert project.update == update
        assert project.active == False

        array = {'name': 'dummy', 'active': True}
        project = Project.create_or_update_project_by_id_array(
            self.projectList[0].id, array)
        assert project.id == Project.get_project_by_id(
            self.projectList[0].id).id
        assert project.name == 'dummy'
        assert project.created == created
        assert project.update > update
        assert project.active == True

        array = {'name': 'dummy2', 'kek': 'kek'}
        project = Project.create_or_update_project_by_id_array(
            self.projectList[0].id, array)
        assert project.id == Project.get_project_by_id(
            self.projectList[0].id).id
        assert project.name == 'dummy2'
        assert project.created == created
        assert project.update > update
        assert project.active == True

        array = {'name': 'dummy2'}
        assert Project.create_or_update_project_by_id_array(
            0, array, raiseFlag=False) == None
示例#13
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[:] = []