def test_from_entity_dictionary(self, get_current_user, from_entity): """ Test context.from_entity_dictionary - this can contruct a context from an entity dictionary looking at linked entities where available. Falls back to 'from_entity' if the entity dictionary doesn't contain everything needed. """ get_current_user.return_value = self.current_user # overload from_entity to ensure it causes a test fail if from_entity_dictionary # falls back to it: from_entity.return_value = {} ent_dict = {"type":self.shot["type"], "id":self.shot["id"], "code":self.shot["code"]} ent_dict["project"] = self.project result = context.from_entity_dictionary(self.tk, ent_dict) self.assertIsNotNone(result) 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)
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, )
def test_from_entity_dictionary(self, get_current_user, from_entity): """ Test context.from_entity_dictionary - this can contruct a context from an entity dictionary looking at linked entities where available. Falls back to 'from_entity' if the entity dictionary doesn't contain everything needed. """ get_current_user.return_value = self.current_user # overload from_entity to ensure it causes a test fail if from_entity_dictionary # falls back to it: from_entity.return_value = {} ent_dict = { "type": self.shot["type"], "id": self.shot["id"], "code": self.shot["code"] } ent_dict["project"] = self.project result = context.from_entity_dictionary(self.tk, ent_dict) self.assertIsNotNone(result) 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)
def test_from_entity_dictionary_additional_entities( self, get_current_user, from_entity): """ Test context.from_entity_dictionary - this can contruct a context from an entity dictionary looking at linked entities where available. Falls back to 'from_entity' if the entity dictionary doesn't contain everything needed. """ get_current_user.return_value = self.current_user # overload from_entity to ensure it causes a test fail if from_entity_dictionary # falls back to it: from_entity.return_value = {} add_value = {"name": "additional", "id": 3, "type": "add_type"} ent_dict = { "type": "Task", "id": self.task["id"], "content": self.task["content"], "additional_field": add_value } ent_dict["project"] = self.project ent_dict["entity"] = self.shot ent_dict["step"] = self.step result = context.from_entity_dictionary(self.tk, ent_dict) self.assertIsNotNone(result) 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.check_entity(self.step, result.step) self.assertEquals(3, len(result.step)) 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))
def test_from_entity_dictionary_additional_entities(self, get_current_user, from_entity): """ Test context.from_entity_dictionary - this can contruct a context from an entity dictionary looking at linked entities where available. Falls back to 'from_entity' if the entity dictionary doesn't contain everything needed. """ get_current_user.return_value = self.current_user # overload from_entity to ensure it causes a test fail if from_entity_dictionary # falls back to it: from_entity.return_value = {} add_value = {"name":"additional", "id": 3, "type": "add_type"} ent_dict = {"type":"Task", "id":self.task["id"], "content":self.task["content"], "additional_field":add_value} ent_dict["project"] = self.project ent_dict["entity"] = self.shot ent_dict["step"] = self.step result = context.from_entity_dictionary(self.tk, ent_dict) self.assertIsNotNone(result) 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.check_entity(self.step, result.step) self.assertEquals(3, len(result.step)) 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))