Ejemplo n.º 1
0
    def import_entry(self, data):
        project = Project.get_by(shotgun_id=data["shotgun_id"])

        if project is None:
            project = Project(**data)

            tree_name = current_app.config["DEFAULT_FILE_TREE"]
            project.file_tree = file_tree_service.get_tree_from_file(tree_name)

            project.save()
            current_app.logger.info("Project created: %s" % project)

        else:
            project.update(data)
            current_app.logger.info("Project updated: %s" % project)

        return project
Ejemplo n.º 2
0
    def import_entry(self, data):
        project = Project.get_by(shotgun_id=data["shotgun_id"])

        if project is None:
            project = Project(**data)

            tree_name = current_app.config["DEFAULT_FILE_TREE"]
            try:
                project.file_tree = file_tree_service.get_tree_from_file(
                    tree_name)
            except WrongFileTreeFileException:
                current_app.logger.error(
                    "Can't find default file to set project file tree. Set "
                    "an empty file tree instead.")
                project.file_tree = {}

            project.save()
            current_app.logger.info("Project created: %s" % project)

        else:
            project.update(data)
            current_app.logger.info("Project updated: %s" % project)

        return project
Ejemplo n.º 3
0
class ApiDBTestCase(ApiTestCase):
    def setUp(self):
        """
        Reset database before each test.
        """
        super(ApiDBTestCase, self).setUp()

        from zou.app.utils import dbhelpers
        dbhelpers.drop_all()
        dbhelpers.create_all()
        self.log_in()

    def log_in(self):
        self.generate_fixture_user()
        self.post("auth/login", {
            "email": self.user.email,
            "password": "******"
        }, 200)

    def tearDown(self):
        """
        Delete database after each test.
        """
        from zou.app.utils import dbhelpers
        dbhelpers.drop_all()

    def generate_data(self, cls, number, **kwargs):
        """
        Generate random data for a given data model.
        """
        mixer.init_app(self.flask_app)
        return mixer.cycle(number).blend(cls, id=fields.gen_uuid, **kwargs)

    def generate_fixture_project_status(self):
        self.open_status = ProjectStatus(name="open", color="#FFFFFF")
        self.open_status.save()

    def generate_fixture_project_closed_status(self):
        self.closed_status = ProjectStatus(name="closed", color="#FFFFFF")
        self.closed_status.save()

    def generate_fixture_project(self):
        self.project = Project(name="Cosmos Landromat",
                               project_status_id=self.open_status.id)
        self.project.save()
        self.project.update(
            {"file_tree": file_tree.get_tree_from_file("simple")})

    def generate_fixture_project_closed(self):
        self.project_closed = Project(name="Old Project",
                                      project_status_id=self.closed_status.id)
        self.project_closed.save()

    def generate_fixture_project_standard(self):
        self.project_standard = Project(name="Big Buck Bunny",
                                        project_status_id=self.open_status.id)
        self.project_standard.save()
        self.project_standard.update(
            {"file_tree": file_tree.get_tree_from_file("standard")})

    def generate_fixture_entity(self):
        self.entity = Entity(name="Tree",
                             description="Description Tree",
                             project_id=self.project.id,
                             entity_type_id=self.entity_type.id)
        self.entity.save()

    def generate_fixture_entity_standard(self):
        self.entity_standard = Entity(name="Car",
                                      project_id=self.project_standard.id,
                                      entity_type_id=self.entity_type.id)
        self.entity_standard.save()

    def generate_fixture_sequence(self):
        if hasattr(self, "episode"):
            episode_id = self.episode.id
        else:
            episode_id = None

        self.sequence = Entity(name="S01",
                               project_id=self.project.id,
                               entity_type_id=self.sequence_type.id,
                               parent_id=episode_id)
        self.sequence.save()

    def generate_fixture_sequence_standard(self):
        self.sequence_standard = Entity(name="S01",
                                        project_id=self.project_standard.id,
                                        entity_type_id=self.sequence_type.id)
        self.sequence_standard.save()

    def generate_fixture_episode(self):
        self.episode = Entity(name="E01",
                              project_id=self.project.id,
                              entity_type_id=self.episode_type.id)
        self.episode.save()

    def generate_fixture_shot(self):
        self.shot = Entity(name="P01",
                           description="Description Shot 01",
                           data={
                               "fps": 25,
                               "frame_in": 0,
                               "frame_out": 100
                           },
                           project_id=self.project.id,
                           entity_type_id=self.shot_type.id,
                           parent_id=self.sequence.id)
        self.shot.save()
        self.shot_noseq = Entity(name="P01NOSEQ",
                                 project_id=self.project.id,
                                 entity_type_id=self.shot_type.id)
        self.shot_noseq.save()

    def generate_fixture_shot_standard(self):
        self.shot_standard = Entity(name="P01",
                                    description="Description Shot 01",
                                    data={
                                        "fps": 25,
                                        "frame_in": 0,
                                        "frame_out": 100
                                    },
                                    project_id=self.project_standard.id,
                                    entity_type_id=self.shot_type.id,
                                    parent_id=self.sequence_standard.id)
        self.shot_standard.save()

    def generate_fixture_user(self):
        self.user = Person(first_name="John",
                           last_name="Did",
                           email=u"*****@*****.**",
                           password=auth.encrypt_password("mypassword"))
        self.user.save()

    def generate_fixture_person(self):
        self.person = Person(first_name="John",
                             last_name="Doe",
                             email=u"*****@*****.**",
                             password=auth.encrypt_password("mypassword"))
        self.person.save()

    def generate_fixture_entity_type(self):
        self.entity_type = EntityType(name="Props")
        self.entity_type.save()
        self.shot_type = EntityType(name="Shot")
        self.shot_type.save()
        self.sequence_type = EntityType(name="Sequence")
        self.sequence_type.save()
        self.episode_type = EntityType(name="Episode")
        self.episode_type.save()

    def generate_fixture_department(self):
        self.department = Department(name="Modeling", color="#FFFFFF")
        self.department.save()
        self.department_animation = Department(name="Animation",
                                               color="#FFFFFF")
        self.department_animation.save()

    def generate_fixture_task_type(self):
        self.task_type = TaskType(name="Shaders",
                                  color="#FFFFFF",
                                  department_id=self.department.id)
        self.task_type.save()
        self.task_type_animation = TaskType(
            name="Animation",
            color="#FFFFFF",
            department_id=self.department_animation.id)
        self.task_type_animation.save()

    def generate_fixture_task_status(self):
        self.task_status = TaskStatus(name="Open",
                                      short_name="opn",
                                      color="#FFFFFF")
        self.task_status.save()

    def generate_fixture_task_status_wip(self):
        self.task_status_wip = TaskStatus(name="WIP",
                                          short_name="wip",
                                          color="#FFFFFF")
        self.task_status_wip.save()

    def generate_fixture_task_status_to_review(self):
        self.task_status_to_review = TaskStatus(name="To review",
                                                short_name="pndng",
                                                color="#FFFFFF")
        self.task_status_to_review.save()

    def generate_fixture_assigner(self):
        self.assigner = Person(first_name="Ema", last_name="Peel")
        self.assigner.save()

    def generate_fixture_task(self):
        start_date = fields.get_date_object("2017-02-20")
        due_date = fields.get_date_object("2017-02-28")
        real_start_date = fields.get_date_object("2017-02-22")
        self.task = Task(name="Super modeling",
                         project_id=self.project.id,
                         task_type_id=self.task_type.id,
                         task_status_id=self.task_status.id,
                         entity_id=self.entity.id,
                         assignees=[self.person],
                         assigner_id=self.assigner.id,
                         duration=50,
                         estimation=40,
                         start_date=start_date,
                         due_date=due_date,
                         real_start_date=real_start_date)
        self.task.save()

    def generate_fixture_task_standard(self):
        start_date = fields.get_date_object("2017-02-20")
        due_date = fields.get_date_object("2017-02-28")
        real_start_date = fields.get_date_object("2017-02-22")
        self.task_standard = Task(name="Super modeling",
                                  project_id=self.project_standard.id,
                                  task_type_id=self.task_type.id,
                                  task_status_id=self.task_status.id,
                                  entity_id=self.entity_standard.id,
                                  assignees=[self.person],
                                  assigner_id=self.assigner.id,
                                  duration=50,
                                  estimation=40,
                                  start_date=start_date,
                                  due_date=due_date,
                                  real_start_date=real_start_date)
        self.task_standard.save()

    def generate_fixture_shot_task(self):
        self.shot_task = Task(
            name="Super animation",
            project_id=self.project.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.shot.id,
            assignees=[self.person],
            assigner_id=self.assigner.id,
        )
        self.shot_task.save()

    def generate_fixture_shot_task_standard(self):
        self.shot_task_standard = Task(
            name="Super animation",
            project_id=self.project_standard.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.shot_standard.id,
            assignees=[self.person],
            assigner_id=self.assigner.id)
        self.shot_task_standard.save()

    def generate_fixture_file_status(self):
        self.file_status = FileStatus(name="To review", color="#FFFFFF")
        self.file_status.save()

    def generate_fixture_working_file(self):
        self.working_file = WorkingFile(name="S01_P01_modeling",
                                        comment="",
                                        revision=1,
                                        task_id=self.task.id,
                                        entity_id=self.entity.id,
                                        person_id=self.person.id)
        self.working_file.save()

    def generate_fixture_shot_working_file(self):
        self.working_file = WorkingFile(name="S01_P01_animation",
                                        comment="",
                                        revision=1,
                                        task_id=self.task.id,
                                        entity_id=self.shot.id,
                                        person_id=self.person.id)
        self.working_file.save()

    def generate_fixture_output_file(self):
        self.output_file = OutputFile(comment="",
                                      revision=1,
                                      task_id=self.task.id,
                                      entity_id=self.entity.id,
                                      person_id=self.person.id,
                                      file_status_id=self.file_status.id)
        self.output_file.save()

    def get_fixture_file_path(self, relative_path):
        current_path = os.getcwd()
        file_path_fixture = os.path.join(current_path, "test", "fixtures",
                                         relative_path)
        return file_path_fixture
Ejemplo n.º 4
0
class ApiDBTestCase(ApiTestCase):
    def setUp(self):
        """
        Reset database before each test.
        """
        super(ApiDBTestCase, self).setUp()

        from zou.app.utils import dbhelpers
        dbhelpers.drop_all()
        dbhelpers.create_all()
        self.generate_fixture_user()
        self.log_in_admin()

    def tearDown(self):
        """
        Delete database after each test.
        """
        from zou.app.utils import dbhelpers
        dbhelpers.drop_all()

    def generate_data(self, cls, number, **kwargs):
        """
        Generate random data for a given data model.
        """
        mixer.init_app(self.flask_app)
        return mixer.cycle(number).blend(cls, id=fields.gen_uuid, **kwargs)

    def generate_fixture_project_status(self):
        self.open_status = ProjectStatus(name="open", color="#FFFFFF")
        self.open_status.save()

    def generate_fixture_project_closed_status(self):
        self.closed_status = ProjectStatus(name="closed", color="#FFFFFF")
        self.closed_status.save()

    def generate_fixture_project(self):
        self.project = Project(name="Cosmos Landromat",
                               project_status_id=self.open_status.id)
        self.project.save()
        self.project.update(
            {"file_tree": file_tree_service.get_tree_from_file("simple")})

    def generate_fixture_project_closed(self):
        self.project_closed = Project(name="Old Project",
                                      project_status_id=self.closed_status.id)
        self.project_closed.save()

    def generate_fixture_project_standard(self):
        self.project_standard = Project(name="Big Buck Bunny",
                                        project_status_id=self.open_status.id)
        self.project_standard.save()
        self.project_standard.update(
            {"file_tree": file_tree_service.get_tree_from_file("standard")})

    def generate_fixture_project_no_preview_tree(self):
        self.project_no_preview_tree = Project(
            name="Agent 327", project_status_id=self.open_status.id)
        self.project_no_preview_tree.save()
        self.project_no_preview_tree.update(
            {"file_tree": file_tree_service.get_tree_from_file("no_preview")})

    def generate_fixture_entity(self):
        self.entity = Entity(name="Tree",
                             description="Description Tree",
                             project_id=self.project.id,
                             entity_type_id=self.entity_type.id)
        self.entity.save()

    def generate_fixture_entity_character(self):
        self.entity_character = Entity(
            name="Rabbit",
            description="Main character",
            project_id=self.project.id,
            entity_type_id=self.entity_type_character.id)
        self.entity_character.save()

    def generate_fixture_entity_camera(self):
        self.entity_camera = Entity(name="Main camera",
                                    description="Description Camera",
                                    project_id=self.project.id,
                                    entity_type_id=self.entity_type_camera.id)
        self.entity_camera.save()

    def generate_fixture_entity_standard(self):
        self.entity_standard = Entity(name="Car",
                                      project_id=self.project_standard.id,
                                      entity_type_id=self.entity_type.id)
        self.entity_standard.save()

    def generate_fixture_sequence(self, name="S01"):
        if hasattr(self, "episode"):
            episode_id = self.episode.id
        else:
            episode_id = None

        self.sequence = Entity(name=name,
                               project_id=self.project.id,
                               entity_type_id=self.sequence_type.id,
                               parent_id=episode_id)
        self.sequence.save()

    def generate_fixture_sequence_standard(self):
        self.sequence_standard = Entity(name="S01",
                                        project_id=self.project_standard.id,
                                        entity_type_id=self.sequence_type.id)
        self.sequence_standard.save()

    def generate_fixture_episode(self, name="E01"):
        self.episode = Entity(name=name,
                              project_id=self.project.id,
                              entity_type_id=self.episode_type.id)
        self.episode.save()

    def generate_fixture_shot(self, name="P01"):
        self.shot = Entity(name=name,
                           description="Description Shot 01",
                           data={
                               "fps": 25,
                               "frame_in": 0,
                               "frame_out": 100
                           },
                           project_id=self.project.id,
                           entity_type_id=self.shot_type.id,
                           parent_id=self.sequence.id)
        self.shot.save()
        self.shot_noseq = Entity(name="P01NOSEQ",
                                 project_id=self.project.id,
                                 entity_type_id=self.shot_type.id)
        self.shot_noseq.save()

    def generate_fixture_scene(self,
                               name="SC01",
                               project_id=None,
                               sequence_id=None):
        if project_id is None:
            project_id = self.project.id

        if sequence_id is None:
            sequence_id = self.sequence.id

        self.scene = Entity(name=name,
                            description="Description Scene 01",
                            data={},
                            project_id=project_id,
                            entity_type_id=self.scene_type.id,
                            parent_id=self.sequence.id)
        self.scene.save()

    def generate_fixture_shot_standard(self):
        self.shot_standard = Entity(name="P01",
                                    description="Description Shot 01",
                                    data={
                                        "fps": 25,
                                        "frame_in": 0,
                                        "frame_out": 100
                                    },
                                    project_id=self.project_standard.id,
                                    entity_type_id=self.shot_type.id,
                                    parent_id=self.sequence_standard.id)
        self.shot_standard.save()

    def generate_fixture_shot_asset_instance(self,
                                             asset=None,
                                             shot=None,
                                             number=1):
        if asset is None:
            asset = self.entity
        if shot is None:
            shot = self.shot
        self.asset_instance = AssetInstance.create(
            asset_id=asset.id,
            entity_id=shot.id,
            entity_type_id=self.shot_type.id,
            number=number,
            description="Asset instance description")

    def generate_fixture_scene_asset_instance(self,
                                              asset=None,
                                              scene=None,
                                              number=1):
        if asset is None:
            asset = self.entity
        if scene is None:
            scene = self.scene
        self.asset_instance = AssetInstance.create(
            asset_id=asset.id,
            entity_id=scene.id,
            entity_type_id=self.scene_type.id,
            number=number,
            description="Asset instance description")

    def generate_fixture_user(self):
        self.user = Person.create(first_name="John",
                                  last_name="Did",
                                  role="admin",
                                  email=u"*****@*****.**",
                                  password=auth.encrypt_password("mypassword"))
        return self.user

    def generate_fixture_user_manager(self):
        self.user_manager = Person.create(
            first_name="John",
            last_name="Did2",
            role="manager",
            email=u"*****@*****.**",
            password=auth.encrypt_password("mypassword"))
        return self.user_manager

    def generate_fixture_user_cg_artist(self):
        self.user_cg_artist = Person.create(
            first_name="John",
            last_name="Did3",
            email=u"*****@*****.**",
            role="user",
            password=auth.encrypt_password("mypassword"))
        return self.user_cg_artist

    def generate_fixture_person(self):
        self.person = Person(first_name="John",
                             last_name="Doe",
                             desktop_login="******",
                             email=u"*****@*****.**",
                             password=auth.encrypt_password("mypassword"))
        self.person.save()

    def generate_fixture_entity_type(self):
        self.entity_type = EntityType.create(name="Props")
        self.shot_type = EntityType.create(name="Shot")
        self.sequence_type = EntityType.create(name="Sequence")
        self.episode_type = EntityType.create(name="Episode")
        self.scene_type = EntityType.create(name="Scene")

    def generate_fixture_asset_types(self):
        self.entity_type_character = EntityType.create(name="Character")
        self.entity_type_environment = EntityType.create(name="Environment")
        self.entity_type_camera = EntityType.create(name="Camera")

    def generate_fixture_department(self):
        self.department = Department(name="Modeling", color="#FFFFFF")
        self.department.save()
        self.department_animation = Department(name="Animation",
                                               color="#FFFFFF")
        self.department_animation.save()

    def generate_fixture_task_type(self):
        self.task_type = TaskType(name="Shaders",
                                  color="#FFFFFF",
                                  department_id=self.department.id)
        self.task_type.save()
        self.task_type_animation = TaskType(
            name="Animation",
            color="#FFFFFF",
            department_id=self.department_animation.id)
        self.task_type_animation.save()

    def generate_fixture_task_status(self):
        self.task_status = TaskStatus(name="Open",
                                      short_name="opn",
                                      color="#FFFFFF")
        self.task_status.save()

    def generate_fixture_task_status_wip(self):
        self.task_status_wip = TaskStatus(name="WIP",
                                          short_name="wip",
                                          color="#FFFFFF")
        self.task_status_wip.save()

    def generate_fixture_task_status_to_review(self):
        self.task_status_to_review = TaskStatus(name="To review",
                                                short_name="pndng",
                                                color="#FFFFFF")
        self.task_status_to_review.save()

    def generate_fixture_assigner(self):
        self.assigner = Person(first_name="Ema", last_name="Peel")
        self.assigner.save()

    def generate_fixture_task(self, name="Master", entity_id=None):
        if entity_id is None:
            entity_id = self.entity.id

        start_date = fields.get_date_object("2017-02-20")
        due_date = fields.get_date_object("2017-02-28")
        real_start_date = fields.get_date_object("2017-02-22")
        self.task = Task(name=name,
                         project_id=self.project.id,
                         task_type_id=self.task_type.id,
                         task_status_id=self.task_status.id,
                         entity_id=entity_id,
                         assignees=[self.person],
                         assigner_id=self.assigner.id,
                         duration=50,
                         estimation=40,
                         start_date=start_date,
                         due_date=due_date,
                         real_start_date=real_start_date)
        self.task.save()

    def generate_fixture_task_standard(self):
        start_date = fields.get_date_object("2017-02-20")
        due_date = fields.get_date_object("2017-02-28")
        real_start_date = fields.get_date_object("2017-02-22")
        self.task_standard = Task(name="Super modeling",
                                  project_id=self.project_standard.id,
                                  task_type_id=self.task_type.id,
                                  task_status_id=self.task_status.id,
                                  entity_id=self.entity_standard.id,
                                  assignees=[self.person],
                                  assigner_id=self.assigner.id,
                                  duration=50,
                                  estimation=40,
                                  start_date=start_date,
                                  due_date=due_date,
                                  real_start_date=real_start_date)
        self.task_standard.save()

    def generate_fixture_shot_task(self, name="Master"):
        self.shot_task = Task(
            name=name,
            project_id=self.project.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.shot.id,
            assignees=[self.person],
            assigner_id=self.assigner.id,
        )
        return self.shot_task.save()

    def generate_fixture_scene_task(self, name="Master"):
        self.scene_task = Task.create(
            name=name,
            project_id=self.project.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.scene.id,
            assignees=[self.person],
            assigner_id=self.assigner.id,
        )
        return self.scene_task

    def generate_fixture_sequence_task(self, name="Master"):
        self.sequence_task = Task(
            name=name,
            project_id=self.project.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.sequence.id,
            assignees=[self.person],
            assigner_id=self.assigner.id,
        )
        self.sequence_task.save()

    def generate_fixture_shot_task_standard(self):
        self.shot_task_standard = Task(
            name="Super animation",
            project_id=self.project_standard.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.shot_standard.id,
            assignees=[self.person],
            assigner_id=self.assigner.id)
        self.shot_task_standard.save()

    def generate_fixture_file_status(self):
        self.file_status = FileStatus(name="To review", color="#FFFFFF")
        self.file_status.save()

    def generate_fixture_working_file(self, name="main", revision=1):
        self.working_file = WorkingFile(name=name,
                                        comment="",
                                        revision=revision,
                                        task_id=self.task.id,
                                        entity_id=self.entity.id,
                                        person_id=self.person.id,
                                        software_id=self.software.id)
        self.working_file.save()
        return self.working_file

    def generate_fixture_shot_working_file(self):
        self.working_file = WorkingFile(name="main",
                                        comment="",
                                        revision=1,
                                        task_id=self.shot_task.id,
                                        entity_id=self.shot.id,
                                        person_id=self.person.id,
                                        software_id=self.software.id)
        self.working_file.save()

    def generate_fixture_output_file(self,
                                     output_type=None,
                                     revision=1,
                                     name="main",
                                     task=None):
        if output_type is None:
            output_type = self.output_type

        if task is None:
            task_type_id = self.task_type.id
            entity_id = self.entity.id
        else:
            task_type_id = task.task_type_id
            entity_id = task.entity_id

        self.output_file = OutputFile.create(
            comment="",
            revision=revision,
            task_type_id=task_type_id,
            entity_id=entity_id,
            person_id=self.person.id,
            file_status_id=self.file_status.id,
            output_type_id=output_type.id,
            name=name)
        return self.output_file

    def generate_fixture_output_type(self, name="Geometry", short_name="Geo"):
        self.output_type = OutputType.create(name=name, short_name=short_name)
        return self.output_type

    def generate_fixture_software(self):
        self.software = Software.create(name="Blender",
                                        short_name="bdr",
                                        file_extension=".blender")
        self.software_max = Software.create(name="3dsMax",
                                            short_name="max",
                                            file_extension=".max")

    def generate_fixture_preview_file(self, revision=1):
        self.preview_file = PreviewFile.create(name="main",
                                               revision=revision,
                                               description="test description",
                                               source="pytest",
                                               task_id=self.task.id,
                                               person_id=self.person.id)
        return self.preview_file

    def get_fixture_file_path(self, relative_path):
        current_path = os.getcwd()
        file_path_fixture = os.path.join(current_path, "tests", "fixtures",
                                         relative_path)
        return file_path_fixture

    def generate_assigned_task(self):
        self.generate_fixture_entity()
        self.generate_fixture_department()
        self.generate_fixture_task_type()
        self.generate_fixture_task_status()
        self.generate_fixture_person()
        self.generate_fixture_assigner()
        self.generate_fixture_task()

    def generate_shot_suite(self):
        self.generate_fixture_entity_type()
        self.generate_fixture_project_status()
        self.generate_fixture_project()
        self.generate_fixture_episode()
        self.generate_fixture_sequence()
        self.generate_fixture_shot()
        self.generate_fixture_scene()