Esempio n. 1
0
 def test_entity_with_step(self):
     """
     Tests string representation of shot context with a single step set
     """
     result = context.from_entity(self.tk, self.shot["type"],
                                  self.shot["id"])
     self.assertEquals(str(result), "step_name, Shot shot_name")
Esempio n. 2
0
 def test_task(self):
     """
     Tests string representation of task context
     """
     result = context.from_entity(self.tk, self.task["type"],
                                  self.task["id"])
     self.assertEquals(str(result), "task_content, Shot shot_name")
Esempio n. 3
0
 def test_entity(self):
     """
     Tests string representation of shot context
     """
     result = context.from_entity(self.tk, self.shot_alt["type"],
                                  self.shot_alt["id"])
     self.assertEquals(str(result), "Shot shot_name_alt")
Esempio n. 4
0
    def test_shot(self, get_current_user):

        get_current_user.return_value = self.current_user
        
        # Add data to mocked shotgun
        self.task = {"id": 1,
                     "type": "Task",
                     "content": "task_content",
                     "project": self.project,
                     "entity": self.shot,
                     "step": self.step}
        
        self.add_to_sg_mock_db(self.task)
        
        
        prev_ctx = context.from_entity(self.tk, self.task["type"], self.task["id"])


        shot_path_abs = os.path.join(self.project_root, self.shot_path)
        result = self.tk.context_from_path(shot_path_abs, prev_ctx)

        # check context's attributes
        self.assertEquals(self.shot["id"], result.entity["id"])
        self.assertEquals(self.shot["type"], result.entity["type"])
        self.assertEquals(self.project["id"], result.project["id"])
        self.assertEquals(self.project["type"], result.project["type"])
        self.assertEquals("Step", result.step["type"])
        self.assertEquals(self.step["id"], result.step["id"])
        self.assertEquals("Task", result.task["type"])
        self.assertEquals(self.task["id"], result.task["id"])
        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])
Esempio n. 5
0
    def test_shot(self, get_current_user):

        get_current_user.return_value = self.current_user
        
        # Add data to mocked shotgun
        self.task = {"id": 1,
                     "type": "Task",
                     "content": "task_content",
                     "project": self.project,
                     "entity": self.shot,
                     "step": self.step}
        
        self.add_to_sg_mock_db(self.task)
        
        
        prev_ctx = context.from_entity(self.tk, self.task["type"], self.task["id"])


        shot_path_abs = os.path.join(self.project_root, self.shot_path)
        result = self.tk.context_from_path(shot_path_abs, prev_ctx)

        # check context's attributes
        self.assertEquals(self.shot["id"], result.entity["id"])
        self.assertEquals(self.shot["type"], result.entity["type"])
        self.assertEquals(self.project["id"], result.project["id"])
        self.assertEquals(self.project["type"], result.project["type"])
        self.assertEquals("Step", result.step["type"])
        self.assertEquals(self.step["id"], result.step["id"])
        self.assertEquals("Task", result.task["type"])
        self.assertEquals(self.task["id"], result.task["id"])
        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])
Esempio n. 6
0
    def test_from_linked_entity_types(self, get_current_user):
        get_current_user.return_value = self.current_user

        # PublishedFile and Version entities are special cased in the context
        # factories. We need to make sure they create a context object that is
        # built from what those entities are linked to, but with the original
        # entity kept as the source_entity of the context.
        result = context.from_entity(self.tk, self.publishedfile["type"], self.publishedfile["id"])
        self.check_entity(self.project, result.project, check_name=False)
        self.check_entity(self.shot, result.entity, check_name=False)
        self.check_entity(self.task, result.task, check_name=False)
        self.check_entity(
            result.source_entity,
            dict(
                type=self.publishedfile["type"],
                id=self.publishedfile["id"],
            ),
            check_name=False,
        )

        result = context.from_entity_dictionary(self.tk, self.publishedfile)
        self.check_entity(self.project, result.project, check_name=False)
        self.check_entity(self.shot, result.entity, check_name=False)
        self.check_entity(self.task, result.task, check_name=False)
        self.check_entity(
            result.source_entity,
            dict(
                type=self.publishedfile["type"],
                id=self.publishedfile["id"],
            ),
            check_name=False,
        )
Esempio n. 7
0
 def test_project(self):
     """
     Tests string representation of project context
     """
     result = context.from_entity(self.tk, self.project["type"],
                                  self.project["id"])
     self.assertEquals(str(result), "Project project_name")
Esempio n. 8
0
    def test_from_linked_entity_types(self, get_current_user):
        get_current_user.return_value = self.current_user

        # PublishedFile and Version entities are special cased in the context
        # factories. We need to make sure they create a context object that is
        # built from what those entities are linked to, but with the original
        # entity kept as the source_entity of the context.
        result = context.from_entity(self.tk, self.publishedfile["type"],
                                     self.publishedfile["id"])
        self.check_entity(self.project, result.project, check_name=False)
        self.check_entity(self.shot, result.entity, check_name=False)
        self.check_entity(self.task, result.task, check_name=False)
        self.check_entity(
            result.source_entity,
            dict(
                type=self.publishedfile["type"],
                id=self.publishedfile["id"],
            ),
            check_name=False,
        )

        result = context.from_entity_dictionary(self.tk, self.publishedfile)
        self.check_entity(self.project, result.project, check_name=False)
        self.check_entity(self.shot, result.entity, check_name=False)
        self.check_entity(self.task, result.task, check_name=False)
        self.check_entity(
            result.source_entity,
            dict(
                type=self.publishedfile["type"],
                id=self.publishedfile["id"],
            ),
            check_name=False,
        )
Esempio n. 9
0
 def test_bad_entities(self):
     """
     Test exception are raised if bad entities are used.
     """
     with self.assertRaisesRegexp(TankError, "Cannot create a context from an entity type 'None'"):
         context.from_entity(self.tk, None, 7777)
     with self.assertRaisesRegexp(TankError, "Cannot create a context from an entity id set to 'None'"):
         context.from_entity(self.tk, "Task", None)
     with self.assertRaisesRegexp(TankError, "Unable to locate Task with id -1 in Shotgun"):
         context.from_entity(self.tk, "Task", -1)
     # PublishedFiles go through some dedicated code.
     with self.assertRaisesRegexp(TankError, "Entity PublishedFile with id -1 not found in Shotgun!"):
         context.from_entity(self.tk, "PublishedFile", -1)
Esempio n. 10
0
 def test_task(self):
     """
     Case that all data is found from shotgun query
     Note that additional field is specified in a
     context_additional_entities hook.
     """
     # add additional field value to task
     add_value = {"name":"additional", "id": 3, "type": "add_type"}
     self.task["additional_field"] = add_value
     
     result = context.from_entity(self.tk, self.task["type"], self.task["id"])
     self.assertEquals(result.shotgun_url, "http://unit_test_mock_sg/detail/Task/1" )
Esempio n. 11
0
    def get_task_context(self):

        # Add data to mocked shotgun
        self.task = {"id": 1,
                     "type": "Task",
                     "content": "task_content",
                     "project": self.project,
                     "entity": self.shot,
                     "step": self.step}
        self.add_to_sg_mock_db(self.task)

        return context.from_entity(self.tk, self.task["type"], self.task["id"])
Esempio n. 12
0
 def test_task(self):
     """
     Case that all data is found from shotgun query
     Note that additional field is specified in a
     context_additional_entities hook.
     """
     # add additional field value to task
     add_value = {"name":"additional", "id": 3, "type": "add_type"}
     self.task["additional_field"] = add_value
     
     result = context.from_entity(self.tk, self.task["type"], self.task["id"])
     self.assertEquals(result.shotgun_url, "http://unit_test_mock_sg/detail/Task/1" )
Esempio n. 13
0
    def get_task_context(self):

        # Add data to mocked shotgun
        self.task = {
            "id": 1,
            "type": "Task",
            "content": "task_content",
            "project": self.project,
            "entity": self.shot,
            "step": self.step
        }
        self.add_to_sg_mock_db(self.task)

        return context.from_entity(self.tk, self.task["type"], self.task["id"])
Esempio n. 14
0
    def test_task(self):
        """
        Case that all data is found from shotgun query
        Note that additional field is specified in a
        context_additional_entities hook.
        """
        # add additional field value to task
        add_value = {"name":"additional", "id": 3, "type": "add_type"}
        self.task["additional_field"] = add_value
        
        # reset call count on mocked shotgun.find_one method so we can check it later
        self.sg_mock.find_one.reset_mock()

        result = context.from_entity(self.tk, self.task["type"], self.task["id"])
        self.assertEquals(result.shotgun_url, "http://unit_test_mock_sg/detail/Task/1" )
Esempio n. 15
0
    def test_entity_from_cache(self, get_current_user):
        
        get_current_user.return_value = self.current_user
        
        result =  context.from_entity(self.tk, self.shot["type"], self.shot["id"])

        self.check_entity(self.project, result.project)
        self.assertEquals(3, len(result.project))

        self.check_entity(self.shot, result.entity)
        self.assertEquals(3, len(result.entity))
                
        self.check_entity(self.current_user, result.user)

        self.assertEquals(None, result.task)
        self.assertEquals(None, result.step)
Esempio n. 16
0
    def test_step_higher_entity(self, get_current_user):
        """
        Case that step appears in path above entity.
        """
        
        get_current_user.return_value = self.current_user
        
        # Add shot below step
        step_path = os.path.join(self.seq_path, "step_short_name")
        shot_path = os.path.join(step_path, "shot_code")
        self.add_production_path(step_path, self.step)
        self.add_production_path(shot_path, self.shot)

        result =  context.from_entity(self.tk, self.shot["type"], self.shot["id"])
        self.check_entity(self.step, result.step)
        self.check_entity(self.shot, result.entity)
        self.check_entity(self.current_user, result.user)
Esempio n. 17
0
    def test_entity_from_cache(self, get_current_user):

        get_current_user.return_value = self.current_user

        result = context.from_entity(self.tk, self.shot["type"],
                                     self.shot["id"])

        self.check_entity(self.project, result.project)
        self.assertEquals(3, len(result.project))

        self.check_entity(self.shot, result.entity)
        self.assertEquals(3, len(result.entity))

        self.check_entity(self.current_user, result.user)

        self.assertEquals(None, result.task)
        self.assertEquals(None, result.step)
Esempio n. 18
0
    def test_task(self):
        """
        Case that all data is found from shotgun query
        Note that additional field is specified in a
        context_additional_entities hook.
        """
        # add additional field value to task
        add_value = {"name": "additional", "id": 3, "type": "add_type"}
        self.task["additional_field"] = add_value

        # reset call count on mocked shotgun.find_one method so we can check it later
        self.sg_mock.find_one.reset_mock()

        result = context.from_entity(self.tk, self.task["type"],
                                     self.task["id"])
        self.assertEquals(result.shotgun_url,
                          "http://unit_test_mock_sg/detail/Task/1")
Esempio n. 19
0
    def test_step_higher_entity(self, get_current_user):
        """
        Case that step appears in path above entity.
        """
        
        get_current_user.return_value = self.current_user
        
        # Add shot below step
        step_path = os.path.join(self.seq_path, "step_short_name")
        shot_path = os.path.join(step_path, "shot_code")
        self.add_production_path(step_path, self.step)
        self.add_production_path(shot_path, self.shot)

        result =  context.from_entity(self.tk, self.shot["type"], self.shot["id"])
        self.check_entity(self.step, result.step)
        self.check_entity(self.shot, result.entity)
        self.check_entity(self.current_user, result.user)
Esempio n. 20
0
    def test_data_missing_non_task(self, get_current_user):
        """
        Case that entity does not exist on local cache or in shotgun
        """
        get_current_user.return_value = self.current_user
        
        # Use entity we have not setup in path cache not in mocked sg
        shot = {"type": "Shot", "id": 13, "name": "never_seen_me_before"}
        result = context.from_entity(self.tk, shot["type"], shot["id"])

        self.assertEquals(shot["id"], result.entity["id"])
        self.assertEquals(shot["type"], result.entity["type"])
        self.check_entity(self.project, result.project)
        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])
        # Everything else should be none
        self.assertIsNone(result.step)
        self.assertIsNone(result.task)
Esempio n. 21
0
    def test_data_missing_non_task(self, get_current_user):
        """
        Case that entity does not exist on local cache or in shotgun
        """
        get_current_user.return_value = self.current_user
        
        # Use entity we have not setup in path cache not in mocked sg
        shot = {"type": "Shot", "id": 13, "name": "never_seen_me_before"}
        result = context.from_entity(self.tk, shot["type"], shot["id"])

        self.assertEquals(shot["id"], result.entity["id"])
        self.assertEquals(shot["type"], result.entity["type"])
        self.check_entity(self.project, result.project)
        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])
        # Everything else should be none
        self.assertIsNone(result.step)
        self.assertIsNone(result.task)
Esempio n. 22
0
 def test_bad_entities(self):
     """
     Test exception are raised if bad entities are used.
     """
     with self.assertRaisesRegexp(
             TankError,
             "Cannot create a context from an entity type 'None'"):
         context.from_entity(self.tk, None, 7777)
     with self.assertRaisesRegexp(
             TankError,
             "Cannot create a context from an entity id set to 'None'"):
         context.from_entity(self.tk, "Task", None)
     with self.assertRaisesRegexp(
             TankError, "Unable to locate Task with id -1 in Shotgun"):
         context.from_entity(self.tk, "Task", -1)
     # PublishedFiles go through some dedicated code.
     with self.assertRaisesRegexp(
             TankError,
             "Entity PublishedFile with id -1 not found in Shotgun!"):
         context.from_entity(self.tk, "PublishedFile", -1)
Esempio n. 23
0
    def test_task_from_sg(self, get_current_user):
        """
        Case that all data is found from shotgun query
        Note that additional field is specified in a
        context_additional_entities hook.
        """
        self.setup_fixtures()
        get_current_user.return_value = self.current_user

        # add additional field value to task
        add_value = {"name": "additional", "id": 3, "type": "add_type"}
        self.task["additional_field"] = add_value

        # store the find call count
        num_finds_before = self.tk.shotgun.finds

        result = context.from_entity(self.tk, self.task["type"],
                                     self.task["id"])
        self.check_entity(self.project, result.project)
        self.assertEquals(3, len(result.project))

        self.check_entity(self.shot, result.entity)
        self.assertEquals(3, len(result.entity))

        self.check_entity(self.step, result.step)
        self.assertEquals(3, len(result.step))

        self.check_entity(self.current_user, result.user)

        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])

        self.assertEquals(self.task["type"], result.task["type"])
        self.assertEquals(self.task["id"], result.task["id"])
        self.assertEquals(self.task["content"], result.task["name"])
        self.assertEquals(3, len(result.task))

        add_result = result.additional_entities[0]
        self.check_entity(add_value, add_result)

        # Check that the shotgun method find_one was used
        num_finds_after = self.tk.shotgun.finds
        self.assertTrue((num_finds_after - num_finds_before) == 1)
Esempio n. 24
0
    def test_task_from_sg(self, get_current_user):
        """
        Case that all data is found from shotgun query
        Note that additional field is specified in a
        context_additional_entities hook.
        """
        self.setup_fixtures()
        get_current_user.return_value = self.current_user
        
        # add additional field value to task
        add_value = {"name":"additional", "id": 3, "type": "add_type"}
        self.task["additional_field"] = add_value
        
        # store the find call count
        num_finds_before = self.tk.shotgun.finds

        result = context.from_entity(self.tk, self.task["type"], self.task["id"])
        self.check_entity(self.project, result.project)
        self.assertEquals(3, len(result.project))

        self.check_entity(self.shot, result.entity)
        self.assertEquals(3, len(result.entity))

        self.check_entity(self.step, result.step)
        self.assertEquals(3, len(result.step))

        self.check_entity(self.current_user, result.user)

        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])

        self.assertEquals(self.task["type"], result.task["type"])
        self.assertEquals(self.task["id"], result.task["id"])
        self.assertEquals(self.task["content"], result.task["name"])
        self.assertEquals(3, len(result.task))

        add_result = result.additional_entities[0]
        self.check_entity(add_value, add_result)

        # Check that the shotgun method find_one was used
        num_finds_after = self.tk.shotgun.finds
        self.assertTrue( (num_finds_after-num_finds_before) == 1 )
Esempio n. 25
0
    def test_task_from_sg(self, get_current_user):
        """
        Case that all data is found from shotgun query
        Note that additional field is specified in a
        context_additional_entities hook.
        """
        get_current_user.return_value = self.current_user

        # add additional field value to task
        add_value = {"name": "additional", "id": 3, "type": "add_type"}
        self.task["additional_field"] = add_value

        # reset call count on mocked shotgun.find_one method so we can check it later
        self.sg_mock.find_one.reset_mock()

        result = context.from_entity(self.tk, self.task["type"],
                                     self.task["id"])
        self.check_entity(self.project, result.project)
        self.assertEquals(3, len(result.project))

        self.check_entity(self.shot, result.entity)
        self.assertEquals(3, len(result.entity))

        self.check_entity(self.step, result.step)
        self.assertEquals(3, len(result.step))

        self.check_entity(self.current_user, result.user)

        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])

        self.assertEquals(self.task["type"], result.task["type"])
        self.assertEquals(self.task["id"], result.task["id"])
        self.assertEquals(self.task["content"], result.task["name"])
        self.assertEquals(3, len(result.task))

        add_result = result.additional_entities[0]
        self.check_entity(add_value, add_result)

        # Check that the shotgun method find_one was used
        self.assertTrue(self.sg_mock.find_one.called)
Esempio n. 26
0
    def test_task_from_sg(self, get_current_user):
        """
        Case that all data is found from shotgun query
        Note that additional field is specified in a
        context_additional_entities hook.
        """
        get_current_user.return_value = self.current_user
        
        # add additional field value to task
        add_value = {"name":"additional", "id": 3, "type": "add_type"}
        self.task["additional_field"] = add_value
        
        # reset call count on mocked shotgun.find_one method so we can check it later
        self.sg_mock.find_one.reset_mock()

        result = context.from_entity(self.tk, self.task["type"], self.task["id"])
        self.check_entity(self.project, result.project)
        self.assertEquals(3, len(result.project))

        self.check_entity(self.shot, result.entity)
        self.assertEquals(3, len(result.entity))

        self.check_entity(self.step, result.step)
        self.assertEquals(3, len(result.step))

        self.check_entity(self.current_user, result.user)

        self.assertEquals(self.current_user["id"], result.user["id"])
        self.assertEquals(self.current_user["type"], result.user["type"])

        self.assertEquals(self.task["type"], result.task["type"])
        self.assertEquals(self.task["id"], result.task["id"])
        self.assertEquals(self.task["content"], result.task["name"])
        self.assertEquals(3, len(result.task))

        add_result = result.additional_entities[0]
        self.check_entity(add_value, add_result)

        # Check that the shotgun method find_one was used
        self.assertTrue(self.sg_mock.find_one.called)
Esempio n. 27
0
 def test_entity(self):
     result =  context.from_entity(self.tk, self.shot["type"], self.shot["id"])
     self.assertEquals(result.shotgun_url, "http://unit_test_mock_sg/detail/Shot/2" )
Esempio n. 28
0
 def test_task(self):
     """
     Tests string representation of task context
     """
     result = context.from_entity(self.tk, self.task["type"], self.task["id"])
     self.assertEquals(str(result), "task_content, Shot shot_name")
Esempio n. 29
0
 def test_entity(self):
     """
     Tests string representation of shot context
     """
     result = context.from_entity(self.tk, self.shot_alt["type"], self.shot_alt["id"])
     self.assertEquals(str(result), "Shot shot_name_alt")
Esempio n. 30
0
 def test_entity_with_step(self):
     """
     Tests string representation of shot context with a single step set
     """
     result = context.from_entity(self.tk, self.shot["type"], self.shot["id"])
     self.assertEquals(str(result), "step_name, Shot shot_name")
Esempio n. 31
0
 def test_project(self):
     """
     Tests string representation of project context
     """
     result = context.from_entity(self.tk, self.project["type"], self.project["id"])
     self.assertEquals(str(result), "Project project_name")
Esempio n. 32
0
 def test_entity(self):
     result =  context.from_entity(self.tk, self.shot["type"], self.shot["id"])
     self.assertEquals(result.shotgun_url, "http://unit_test_mock_sg/detail/Shot/2" )