Пример #1
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)
    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
        )
Пример #3
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
        )
Пример #4
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()
Пример #5
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),
        )
Пример #6
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()
    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))
Пример #8
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
        )
Пример #9
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()
Пример #10
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()
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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
Пример #15
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)
Пример #16
0
def assign_reference(request):
    """assigns the link to the given entity as a new reference
    """
    link_ids = get_multi_integer(request, 'link_ids[]')
    removed_link_ids = get_multi_integer(request, 'removed_link_ids[]')
    entity_id = request.params.get('entity_id', -1)

    entity = Entity.query.filter_by(id=entity_id).first()
    links = Link.query.filter(Link.id.in_(link_ids)).all()
    removed_links = Link.query.filter(Link.id.in_(removed_link_ids)).all()

    # Tags
    tags = get_tags(request)

    logged_in_user = get_logged_in_user(request)

    logger.debug('link_ids      : %s' % link_ids)
    logger.debug('links         : %s' % links)
    logger.debug('entity_id     : %s' % entity_id)
    logger.debug('entity        : %s' % entity)
    logger.debug('tags          : %s' % tags)
    logger.debug('removed_links : %s' % removed_links)

    # remove all the removed links
    for removed_link in removed_links:
        # no need to search for any linked tasks here
        DBSession.delete(removed_link)

    if entity and links:
        entity.references.extend(links)

        # assign all the tags to the links
        for link in links:
            link.tags.extend(tags)
            # generate thumbnail
            thumbnail = generate_thumbnail(link)
            link.thumbnail = thumbnail
            thumbnail.created_by = logged_in_user
            DBSession.add(thumbnail)

        DBSession.add(entity)
        DBSession.add_all(links)

    # return new links as json data
    # in response text
    return [
        {
            'id': link.id,
            'full_path': link.full_path,
            'original_filename': link.original_filename,
            'thumbnail': link.thumbnail.full_path
            if link.thumbnail else link.full_path,
            'tags': [tag.name for tag in link.tags]
        } for link in links
    ]
Пример #17
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()
Пример #18
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))
Пример #19
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()
Пример #20
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()
Пример #21
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()
Пример #22
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
        )
Пример #23
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)
        )
    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
        )
Пример #25
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()
Пример #26
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)
    def test_tasks_are_correctly_scheduled(self):
        """testing if the tasks are correctly scheduled
        """
        tjp_sched = TaskJugglerScheduler()
        test_studio = Studio(name='Test Studio',
                             now=datetime.datetime(2013, 4, 16, 0, 0))
        test_studio.daily_working_hours = 9
        DBSession.add(test_studio)

        tjp_sched.studio = test_studio
        tjp_sched.schedule()

        # 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_user5, self.test_user4],
            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_user1, self.test_user2],
            self.test_task2.computed_resources
        )
Пример #28
0
def update_asset(request):
    """updates an Asset
    """
    logger.debug('***update_asset method starts ***')
    logged_in_user = get_logged_in_user(request)

    # get params
    asset_id = request.matchdict.get('id', -1)
    asset = Asset.query.filter_by(id=asset_id).first()

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

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

    if asset and name and code and type_name and status:
        # get the type
        type_ = Type.query\
            .filter_by(target_entity_type='Asset')\
            .filter_by(name=type_name)\
            .first()

        if type_ is None:
            # create a new Type
            type_ = Type(
                name=type_name,
                code=type_name,
                target_entity_type='Asset'
            )

        # update the asset
        logger.debug('code      : %s' % code)
        asset.name = name
        asset.code = code
        asset.description = description
        asset.type = type_
        asset.status = status
        asset.updated_by = logged_in_user
        asset.date_updated = datetime.datetime.now()

        DBSession.add(asset)

    return HTTPOk()
Пример #29
0
def update_time_log(request):
    """runs when updating a time_log
    """
    logger.debug('inside update_time_log')
    # time_log_id = int(request.params.get('time_log_id'))
    time_log_id = request.matchdict.get('id', -1)
    time_log = TimeLog.query.filter_by(id=time_log_id).first()

    #**************************************************************************
    # collect data
    resource_id = int(request.params.get('resource_id', None))
    resource = User.query.filter(User.id == resource_id).first()

    start_date = get_date(request, 'start')
    end_date = get_date(request, 'end')

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

    logger.debug('time_log_id : %s' % time_log_id)
    logger.debug('resource_id : %s' % resource_id)
    logger.debug('start         : %s' % start_date)
    logger.debug('end           : %s' % end_date)

    if time_log and resource and start_date and end_date:
        # we are ready to create the time log
        # TimeLog should handle the extension of the effort

        try:
            time_log.start = start_date
            time_log.end = end_date
            time_log.description = description
            time_log.resource = resource
        except OverBookedError as e:
            logger.debug('e.message: %s' % str(e))
            response = Response(str(e), 500)
            transaction.abort()
            return response
        else:
            DBSession.add(time_log)
            request.session.flash(
                'success:Time log for <strong>%s</strong> is updated..'
                % time_log.task.name
            )
            logger.debug('successfully updated time log!')

    return Response('TimeLog has been updated successfully')
Пример #30
0
def create_entity_note(request):

    logger.debug('create_entity_note is running')

    entity_id = request.matchdict.get('id', -1)
    entity = Entity.query.filter(Entity.id == entity_id).first()

    content = request.params.get('message', '')

    utc_now = local_to_utc(datetime.datetime.now())

    logged_in_user = get_logged_in_user(request)

    if not entity:
        transaction.abort()
        return Response('There is no entity with id: %s' % entity_id, 500)


    logger.debug('content %s' % content)

    if content != '':

        note_type = Type.query.filter_by(name='Simple Text').first()
        if note_type is None:
                 # create a new Type
                note_type = Type(
                    name='Simple Text',
                    code='Simple_Text',
                    target_entity_type='Note',
                    html_class='grey'

                )

        note = Note(
                    content=content,
                    created_by=logged_in_user,
                    date_created=utc_now,
                    date_updated=utc_now,
                    type = note_type
                )

        DBSession.add(note)

        entity.notes.append(note)

    return Response('Task note is created')
Пример #31
0
def update_shot(request):
    """runs when adding a new shot
    """
    logged_in_user = get_logged_in_user(request)

    shot_id = request.params.get("shot_id")
    shot = Shot.query.filter_by(id=shot_id).first()

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

    cut_in = int(request.params.get("cut_in", 1))
    cut_out = int(request.params.get("cut_out", 1))

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

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

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

        # update the shot

        shot.name = name
        shot.code = code
        shot.description = description
        shot.sequences = [sequence]
        shot.status = status
        shot.updated_by = logged_in_user
        shot.date_updated = datetime.datetime.now()
        shot.cut_in = cut_in
        shot.cut_out = cut_out

        DBSession.add(shot)

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

    return HTTPOk()
Пример #32
0
    def handle_starttag(self, tag, attrs):
        # print tag, attrs
        attrs_dict = {}
        if tag == 'img':
            # convert attributes to a dict
            for attr in attrs:
                attrs_dict[attr[0]] = attr[1]
            src = attrs_dict['src']

            # check if it contains data
            if not src.startswith('data'):
                return

            # get the file type and use it as extension
            image_data = ImageData(src)
            # generate a path for this file
            file_full_path, link_full_path = \
                generate_local_file_path(image_data.extension)
            original_name = os.path.basename(link_full_path)

            # create folders
            try:
                os.makedirs(os.path.dirname(file_full_path))
            except OSError:
                # path exists
                pass

            with open(file_full_path, 'wb') as f:
                f.write(
                    base64.decodestring(image_data.base64_data)
                )

            # create Link instances
            # create a Link instance and return it
            new_link = Link(
                full_path=link_full_path,
                original_filename=original_name,
            )
            DBSession.add(new_link)
            self.links.append(new_link)

            # save data to be replaced in the raw content
            self.raw_img_to_url.append(
                (src, link_full_path)
            )
Пример #33
0
def update_version(request):
    """runs when updating a version
    """
    logged_in_user = get_logged_in_user(request)

    version_id = request.params.get('version_id')
    version = TimeLog.query.filter_by(id=version_id).first()

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

    if version and name:

        version.name = name
        version.updated_by = logged_in_user
    else:
        DBSession.add(version)

    return HTTPOk()
Пример #34
0
def remove_entity_from_entity(request):
    """Removes entitiy from entity for example removes selected project from user.projects
    etc.
    """
    logger.debug('remove_entity_from_entity is running')

    came_from = request.params.get('came_from', '/')

    entity_id = request.matchdict.get('id', -1)
    entity = Entity.query.filter_by(id=entity_id).first()

    selected_entity_id = request.matchdict.get('entity_id', -1)
    selected_entity = Entity.query.filter_by(id=selected_entity_id).first()

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

    if entity and selected_entity:

        attr_name = selected_entity.plural_class_name.lower()
        eval('entity.%(attr_name)s.remove(selected_entity)' % {'attr_name': attr_name})
        DBSession.add(entity)

        logger.debug('entity is updated successfully')

        request.session.flash(
            'success:%s <strong>%s</strong> is successfully removed from %s '
            '\'s %s' % (
                selected_entity.entity_type,
                selected_entity.name, entity.name, attr_name
            )
        )
        logger.debug('***remove_entity_from_entity method ends ***')
    else:
        logger.debug('not all parameters are in request.params')
        request.session.flash(
            'failed:not all parameters are in request.params'
        )
        HTTPServerError()

    return Response(
        'success:%s <strong>%s</strong> is successfully removed from %s \'s %s'
        % (selected_entity.entity_type, selected_entity.name, entity.name,
           attr_name)
    )
Пример #35
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)
Пример #36
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()
Пример #37
0
def get_tags(request, parameter='tags[]'):
    """Extracts Tags from the given request

    :param request: Request object
    :return: A list of stalker.models.tag.Tag instances
    """
    # Tags
    tags = []
    tag_names = request.POST.getall(parameter)
    for tag_name in tag_names:
        logger.debug('tag_name : %s' % tag_name)
        if tag_name == '':
            continue
        tag = Tag.query.filter(Tag.name == tag_name).first()
        if not tag:
            logger.debug('new tag is created %s' % tag_name)
            tag = Tag(name=tag_name)
            DBSession.add(tag)
        tags.append(tag)
    return tags
Пример #38
0
def query_type(entity_type, type_name):
    """returns a Type instance either it creates a new one or gets it from DB
    """
    if not type_name:
        return None

    type_query = Type.query.filter_by(target_entity_type=entity_type)
    type_ = type_query.filter_by(name=type_name).first()
    if type_name and type_ is None:
        # create a new Type
        logger.debug('creating new %s type: %s' % (
            entity_type.lower(), type_name)
        )
        type_ = Type(
            name=type_name,
            code=type_name,
            target_entity_type=entity_type
        )
        DBSession.add(type_)

    return type_
Пример #39
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()
Пример #40
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()
Пример #41
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)
Пример #42
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)
Пример #43
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()