Пример #1
0
def delete_department(request):
    """deletes the department with the given id
    """
    department_id = request.matchdict.get('id')
    department = Department.query.get(department_id)
    name = department.name

    if not department:
        transaction.abort()
        return Response(
            'Can not find a Department with id: %s' % department_id, 500
        )

    try:
        DBSession.delete(department)
        transaction.commit()
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        return Response(c.html(), 500)

    request.session.flash(
        'success: <strong>%s Department</strong> is deleted '
        'successfully' % name
    )

    return Response('Successfully deleted department: %s' % department_id)
Пример #2
0
def delete_group(request):
    """deletes the group with the given id
    """
    group_id = request.matchdict.get('id')
    group = Group.query.get(group_id)
    name = group.name

    if not group:
        transaction.abort()
        return Response('Can not find a Group with id: %s' % group_id, 500)

    try:
        DBSession.delete(group)
        transaction.commit()
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        return Response(c.html(), 500)

    request.session.flash(
        'success:<strong>%s Group</strong> is deleted successfully' % name
    )

    return Response('Successfully deleted group: %s' % group_id)
 def tearDown(self):
     """clean up the test
     """
     # clean up test database
     from stalker.db.declarative import Base
     Base.metadata.drop_all(db.DBSession.connection())
     DBSession.commit()
Пример #4
0
def assign_thumbnail(request):
    """assigns the thumbnail to the given entity
    """
    link_ids = get_multi_integer(request, 'link_ids[]')
    entity_id = request.params.get('entity_id', -1)

    link = Link.query.filter(Link.id.in_(link_ids)).first()
    entity = Entity.query.filter_by(id=entity_id).first()

    logger.debug('link_ids  : %s' % link_ids)
    logger.debug('link      : %s' % link)
    logger.debug('entity_id : %s' % entity_id)
    logger.debug('entity    : %s' % entity)

    logged_in_user = get_logged_in_user(request)
    if entity and link:
        entity.thumbnail = link

        # resize the thumbnail
        file_full_path = convert_file_link_to_full_path(link.full_path)
        img = Image.open(file_full_path)
        if img.format != 'GIF':
            img.thumbnail((1024, 1024))
            img.thumbnail((512, 512), Image.ANTIALIAS)
            img.save(file_full_path)

        DBSession.add(entity)
        DBSession.add(link)

    return HTTPOk()
Пример #5
0
    def test_update_with_studio_is_working_properly(self):
        """testing if the default values are updated with the Studio instance
        if there is a database connection and there is a Studio in there
        """
        import datetime
        from stalker import db, defaults
        from stalker.db.session import DBSession
        from stalker.models.studio import Studio

        db.setup()
        db.init()

        # check the defaults are still using them self
        self.assertEqual(
            defaults.timing_resolution,
            datetime.timedelta(hours=1)
        )

        studio = Studio(
            name='Test Studio',
            timing_resolution=datetime.timedelta(minutes=15)
        )
        DBSession.add(studio)
        DBSession.commit()

        # now check it again
        self.assertEqual(
            defaults.timing_resolution,
            studio.timing_resolution
        )
Пример #6
0
    def test_tasks_are_correctly_scheduled_when_compute_resources_is_True(self):
        """testing if the tasks are correctly scheduled when the compute
        resources is True
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=True)
        test_studio = Studio(name="Test Studio", now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(datetime.datetime(2013, 4, 16, 9, 0), self.test_proj1.computed_start)
        self.assertEqual(datetime.datetime(2013, 4, 24, 10, 0), self.test_proj1.computed_end)

        self.assertEqual(datetime.datetime(2013, 4, 16, 9, 0), self.test_task1.computed_start)
        self.assertEqual(datetime.datetime(2013, 4, 18, 16, 0), self.test_task1.computed_end)
        self.assertEqual(
            sorted([self.test_user1, self.test_user2], key=lambda x: x.name),
            sorted(self.test_task1.computed_resources, key=lambda x: x.name),
        )

        self.assertEqual(datetime.datetime(2013, 4, 18, 16, 0), self.test_task2.computed_start)
        self.assertEqual(datetime.datetime(2013, 4, 24, 10, 0), self.test_task2.computed_end)
        self.assertEqual(
            sorted([self.test_user4, self.test_user5], key=lambda x: x.name),
            sorted(self.test_task2.computed_resources, key=lambda x: x.name),
        )
Пример #7
0
def upload_files(request):
    """uploads a list of files to the server, creates Link instances in server
    and returns the created link ids with a response to let the front end
    request a linkage between the entity and the uploaded files
    """
    # decide if it is single or multiple files
    file_params = request.POST.getall('file')
    logger.debug('file_params: %s ' % file_params)

    try:
        new_links = upload_files_to_server(request, file_params)
    except IOError as e:
        c = StdErrToHTMLConverter(e)
        response = Response(c.html())
        response.status_int = 500
        transaction.abort()
        return response
    else:
        # store the link object
        DBSession.add_all(new_links)

        logger.debug('created links for uploaded files: %s' % new_links)

        return {
            'link_ids': [link.id for link in new_links]
        }
    def test_tasks_of_given_projects_are_correctly_scheduled(self):
        """testing if the tasks of given projects are correctly scheduled
        """
        # create a dummy project
        # create a dummy Project to schedule
        dummy_project = Project(name='Dummy Project',
                                code='DP',
                                repository=self.test_repo)

        dt1 = Task(name='Dummy Task 1',
                   project=dummy_project,
                   schedule_timing=4,
                   schedule_unit='h',
                   resources=[self.test_user1])

        dt2 = Task(name='Dummy Task 2',
                   project=dummy_project,
                   schedule_timing=4,
                   schedule_unit='h',
                   resources=[self.test_user2])
        db.DBSession.add_all([dummy_project, dt1, dt2])
        db.DBSession.commit()

        tjp_sched = TaskJugglerScheduler(compute_resources=True,
                                         projects=[dummy_project])
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)
        db.DBSession.commit()

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(self.test_proj1.computed_start, None)
        self.assertEqual(self.test_proj1.computed_end, None)

        self.assertEqual(self.test_task1.computed_start, None)
        self.assertEqual(self.test_task1.computed_end, None)
        self.assertEqual(self.test_task1.computed_resources,
                         [self.test_user1, self.test_user2])

        self.assertEqual(self.test_task2.computed_start, None)
        self.assertEqual(self.test_task2.computed_end, None)
        self.assertEqual(self.test_task2.computed_resources,
                         [self.test_user1, self.test_user2])

        self.assertEqual(dt1.computed_start,
                         datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt1.computed_end,
                         datetime.datetime(2013, 4, 16, 13, 0))

        self.assertEqual(dt2.computed_start,
                         datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt2.computed_end,
                         datetime.datetime(2013, 4, 16, 13, 0))
Пример #9
0
def update_structure(request):
    """updates a structure
    """
    logged_in_user = get_logged_in_user(request)

    # get params
    structure_id = request.params.get('structure_id')
    structure = Structure.query.filter_by(id=structure_id).first()

    name = request.params.get('name')
    custom_template = request.params.get('custom_template')

    # get all FilenameTemplates
    ft_ids = get_multi_integer(request, 'filename_templates')
    fts = FilenameTemplate.query.filter(FilenameTemplate.id.in_(ft_ids)).all()

    if name:
        # update structure
        structure.name = name
        structure.custom_template = custom_template
        structure.templates = fts
        structure.updated_by = logged_in_user
        structure.date_updated = datetime.datetime.now()

        DBSession.add(structure)

    return HTTPOk()
Пример #10
0
def create_image_format(request):
    """creates an image format
    """
    logged_in_user = get_logged_in_user(request)

    name = request.params.get('name')
    width = int(request.params.get('width', -1))
    height = int(request.params.get('height', -1))
    pixel_aspect = float(request.params.get('pixel_aspect', -1))

    if name and width and height and pixel_aspect:
        # create a new ImageFormat and save it to the database
        new_image_format = ImageFormat(
            name=name,
            width=width,
            height=height,
            pixel_aspect=pixel_aspect,
            created_by=logged_in_user
        )
        DBSession.add(new_image_format)
        logger.debug('created new image format')
        logger.debug('new_image_format: %s' % new_image_format)
    else:
        logger.debug('some data is missing')
        return HTTPServerError()

    return HTTPOk()
Пример #11
0
def delete_user(request):
    """deletes the user with the given id
    """
    user_id = request.matchdict.get('id')
    user = User.query.get(user_id)

    if not user:
        transaction.abort()
        return Response('Can not find a User with id: %s' % user_id, 500)

    try:
        DBSession.delete(user)

        transaction.commit()
        request.session.flash(
            'success: %s is deleted' % user.name
        )
    except Exception as e:
        transaction.abort()
        c = StdErrToHTMLConverter(e)
        transaction.abort()
        request.session.flash(
            c.html()
        )
        return Response(c.html(), 500)

    return Response('Successfully deleted user: %s' % user_id)
Пример #12
0
def update_sequence(request):
    """runs when adding a new sequence
    """
    logged_in_user = get_logged_in_user(request)

    sequence_id = request.params.get('sequence_id')
    sequence = Sequence.query.filter_by(id=sequence_id).first()

    name = request.params.get('name')
    code = request.params.get('code')

    status_id = request.params.get('status_id')
    status = Status.query.filter_by(id=status_id).first()

    if sequence and code and name and status:
        # get descriptions
        description = request.params.get('description')

        #update the sequence
        sequence.name = name
        sequence.code = code
        sequence.description = description
        sequence.status = status
        sequence.updated_by = logged_in_user
        sequence.date_updated = datetime.datetime.now()

        DBSession.add(sequence)

    else:
        logger.debug('there are missing parameters')
        logger.debug('name      : %s' % name)
        logger.debug('status    : %s' % status)
        HTTPServerError()

    return HTTPOk()
Пример #13
0
    def test_creating_a_time_log_for_a_task_whose_dependent_tasks_has_not_finished_yet(self):
        """testing if a HTTPServer error will be raised when a time log tried
        to be created for a Task whose dependent tasks has not finished yet
        """
        # create a new task
        task2 = Task(
            name='Test Task 2',
            project=self.proj1,
            depends=[self.task1],
            resources=[self.user1],
            schedule_timing=4,
            schedule_unit='d',
            schedule_model='effort',
            status_list=self.task_status_list
        )
        DBSession.add(task2)
        DBSession.flush()
        transaction.commit()

        # now because task2 is depending on to the task1
        # and task1 is not finished yet (where the status is not
        # set to Complete, we should expect an HTTPServerError()
        # to be raised
        request = testing.DummyRequest()
        request.params['task_id'] = task2.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 01 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 01 Nov 2013 17:00:00 GMT"

        response = time_log.create_time_log(request)
        self.assertEqual(
            response.status_int, 500
        )
Пример #14
0
    def test_update_with_studio_is_working_properly(self):
        """testing if the default values are updated with the Studio instance
        if there is a database connection and there is a Studio in there
        """
        import datetime
        from stalker import db, defaults
        from stalker.db.session import DBSession
        from stalker.models.studio import Studio

        db.setup()
        db.init()

        # check the defaults are still using them self
        self.assertEqual(
            defaults.timing_resolution,
            datetime.timedelta(hours=1)
        )

        studio = Studio(
            name='Test Studio',
            timing_resolution=datetime.timedelta(minutes=15)
        )
        DBSession.add(studio)
        DBSession.commit()

        # now check it again
        self.assertEqual(
            defaults.timing_resolution,
            studio.timing_resolution
        )
Пример #15
0
    def test_logged_in_user_returns_the_stored_User_instance_from_last_time(
            self):
        """testing if logged_in_user returns the logged in user
        """
        # create a new user
        new_user = User(name='Test User',
                        login='******',
                        email='*****@*****.**',
                        password='******')

        # save it to the Database
        DBSession.add(new_user)
        DBSession.commit()

        self.assertTrue(new_user.id is not None)

        # save it to the local storage
        local_session = LocalSession()
        local_session.store_user(new_user)

        # save the session
        local_session.save()

        # now get it back with a new local_session
        local_session2 = LocalSession()

        self.assertEqual(local_session2.logged_in_user_id, new_user.id)

        self.assertEqual(local_session2.logged_in_user, new_user)
Пример #16
0
 def test_depends_to_argument_is_skipped_raises_error_on_commit(self):
     """testing if an Integrity error will be raised when the depends_to
     argument is skipped and the session is committed
     """
     self.kwargs.pop('depends_to')
     new_dependency = TaskDependency(**self.kwargs)
     DBSession.add(new_dependency)
     self.assertRaises(IntegrityError, DBSession.commit)
Пример #17
0
    def setUp(self):
        """set up
        """
        from stalker.db.declarative import Base
        Base.metadata.drop_all(db.DBSession.connection())
        DBSession.commit()

        super(TaskJugglerScheduler_PostgreSQL_Tester, self).setUp()
Пример #18
0
 def test_depends_to_argument_is_skipped_raises_error_on_commit(self):
     """testing if an Integrity error will be raised when the depends_to
     argument is skipped and the session is committed
     """
     self.kwargs.pop('depends_to')
     new_dependency = TaskDependency(**self.kwargs)
     DBSession.add(new_dependency)
     self.assertRaises(IntegrityError, DBSession.commit)
    def setUp(self):
        """set up
        """
        from stalker.db.declarative import Base
        Base.metadata.drop_all(db.DBSession.connection())
        DBSession.commit()

        super(TaskJugglerScheduler_PostgreSQL_Tester, self).setUp()
Пример #20
0
def update_department(request):
    """updates an Department
    """

    logger.debug('***update department method starts ***')

    logged_in_user = get_logged_in_user(request)

    # get params
    came_from = request.params.get('came_from', '/')
    department_id = request.matchdict.get('id', -1)
    department = Department.query.filter_by(id=department_id).first()

    name = request.params.get('name')

    logger.debug('department : %s' % department)
    logger.debug('department new name : %s' % name)


    if department and name:

        description = request.params.get('description')

        lead_id = request.params.get('lead_id', -1)
        lead = User.query.filter_by(id=lead_id).first()

        # Tags
        tags = get_tags(request)

        logger.debug('department new description : %s' % description)
        logger.debug('department new lead : %s' % lead)
        logger.debug('department new tags : %s' % tags)

        # update the department
        department.name = name
        department.description = description

        department.lead = lead
        department.tags = tags
        department.updated_by = logged_in_user
        department.date_updated = datetime.datetime.now()

        DBSession.add(department)

        logger.debug('department is updated successfully')

        request.session.flash(
                'success:Department <strong>%s</strong> is updated successfully' % name
            )

        logger.debug('***update department method ends ***')
    else:
        logger.debug('not all parameters are in request.params')
        log_param(request, 'department_id')
        log_param(request, 'name')
        HTTPServerError()

    return Response('Successfully updated department: %s' % department_id)
Пример #21
0
    def save_as(self, version):
        """the save action for houdini environment
        """
        if not version:
            return

        from stalker import Version
        assert isinstance(version, Version)

        # get the current version, and store it as the parent of the new version
        current_version = self.get_current_version()

        # initialize path variables by using update_paths()
        version.update_paths()

        # set the extension to hip
        if not hou.isApprentice():
            version.extension = '.hip'
        else:
            version.extension = '.hipnc'

        # define that this version is created with Houdini
        version.created_with = self.name

        # create the folder if it doesn't exists
        try:
            os.makedirs(os.path.dirname(version.absolute_full_path))
        except OSError:
            # dirs exist
            pass

        # houdini uses / instead of \ under windows
        # lets fix it

        # set the environment variables
        self.set_environment_variables(version)

        # set the render file name
        self.set_render_filename(version)

        # houdini accepts only strings as file name, no unicode support as I
        # see
        hou.hipFile.save(file_name=str(version.absolute_full_path))

        # set the environment variables again
        self.set_environment_variables(version)

        # append it to the recent file list
        self.append_to_recent_files(version.absolute_full_path)

        # update the parent info
        if current_version:
            version.parent = current_version

            # update database with new version info
            DBSession.commit()

        return True
Пример #22
0
    def tearDown(self):
        """clean up the test
        """
        from stalker.db import DBSession
        DBSession.remove()

        # and remove the temp directory
        shutil.rmtree(self.temp_config_folder)
        # restore defaults.timing_resolution
        stalker.defaults.timing_resolution = datetime.timedelta(hours=1)
Пример #23
0
    def tearDown(self):
        """clean up the test
        """
        from stalker.db import DBSession
        DBSession.remove()

        # and remove the temp directory
        shutil.rmtree(self.temp_config_folder)
        # restore defaults.timing_resolution
        stalker.defaults.timing_resolution = datetime.timedelta(hours=1)
Пример #24
0
    def test_tasks_are_correctly_scheduled(self):
        """testing if the tasks are correctly scheduled
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=True)
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_proj1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_proj1.computed_end
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task1.computed_end
        )
        self.assertEqual(
            sorted([self.test_user1, self.test_user2], key=lambda x: x.name),
            sorted(self.test_task1.computed_resources, key=lambda x: x.name)
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task2.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_task2.computed_end
        )

        self.assertEqual(2, len(self.test_task2.computed_resources))

        possible_resources = [
            self.test_user2, self.test_user3,
            self.test_user4, self.test_user5
        ]
        for r in self.test_task2.computed_resources:
            self.assertIn(r, possible_resources)
Пример #25
0
def update_group(request):
    """updates the group with data from request
    """

    logger.debug('***update group method starts ***')

    logged_in_user = get_logged_in_user(request)

    # get parameters
    post_multi_dict = request.POST

    came_from = request.params.get('came_from', '/')
    group_id = int(post_multi_dict['group_id'])
    group = Group.query.filter_by(id=group_id).first()

    name = post_multi_dict['name']

    if group and name:

        description = post_multi_dict['description']

        # remove name and description to leave only permission in the dictionary
        post_multi_dict.pop('name')
        post_multi_dict.pop('description')
        permissions = get_permissions_from_multi_dict(post_multi_dict)

         # update the group
        group.name = name
        group.description = description
        group.permissions = permissions
        group.updated_by = logged_in_user
        group.date_updated = datetime.datetime.now()

        DBSession.add(group)

        logger.debug('group is updated successfully')

        request.session.flash(
                'success:Group <strong>%s</strong> is updated successfully' % name
            )

        logger.debug('***update group method ends ***')
    else:
        logger.debug('not all parameters are in request.params')
        log_param(request, 'group_id')
        log_param(request, 'name')
        response = Response(
            'There are missing parameters: '
            'group_id: %s, name: %s' % (group_id, name), 500
        )
        transaction.abort()
        return response

    response = Response('successfully updated %s group!' % name)
    return response
Пример #26
0
 def tearDown(self):
     """clean up the test
     """
     # clean up test database
     from stalker.db.declarative import Base
     Base.metadata.drop_all(db.DBSession.connection())
     from sqlalchemy.exc import ProgrammingError
     try:
         DBSession.commit()
     except ProgrammingError:
         DBSession.rollback()
Пример #27
0
    def test_tasks_of_given_projects_are_correctly_scheduled(self):
        """testing if the tasks of given projects are correctly scheduled
        """
        # create a dummy project
        # create a dummy Project to schedule
        dummy_project = Project(name="Dummy Project", code="DP", repository=self.test_repo)

        dt1 = Task(
            name="Dummy Task 1",
            project=dummy_project,
            schedule_timing=4,
            schedule_unit="h",
            resources=[self.test_user1],
        )

        dt2 = Task(
            name="Dummy Task 2",
            project=dummy_project,
            schedule_timing=4,
            schedule_unit="h",
            resources=[self.test_user2],
        )
        db.DBSession.add_all([dummy_project, dt1, dt2])
        db.DBSession.commit()

        tjp_sched = TaskJugglerScheduler(compute_resources=True, projects=[dummy_project])
        test_studio = Studio(name="Test Studio", now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)
        db.DBSession.commit()

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(self.test_proj1.computed_start, None)
        self.assertEqual(self.test_proj1.computed_end, None)

        self.assertEqual(self.test_task1.computed_start, None)
        self.assertEqual(self.test_task1.computed_end, None)
        self.assertEqual(self.test_task1.computed_resources, [self.test_user1, self.test_user2])

        self.assertEqual(self.test_task2.computed_start, None)
        self.assertEqual(self.test_task2.computed_end, None)
        self.assertEqual(self.test_task2.computed_resources, [self.test_user1, self.test_user2])

        self.assertEqual(dt1.computed_start, datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt1.computed_end, datetime.datetime(2013, 4, 16, 13, 0))

        self.assertEqual(dt2.computed_start, datetime.datetime(2013, 4, 16, 9, 0))
        self.assertEqual(dt2.computed_end, datetime.datetime(2013, 4, 16, 13, 0))
 def tearDown(self):
     """clean up the test
     """
     # clean up test database
     from stalker.db.declarative import Base
     Base.metadata.drop_all(db.DBSession.connection())
     from sqlalchemy.exc import ProgrammingError
     try:
         DBSession.commit()
     except ProgrammingError:
         DBSession.rollback()
Пример #29
0
def update_project(request):
    """called when updating a Project
    """
    logged_in_user = get_logged_in_user(request)

    # parameters
    project_id = request.params.get('project_id', -1)
    project = Project.query.filter_by(id=project_id).first()

    name = request.params.get('name')

    fps = int(request.params.get('fps'))

    imf_id = request.params.get('image_format', -1)
    imf = ImageFormat.query.filter_by(id=imf_id).first()

    repo_id = request.params.get('repository_id', -1)
    repo = Repository.query.filter_by(id=repo_id).first()

    structure_id = request.params.get('structure_id', -1)
    structure = Structure.query.filter_by(id=structure_id).first()

    lead_id = request.params.get('lead_id', -1)
    lead = User.query.filter_by(id=lead_id).first()

    status_id = request.params.get('status_id', -1)
    status = Status.query.filter_by(id=status_id).first()

    # get the dates
    start = get_date(request, 'start')
    end = get_date(request, 'end')

    if project and name and imf and repo and structure and lead and \
            status:

        project.name = name
        project.image_format = imf
        project.repository = repo
        project.updated_by = logged_in_user
        project.date_updated = datetime.datetime.now()
        project.fps = fps
        project.structure = structure
        project.lead = lead
        project.status = status
        project.start = start
        project.end = end

        DBSession.add(project)

    else:
        logger.debug('there are missing parameters')
        HTTPServerError()

    return HTTPOk()
Пример #30
0
    def test_delete_will_delete_the_session_cache(self):
        """testing if the LocalSession.delete() will delete the current cache
        file
        """
        # create a new user
        new_user = User(
            name='Test User',
            login='******',
            email='*****@*****.**',
            password='******'
        )

        # save it to the Database
        DBSession.add(new_user)
        DBSession.commit()

        self.assertTrue(new_user.id is not None)

        # save it to the local storage
        local_session = LocalSession()
        local_session.store_user(new_user)

        # save the session
        local_session.save()

        # check if the file is created
        # check if a file is created in the users local storage
        self.assertTrue(
            os.path.exists(
                os.path.join(
                    defaults.local_storage_path,
                    defaults.local_session_data_file_name
                )
            )
        )

        # now delete the session by calling delete()
        local_session.delete()

        # check if the file is gone
        # check if a file is created in the users local storage
        self.assertFalse(
            os.path.exists(
                os.path.join(
                    defaults.local_storage_path,
                    defaults.local_session_data_file_name
                )
            )
        )

        # delete a second time
        # this should not raise an OSError
        local_session.delete()
Пример #31
0
def update_studio(request):
    """updates the studio
    """

    studio_id = request.params.get('studio_id')
    studio = Studio.query.filter_by(id=studio_id).first()

    name = request.params.get('name', None)
    dwh = request.params.get('dwh', None)
    wh_mon_start = get_time(request, 'mon_start')
    wh_mon_end   = get_time(request, 'mon_end')
    wh_tue_start = get_time(request, 'tue_start')
    wh_tue_end   = get_time(request, 'tue_end')
    wh_wed_start = get_time(request, 'wed_start')
    wh_wed_end   = get_time(request, 'wed_end')
    wh_thu_start = get_time(request, 'thu_start')
    wh_thu_end   = get_time(request, 'thu_end')
    wh_fri_start = get_time(request, 'fri_start')
    wh_fri_end   = get_time(request, 'fri_end')
    wh_sat_start = get_time(request, 'sat_start')
    wh_sat_end   = get_time(request, 'sat_end')
    wh_sun_start = get_time(request, 'sun_start')
    wh_sun_end   = get_time(request, 'sun_end')

    if studio and name and dwh:
        # update new studio

        studio.name=name
        studio.daily_working_hours=int(dwh)

        wh = WorkingHours()

        def set_wh_for_day(day, start, end):
            if start != end:
                wh[day] = [[start.seconds/60, end.seconds/60]]
            else:
                wh[day] = []

        set_wh_for_day('mon', wh_mon_start, wh_mon_end)
        set_wh_for_day('tue', wh_tue_start, wh_tue_end)
        set_wh_for_day('wed', wh_wed_start, wh_wed_end)
        set_wh_for_day('thu', wh_thu_start, wh_thu_end)
        set_wh_for_day('fri', wh_fri_start, wh_fri_end)
        set_wh_for_day('sat', wh_sat_start, wh_sat_end)
        set_wh_for_day('sun', wh_sun_start, wh_sun_end)

        studio.working_hours = wh

        DBSession.add(studio)
        # Commit will be handled by the zope transaction extension

    return HTTPOk()
Пример #32
0
def create_shot(request):
    """runs when adding a new shot
    """
    logged_in_user = get_logged_in_user(request)

    name = request.params.get("name")
    code = request.params.get("code")

    status_id = request.params.get("status_id")
    status = Status.query.filter_by(id=status_id).first()

    project_id = request.params.get("project_id")
    project = Project.query.filter_by(id=project_id).first()
    logger.debug("project_id   : %s" % project_id)

    if name and code and status and project:
        # get descriptions
        description = request.params.get("description")

        sequence_id = request.params["sequence_id"]
        sequence = Sequence.query.filter_by(id=sequence_id).first()

        # get the status_list
        status_list = StatusList.query.filter_by(target_entity_type="Shot").first()

        # there should be a status_list
        # TODO: you should think about how much possible this is
        if status_list is None:
            return HTTPServerError(detail="No StatusList found")

        new_shot = Shot(
            name=name,
            code=code,
            description=description,
            sequence=sequence,
            status_list=status_list,
            status=status,
            created_by=logged_in_user,
            project=project,
        )

        DBSession.add(new_shot)

    else:
        logger.debug("there are missing parameters")
        logger.debug("name      : %s" % name)
        logger.debug("code      : %s" % code)
        logger.debug("status    : %s" % status)
        logger.debug("project   : %s" % project)
        HTTPServerError()

    return HTTPOk()
Пример #33
0
    def test_creating_a_time_log_for_a_task_whose_dependending_tasks_already_has_time_logs(self):
        """testing if a HTTPServer error will be raised when a time log tried
        to be for a task whose depending tasks already has time logs created
        (This test should be in Stalker)
        """
        # create a new task
        task2 = Task(
            name='Test Task 2',
            project=self.proj1,
            depends=[self.task1],
            resources=[self.user1],
            schedule_timing=4,
            schedule_unit= 'd',
            schedule_model='effort',
            status_list=self.task_status_list
        )
        DBSession.add(task2)
        DBSession.flush()
        transaction.commit()

        # set the status of task1 to complete
        self.task1.status = self.status_cmpl
        # artificially update task2 status to rts
        task2.status = self.status_rts
        DBSession.flush()
        transaction.commit()

        # and now create time logs for task2
        request = testing.DummyRequest()
        request.params['task_id'] = task2.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 01 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 01 Nov 2013 17:00:00 GMT"
        response = time_log.create_time_log(request)
        self.assertEqual(response.status_int, 200)
        DBSession.add(task2)
        DBSession.flush()
        transaction.commit()

        # now because task2 is depending on to the task1
        # and task2 has now started, entering any new time logs to task1
        # is forbidden
        request = testing.DummyRequest()
        request.params['task_id'] = self.task1.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 02 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 02 Nov 2013 17:00:00 GMT"

        response = time_log.create_time_log(request)
        self.assertEqual(
            response.status_int, 500
        )
 def setUpClass(cls):
     """setup tests in class level
     """
     cls.config = {
         'sqlalchemy.url':
             'postgresql://*****:*****@localhost/stalker_test',
         'sqlalchemy.echo': False
     }
     # clean up test database
     db.setup(cls.config)
     from stalker.db.declarative import Base
     Base.metadata.drop_all(db.DBSession.connection())
     DBSession.commit()
Пример #35
0
 def setUpClass(cls):
     """setup tests in class level
     """
     cls.config = {
         'sqlalchemy.url':
             'postgresql://*****:*****@localhost/stalker_test',
         'sqlalchemy.echo': False
     }
     # clean up test database
     db.setup(cls.config)
     from stalker.db.declarative import Base
     Base.metadata.drop_all(db.DBSession.connection())
     DBSession.commit()
    def test_tasks_are_correctly_scheduled_when_compute_resources_is_False(self):
        """testing if the tasks are correctly scheduled when the compute
        resources is False
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=False)
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_proj1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 19, 12, 0),
            self.test_proj1.computed_end
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task1.computed_end
        )
        self.assertItemsEqual(
            self.test_task1.resources,
            self.test_task1.computed_resources
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task2.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 19, 12, 0),
            self.test_task2.computed_end
        )
        self.assertItemsEqual(
            self.test_task2.resources,
            self.test_task2.computed_resources
        )
Пример #37
0
def create_sequence(request):
    """runs when adding a new sequence
    """
    logged_in_user = get_logged_in_user(request)

    name = request.params.get('name')
    code = request.params.get('code')

    status_id = request.params.get('status_id')
    status = Status.query.filter_by(id=status_id).first()

    project_id = request.params.get('project_id')
    project = Project.query.filter_by(id=project_id).first()

    logger.debug('project_id   : %s' % project_id)

    if name and code and status and project:
        # get descriptions
        description = request.params.get('description')

        # get the status_list
        status_list = StatusList.query.filter_by(
            target_entity_type='Sequence'
        ).first()

        # there should be a status_list
        # TODO: you should think about how much possible this is
        if status_list is None:
            return HTTPServerError(detail='No StatusList found')

        new_sequence = Sequence(
            name=name,
            code=code,
            description=description,
            status_list=status_list,
            status=status,
            created_by=logged_in_user,
            project=project
        )

        DBSession.add(new_sequence)

    else:
        logger.debug('there are missing parameters')
        logger.debug('name      : %s' % name)
        logger.debug('code      : %s' % code)
        logger.debug('status    : %s' % status)
        logger.debug('project   : %s' % project)
        HTTPServerError()

    return HTTPOk()
Пример #38
0
    def test_tasks_are_correctly_scheduled_when_compute_resources_is_False(self):
        """testing if the tasks are correctly scheduled when the compute
        resources is False
        """
        tjp_sched = TaskJugglerScheduler(compute_resources=False)
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.start = datetime.datetime(2013, 4, 16, 0, 0)
        test_studio.end = datetime.datetime(2013, 4, 30, 0, 0)
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()
        db.DBSession.commit()

        # check if the task and project timings are all adjusted
        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_proj1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_proj1.computed_end
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 16, 9, 0),
            self.test_task1.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task1.computed_end
        )
        self.assertEqual(
            sorted(self.test_task1.resources, key=lambda x: x.name),
            sorted(self.test_task1.computed_resources, key=lambda x: x.name)
        )

        self.assertEqual(
            datetime.datetime(2013, 4, 18, 16, 0),
            self.test_task2.computed_start
        )
        self.assertEqual(
            datetime.datetime(2013, 4, 24, 10, 0),
            self.test_task2.computed_end
        )
        self.assertEqual(
            sorted(self.test_task2.resources, key=lambda x: x.name),
            sorted(self.test_task2.computed_resources, key=lambda x: x.name)
        )
Пример #39
0
    def test_LocalSession_will_not_use_the_stored_data_if_it_is_invalid(self):
        """testing if the LocalSession will not use the stored session if it is
        not valid anymore
        """
        # create a new user
        new_user = User(
            name='Test User',
            login='******',
            email='*****@*****.**',
            password='******'
        )

        # save it to the Database
        DBSession.add(new_user)
        DBSession.commit()

        self.assertTrue(new_user.id is not None)

        # save it to the local storage
        local_session = LocalSession()
        local_session.store_user(new_user)

        # save the session
        local_session.save()

        # set the valid time to an early date
        local_session.valid_to = \
            datetime.datetime.now() - datetime.timedelta(10)

        # pickle the data
        data = json.dumps(
            {
                'valid_to': local_session.valid_to,
                'logged_in_user_id': -1
            },
            default=local_session.default_json_serializer
        )
        print('data: %s' % data)
        local_session._write_data(data)

        # now get it back with a new local_session
        local_session2 = LocalSession()

        self.assertEqual(
            local_session2.logged_in_user_id, None
        )

        self.assertTrue(local_session2.logged_in_user is None)
Пример #40
0
def get_shots_children_task_type(request):
    """returns the Task Types defined under the Shot container
    """

    sql_query = """select
        "SimpleEntities".id as type_id,
        "SimpleEntities".name as type_name
    from "SimpleEntities"
    join "SimpleEntities" as "Task_SimpleEntities" on "SimpleEntities".id = "Task_SimpleEntities".type_id
    join "Tasks" on "Task_SimpleEntities".id = "Tasks".id
    join "Shots" on "Tasks".parent_id = "Shots".id
    group by "SimpleEntities".id, "SimpleEntities".name
    order by "SimpleEntities".name"""

    result = DBSession.connection().execute(sql_query)

    return_data = [{"id": r[0], "name": r[1]} for r in result.fetchall()]

    content_range = "%s-%s/%s"

    type_count = len(return_data)
    content_range = content_range % (0, type_count - 1, type_count)

    logger.debug("content_range : %s" % content_range)

    resp = Response(json_body=return_data)
    resp.content_range = content_range
    return resp
Пример #41
0
def create_version_dialog(request):
    """creates a create_version_dialog by using the given task
    """
    logger.debug('inside create_version_dialog')

    # get logged in user
    logged_in_user = get_logged_in_user(request)

    task_id = request.matchdict.get('id', -1)
    task = Task.query.filter(Task.task_id == task_id).first()

    takes = map(
        lambda x: x[0],
        DBSession.query(distinct(Version.take_name))
        .filter(Version.task == task)
        .all()
    )

    if defaults.version_take_name not in takes:
        takes.append(defaults.version_take_name)

    return {
        'mode': 'CREATE',
        'has_permission': PermissionChecker(request),
        'logged_in_user': logged_in_user,
        'task': task,
        'default_take_name': defaults.version_take_name,
        'take_names': [defaults.version_take_name]
    }
Пример #42
0
    def test_delete_will_delete_the_session_cache(self):
        """testing if the LocalSession.delete() will delete the current cache
        file
        """
        # create a new user
        new_user = User(name='Test User',
                        login='******',
                        email='*****@*****.**',
                        password='******')

        # save it to the Database
        DBSession.add(new_user)
        DBSession.commit()

        self.assertTrue(new_user.id is not None)

        # save it to the local storage
        local_session = LocalSession()
        local_session.store_user(new_user)

        # save the session
        local_session.save()

        # check if the file is created
        # check if a file is created in the users local storage
        self.assertTrue(
            os.path.exists(
                os.path.join(defaults.local_storage_path,
                             defaults.local_session_data_file_name)))

        # now delete the session by calling delete()
        local_session.delete()

        # check if the file is gone
        # check if a file is created in the users local storage
        self.assertFalse(
            os.path.exists(
                os.path.join(defaults.local_storage_path,
                             defaults.local_session_data_file_name)))

        # delete a second time
        # this should not raise an OSError
        local_session.delete()
Пример #43
0
    def test_LocalSession_will_not_use_the_stored_data_if_it_is_invalid(self):
        """testing if the LocalSession will not use the stored session if it is
        not valid anymore
        """
        # create a new user
        new_user = User(name='Test User',
                        login='******',
                        email='*****@*****.**',
                        password='******')

        # save it to the Database
        DBSession.add(new_user)
        DBSession.commit()

        self.assertTrue(new_user.id is not None)

        # save it to the local storage
        local_session = LocalSession()
        local_session.store_user(new_user)

        # save the session
        local_session.save()

        # set the valid time to an early date
        local_session.valid_to = \
            datetime.datetime.now() - datetime.timedelta(10)

        # pickle the data
        data = json.dumps(
            {
                'valid_to': local_session.valid_to,
                'logged_in_user_id': -1
            },
            default=local_session.default_json_serializer)
        print('data: %s' % data)
        local_session._write_data(data)

        # now get it back with a new local_session
        local_session2 = LocalSession()

        self.assertEqual(local_session2.logged_in_user_id, None)

        self.assertTrue(local_session2.logged_in_user is None)
Пример #44
0
def do_db_setup():
    """the common routing for setting up the database
    """
    from sqlalchemy.exc import UnboundExecutionError

    from stalker import db
    from stalker.db import DBSession

    DBSession.remove()
    DBSession.close()

    try:
        DBSession.connection()
        logger.debug('already connected, not creating any new connections')
    except UnboundExecutionError:
        # no connection do setup
        logger.debug('doing a new connection with NullPool')
        from stalker import defaults
        from sqlalchemy.pool import NullPool
        settings = defaults.database_engine_settings
        settings['sqlalchemy.poolclass'] = NullPool
        db.setup(settings)
Пример #45
0
 def tearDown(self):
     """clean up the test
     """
     DBSession.remove()
Пример #46
0
    def setUp(self):
        """set up the test
        """
        db.setup()
        db.init()

        self.user1 = User(
            name='Test User 1',
            login='******',
            email='*****@*****.**',
            password='******'
        )
        DBSession.add(self.user1)

        self.user2 = User(
            name='Test User 2',
            login='******',
            email='*****@*****.**',
            password='******'
        )
        DBSession.add(self.user2)

        self.user3 = User(
            name='Test User 2',
            login='******',
            email='*****@*****.**',
            password='******'
        )
        DBSession.add(self.user3)

        # Review Statuses
        self.status_new = Status.query.filter_by(code='NEW').first()
        self.status_rrev = Status.query.filter_by(code='RREV').first()
        self.status_app = Status.query.filter_by(code='APP').first()

        # Task Statuses
        self.status_wfd = Status.query.filter_by(code='WFD').first()
        self.status_rts = Status.query.filter_by(code='RTS').first()
        self.status_wip = Status.query.filter_by(code='WIP').first()
        self.status_prev = Status.query.filter_by(code='PREV').first()
        self.status_hrev = Status.query.filter_by(code='HREV').first()
        self.status_drev = Status.query.filter_by(code='DREV').first()
        self.status_cmpl = Status.query.filter_by(code='CMPL').first()

        self.project_status_list = StatusList(
            target_entity_type='Project',
            statuses=[
                self.status_new, self.status_wip, self.status_cmpl
            ]
        )
        DBSession.add(self.project_status_list)

        self.temp_path = tempfile.mkdtemp()
        self.repo = Repository(
            name='Test Repository',
            linux_path=self.temp_path,
            windows_path=self.temp_path,
            osx_path=self.temp_path
        )
        DBSession.add(self.repo)

        self.structure = Structure(
            name='Test Project Structure'
        )
        DBSession.add(self.structure)

        self.project = Project(
            name='Test Project',
            code='TP',
            status_list=self.project_status_list,
            repository=self.repo
        )
        DBSession.add(self.project)

        self.task1 = Task(
            name='Test Task 1',
            project=self.project,
            resources=[self.user1],
            responsible=[self.user2]
        )
        DBSession.add(self.task1)

        self.task2 = Task(
            name='Test Task 2',
            project=self.project,
            responsible=[self.user1]
        )
        DBSession.add(self.task2)

        self.task3 = Task(
            name='Test Task 3',
            parent=self.task2,
            resources=[self.user1]
        )
        DBSession.add(self.task3)

        self.task4 = Task(
            name='Test Task 4',
            project=self.project,
            resources=[self.user1],
            depends=[self.task3],
            responsible=[self.user2],
            schedule_timing=2,
            schedule_unit='h'
        )
        DBSession.add(self.task4)

        self.task5 = Task(
            name='Test Task 5',
            project=self.project,
            resources=[self.user2],
            depends=[self.task3],
            responsible=[self.user2],
            schedule_timing=2,
            schedule_unit='h'
        )
        DBSession.add(self.task5)

        self.task6 = Task(
            name='Test Task 6',
            project=self.project,
            resources=[self.user3],
            depends=[self.task3],
            responsible=[self.user2],
            schedule_timing=2,
            schedule_unit='h'
        )
        DBSession.add(self.task6)

        self.kwargs = {
            'task': self.task1,
            'reviewer': self.user1
        }
        #self.review = Review(**self.kwargs)
        #DBSession.add(self.review)

        # add everything to the db
        DBSession.commit()
Пример #47
0
    def save_as(self, version):
        """"the save action for nuke environment

        uses Nukes own python binding
        """

        # get the current version, and store it as the parent of the new version
        current_version = self.get_current_version()

        # first initialize the version path
        version.update_paths()

        # set the extension to '.nk'
        version.extension = '.nk'

        # set created_with to let the UI show Nuke icon in versions list
        version.created_with = self.name

        # set project_directory
        # self.project_directory = os.path.dirname(version.absolute_path)

        # create the main write node
        self.create_main_write_node(version)

        # replace read and write node paths
        # self.replace_external_paths()

        # create the path before saving
        try:
            os.makedirs(version.absolute_path)
        except OSError:
            # path already exists OSError
            pass

        # set frame range
        # if this is a shot related task set it to shots resolution
        is_shot_related_task = False
        shot = None
        from stalker import Shot
        for task in version.task.parents:
            if isinstance(task, Shot):
                is_shot_related_task = True
                shot = task
                break

        # set scene fps
        project = version.task.project
        self.set_fps(project.fps)

        if version.version_number == 1:
            if is_shot_related_task:
                # just set if the frame range is not 1-1
                if shot.cut_in != 1 and shot.cut_out != 1:
                    self.set_frame_range(
                        shot.cut_in,
                        shot.cut_out
                    )
                imf = shot.image_format
            else:
                imf = project.image_format

            # TODO: set the render resolution later
            # self.set_resolution(
            #     imf.width,
            #     imf.height,
            #     imf.pixel_aspect
            # )

        nuke.scriptSaveAs(version.absolute_full_path)

        if current_version:
            # update the parent info
            version.parent = current_version

            # update database with new version info
            DBSession.commit()

        return True
Пример #48
0
 def tearDownClass(cls):
     """clear the test in class level
     """
     DBSession.remove()
Пример #49
0
    def setUp(self):
        """set up the test
        """
        db.setup()
        db.init()

        # get statuses
        self.status_new = Status.query.filter_by(code="NEW").first()
        self.status_wfd = Status.query.filter_by(code="WFD").first()
        self.status_rts = Status.query.filter_by(code="RTS").first()
        self.status_wip = Status.query.filter_by(code="WIP").first()
        self.status_prev = Status.query.filter_by(code="PREV").first()
        self.status_hrev = Status.query.filter_by(code="HREV").first()
        self.status_drev = Status.query.filter_by(code="DREV").first()
        self.status_oh = Status.query.filter_by(code="OH").first()
        self.status_stop = Status.query.filter_by(code="STOP").first()
        self.status_cmpl = Status.query.filter_by(code="CMPL").first()

        self.test_user1 = User(name='Test User 1',
                               login='******',
                               email='*****@*****.**',
                               password='******')

        self.test_user2 = User(name='Test User 2',
                               login='******',
                               email='*****@*****.**',
                               password='******')

        self.test_user3 = User(name='Test User 1',
                               login='******',
                               email='*****@*****.**',
                               password='******')

        self.test_repo = Repository(name='Test Repository')

        self.test_structure = Structure(name='test structure')

        # project status list
        self.test_project_status_list = StatusList(
            name='Project Statuses',
            target_entity_type='Project',
            statuses=[
                self.status_new, self.status_wip, self.status_oh,
                self.status_stop, self.status_cmpl
            ])
        self.test_project1 = Project(name='Test Project 1',
                                     code='TP1',
                                     repository=self.test_repo,
                                     structure=self.test_structure,
                                     status_list=self.test_project_status_list)

        # create three Tasks
        self.test_task1 = Task(name='Test Task 1', project=self.test_project1)

        self.test_task2 = Task(name='Test Task 2', project=self.test_project1)

        self.test_task3 = Task(name='Test Task 3', project=self.test_project1)

        # add everything to db
        DBSession.add_all([
            self.test_project1, self.test_project_status_list, self.test_repo,
            self.test_structure, self.test_task1, self.test_task2,
            self.test_task3, self.test_user1, self.test_user2
        ])
        DBSession.commit()

        self.kwargs = {
            'task': self.test_task1,
            'depends_to': self.test_task2,
            'dependency_target': 'onend',
            'gap_timing': 0,
            'gap_unit': 'h',
            'gap_model': 'length'
        }
Пример #50
0
 def setUpClass(cls):
     """set up the test in class level
     """
     DBSession.remove()
     DBSession.configure(extension=None)
Пример #51
0
    def test_get_version_from_full_path_with_multiple_repositories(self):
        """testing if the get version from full path is working fine with
        multiple repositories and with same version names
        """
        repo1 = Repository(name='Test Repo 1',
                           linux_path='/mnt/T/',
                           windows_path='T:/',
                           osx_path='/Volumes/T/')
        DBSession.add(repo1)

        repo2 = Repository(name='Test Repo 2',
                           linux_path='/mnt/S/',
                           windows_path='S:/',
                           osx_path='/Volumes/S/')
        DBSession.add(repo2)

        task_ft = FilenameTemplate(
            name='Task Filename Template',
            target_entity_type='Task',
            path='$REPO{{project.repository.code}}/{{project.code}}/'
            '{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/{%- endfor -%}',
            filename='{{task.nice_name}}_{{version.take_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )
        DBSession.add(task_ft)

        structure1 = Structure(name='Commercial Project Structure',
                               templates=[task_ft])
        DBSession.add(structure1)

        status1 = Status(name='Status 1', code='STS1')
        status2 = Status(name='Status 2', code='STS2')
        status3 = Status(name='Status 3', code='STS3')
        DBSession.add_all([status1, status2, status3])

        proj_status_list = \
            StatusList.query.filter_by(target_entity_type='Project').first()

        task_status_list = \
            StatusList.query.filter_by(target_entity_type='Task').first()

        version_status_list = StatusList(name='Version Statuses',
                                         target_entity_type='Version',
                                         statuses=[status1, status2, status3])
        DBSession.add(version_status_list)

        project1 = Project(name='Test Project 1',
                           code='TP1',
                           repositories=[repo1],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project1)

        project2 = Project(name='Test Project 2',
                           code='TP2',
                           repositories=[repo2],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project2)

        task1 = Task(name='Test Task 1',
                     code='TT1',
                     project=project1,
                     status_list=task_status_list)
        DBSession.add(task1)

        task2 = Task(name='Test Task 1',
                     code='TT1',
                     project=project2,
                     status_list=task_status_list)
        DBSession.add(task2)

        DBSession.commit()

        # now create versions
        version1 = Version(task=task1, status_list=version_status_list)
        DBSession.add(version1)
        DBSession.commit()
        version1.update_paths()

        version2 = Version(task=task2, status_list=version_status_list)
        DBSession.add(version2)
        DBSession.commit()
        version2.update_paths()

        DBSession.commit()
        logger.debug('version1.full_path : %s' % version1.full_path)
        logger.debug('version2.full_path : %s' % version2.full_path)

        # now try to get the versions with an EnvironmentBase instance
        env = EnvironmentBase()

        # version1
        version1_found = env.get_version_from_full_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2
        version2_found = env.get_version_from_full_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)

        # version1 in windows
        version1_found = env.get_version_from_full_path(
            'T:/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2 in windows
        version2_found = env.get_version_from_full_path(
            'S:/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)

        # version1 in linux
        version1_found = env.get_version_from_full_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2 in linux
        version2_found = env.get_version_from_full_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)

        # version1 in osx
        version1_found = env.get_version_from_full_path(
            '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2 in osx
        version2_found = env.get_version_from_full_path(
            '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)
Пример #52
0
    def setUp(self):
        """set up the test
        """
        # we need a database
        db.setup(self.config)
        db.init()

        # replace datetime now function

        # create departments
        self.test_dep1 = Department(name='Dep1')
        self.test_dep2 = Department(name='Dep2')

        # create resources
        self.test_user1 = User(
            login='******',
            name='User1',
            email='*****@*****.**',
            password='******',
            departments=[self.test_dep1]
        )
        DBSession.add(self.test_user1)

        self.test_user2 = User(
            login='******',
            name='User2',
            email='*****@*****.**',
            password='******',
            departments=[self.test_dep1]
        )
        DBSession.add(self.test_user2)

        self.test_user3 = User(
            login='******',
            name='User3',
            email='*****@*****.**',
            password='******',
            departments=[self.test_dep2]
        )
        DBSession.add(self.test_user3)

        self.test_user4 = User(
            login='******',
            name='User4',
            email='*****@*****.**',
            password='******',
            departments=[self.test_dep2]
        )
        DBSession.add(self.test_user4)

        # user with two departments
        self.test_user5 = User(
            login='******',
            name='User5',
            email='*****@*****.**',
            password='******',
            departments=[self.test_dep1, self.test_dep2]
        )
        DBSession.add(self.test_user5)

        # user with no departments
        self.test_user6 = User(
            login='******',
            name='User6',
            email='*****@*****.**',
            password='******'
        )
        DBSession.add(self.test_user6)

        # repository
        self.test_repo = Repository(
            name='Test Repository',
            linux_path='/mnt/T/',
            windows_path='T:/',
            osx_path='/Volumes/T/'
        )
        DBSession.add(self.test_repo)

        # statuses
        self.test_status1 = Status(name='Status 1', code='STS1')
        self.test_status2 = Status(name='Status 2', code='STS2')
        self.test_status3 = Status(name='Status 3', code='STS3')
        self.test_status4 = Status(name='Status 4', code='STS4')
        self.test_status5 = Status(name='Status 5', code='STS5')
        DBSession.add_all([self.test_status1,
                           self.test_status2,
                           self.test_status3,
                           self.test_status4,
                           self.test_status5])

        # status lists
        self.test_proj_status_list = StatusList(
            name='Project Status List',
            statuses=[self.test_status1, self.test_status2, self.test_status3],
            target_entity_type='Project'
        )
        DBSession.add(self.test_proj_status_list)

        # create one project
        self.test_proj1 = Project(
            name='Test Project 1',
            code='TP1',
            repository=self.test_repo,
            status_list=self.test_proj_status_list,
            start=datetime.datetime(2013, 4, 4),
            end=datetime.datetime(2013, 5, 4)
        )
        DBSession.add(self.test_proj1)
        self.test_proj1.now = datetime.datetime(2013, 4, 4)

        # create task status list
        with DBSession.no_autoflush:
            self.test_task_status_list = StatusList.query\
                .filter_by(target_entity_type='Task').first()

        # create two tasks with the same resources
        self.test_task1 = Task(
            name='Task1',
            project=self.test_proj1,
            resources=[self.test_user1, self.test_user2],
            alternative_resources=[
                self.test_user3, self.test_user4, self.test_user5
            ],
            schedule_model=0,
            schedule_timing=50,
            schedule_unit='h',
            status_list=self.test_task_status_list
        )
        DBSession.add(self.test_task1)

        self.test_task2 = Task(
            name='Task2',
            project=self.test_proj1,
            resources=[self.test_user1, self.test_user2],
            alternative_resources=[
                self.test_user3, self.test_user4, self.test_user5
            ],
            depends=[self.test_task1],
            schedule_model=0,
            schedule_timing=60,
            schedule_unit='h',
            status_list=self.test_task_status_list
        )
        DBSession.add(self.test_task2)
        DBSession.commit()
Пример #53
0
 def setUpClass(cls):
     """sets the test in class level
     """
     DBSession.remove()
Пример #54
0
 def tearDownClass(cls):
     """cleanup the test
     """
     DBSession.remove()
     DBSession.configure(extension=None)
Пример #55
0
 def setUp(self):
     """setup the test
     """
     DBSession.remove()
     db.setup()
     defaults.local_storage_path = tempfile.mktemp()
Пример #56
0
    def test_generic_data_attribute_can_hold_a_wide_variety_of_object_types(self):
        """testing if the generic_data attribute can hold any kind of object as
        a list
        """
        from stalker import db

        db.setup()

        new_simple_entity = SimpleEntity(**self.kwargs)
        test_user = User(
            name='email',
            login='******',
            email='*****@*****.**',
            password='******',
        )

        from stalker import Department

        test_department = Department(
            name='department1'
        )

        from stalker import Repository

        test_repo = Repository(
            name='Test Repository'
        )

        from stalker import Structure

        test_struct = Structure(
            name='Test Project Structure'
        )

        from stalker import Status, StatusList

        test_project_status_list = StatusList(
            name='Project Status List',
            target_entity_type='Project',
            statuses=[
                Status(name='Active', code='ACT')
            ]
        )

        from stalker import Project

        test_proj = Project(
            name='Test Project 1',
            code='tp1',
            repository=test_repo,
            structure=test_struct,
            status_list=test_project_status_list
        )

        new_simple_entity.generic_data.extend(
            [test_proj, test_project_status_list, test_struct, test_repo,
             test_department, test_user]
        )

        DBSession.add(new_simple_entity)
        DBSession.commit()

        # now check if it is added to the database correctly
        del new_simple_entity

        new_simple_entity_db = SimpleEntity.query \
            .filter_by(name=self.kwargs['name']) \
            .first()

        self.assertTrue(test_proj in new_simple_entity_db.generic_data)
        self.assertTrue(
            test_project_status_list in new_simple_entity_db.generic_data)
        self.assertTrue(test_struct in new_simple_entity_db.generic_data)
        self.assertTrue(test_repo in new_simple_entity_db.generic_data)
        self.assertTrue(test_department in new_simple_entity_db.generic_data)
        self.assertTrue(test_user in new_simple_entity_db.generic_data)

        DBSession.remove()
Пример #57
0
    def test_trim_repo_path_with_multiple_repositories(self):
        """testing if the trim_repo_path is working fine with multiple
        repositories and with same version names
        """
        repo0 = Repository(
            name='Test Repo 0',
            linux_path='/mnt/T/with_a_very_long_path_which_will_cause_errors/',
            windows_path='T:/with_a_very_long_path_which_will_cause_errors/',
            osx_path='/Volumes/T/'
            'with_a_very_long_path_which_will_cause_errors/')
        DBSession.add(repo0)

        repo1 = Repository(name='Test Repo 1',
                           linux_path='/mnt/T/',
                           windows_path='T:/',
                           osx_path='/Volumes/T/')
        DBSession.add(repo1)

        repo2 = Repository(name='Test Repo 2',
                           linux_path='/mnt/S/',
                           windows_path='S:/',
                           osx_path='/Volumes/S/')
        DBSession.add(repo2)

        task_ft = FilenameTemplate(
            name='Task Filename Template',
            target_entity_type='Task',
            path='{{project.code}}/{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/{%- endfor -%}',
            filename='{{task.nice_name}}_{{version.take_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )
        DBSession.add(task_ft)

        structure1 = Structure(name='Commercial Project Structure',
                               templates=[task_ft])
        DBSession.add(structure1)

        status1 = Status(name='Status 1', code='STS1')
        status2 = Status(name='Status 2', code='STS2')
        status3 = Status(name='Status 3', code='STS3')
        DBSession.add_all([status1, status2, status3])

        proj_status_list = \
            StatusList.query.filter_by(target_entity_type='Project').first()

        task_status_list = \
            StatusList.query.filter_by(target_entity_type='Task').first()
        DBSession.add(task_status_list)

        project1 = Project(name='Test Project 1',
                           code='TP1',
                           repositories=[repo1],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project1)

        project2 = Project(name='Test Project 2',
                           code='TP2',
                           repositories=[repo2],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project2)

        task1 = Task(name='Test Task 1',
                     code='TT1',
                     project=project1,
                     status_list=task_status_list)
        DBSession.add(task1)

        task2 = Task(name='Test Task 1',
                     code='TT1',
                     project=project2,
                     status_list=task_status_list)
        DBSession.add(task2)

        DBSession.commit()

        # now create versions
        version1 = Version(task=task1, status_list=version_status_list)
        DBSession.add(version1)
        DBSession.commit()
        version1.update_paths()

        version2 = Version(task=task1)
        DBSession.add(version2)
        DBSession.commit()
        version2.update_paths()

        version3 = Version(task=task2)
        DBSession.add(version3)
        DBSession.commit()
        version3.update_paths()

        version4 = Version(task=task2)
        DBSession.add(version4)
        DBSession.commit()
        version4.update_paths()

        DBSession.commit()
        logger.debug('version1.full_path : %s' % version1.full_path)
        logger.debug('version2.full_path : %s' % version2.full_path)
        logger.debug('version3.full_path : %s' % version2.full_path)
        logger.debug('version4.full_path : %s' % version2.full_path)

        # now try to get the versions with an EnvironmentBase instance
        env = EnvironmentBase()

        expected_value1 = 'TP1/Test_Task_1/Test_Task_1_Main_v001'
        expected_value2 = 'TP2/Test_Task_1/Test_Task_1_Main_v001'

        # version1 native
        trimmed_path = env.trim_repo_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 native
        trimmed_path = env.trim_repo_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)

        # version1 windows
        trimmed_path = env.trim_repo_path(
            'T:/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 windows
        trimmed_path = env.trim_repo_path(
            'S:/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)

        # version1 linux
        trimmed_path = env.trim_repo_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 linux
        trimmed_path = env.trim_repo_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)

        # version1 osx
        trimmed_path = env.trim_repo_path(
            '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 osx
        trimmed_path = env.trim_repo_path(
            '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)