def test_create_post_same_reference_and_revision(self): """ Tests that when auto is True and we intent to create an object with the same type, reference and revision: * a new and available reference is given to the new object * the object is created. """ data = self.DATA.copy() ref = self.controller.reference rev = self.controller.revision data.update({ "type" : self.TYPE, "reference" : ref, "auto" : True, "revision" : rev, "name" : "A valid object", "group" : str(self.group.id), "lifecycle" : m.get_default_lifecycle().pk, "state" : m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] response = self.post("/object/create/", data) obj = m.PLMObject.objects.get(type=self.TYPE, revision=rev, name="A valid object") self.assertNotEqual(ref, obj.reference) self.assertEqual(self.group.id, obj.group_id) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator)
def test_create_from_template_post(self): data = self.DATA.copy() data["lifecycle"] = m.Lifecycle.objects.get(name="Template") template = self.CONTROLLER.create('TPL_1', 'Document', 'a', self.user, data, True, True) template.add_file(self.get_file("data.test", "plop")) template.promote(checked=True) data = self.DATA.copy() data.update({ "type" : self.TYPE, "reference" : "doc2", "auto" : False, "revision" : "a", "name" : "Docc", "group" : str(self.group.id), "lifecycle" : m.get_default_lifecycle().pk, "state" : m.get_default_state().pk, "template": str(template.id), }) response = self.post("/object/create/", data) obj = m.Document.objects.get(type=self.TYPE, reference="doc2", revision="a") self.assertEqual(obj, response.context["obj"].object) self.assertEqual("Docc", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) df, = obj.files self.assertEqual("data.test", df.filename) self.assertEqual("plop", open(df.file.path).read()) self.assertNotEqual(template.files[0].id, df.id) self.assertEqual(template.object, obj.template)
def test_create_and_attach_post(self): doc = self.attach_to_official_document() data = self.DATA.copy() data.update({ "__next__": "/home/", "related_doc": doc.id, "type": self.TYPE, "reference": "mapart", "auto": False, "revision": "a", "name": "MaPart", "group": str(self.group.id), "lifecycle": m.get_default_lifecycle().pk, "state": m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] response = self.post("/object/create/", data, follow=False, status_code=302) self.assertRedirects(response, "/home/") obj = m.PLMObject.objects.get(type=self.TYPE, reference="mapart", revision="a") self.assertEqual("MaPart", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) link = m.DocumentPartLink.current_objects.get(document=doc.object, part=obj)
def test_create_post_same_reference_and_revision(self): """ Tests that when auto is True and we intent to create an object with the same type, reference and revision: * a new and available reference is given to the new object * the object is created. """ data = self.DATA.copy() ref = self.controller.reference rev = self.controller.revision data.update({ "type": self.TYPE, "reference": ref, "auto": True, "revision": rev, "name": "A valid object", "group": str(self.group.id), "lifecycle": m.get_default_lifecycle().pk, "state": m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] response = self.post("/object/create/", data) obj = m.PLMObject.objects.get(type=self.TYPE, revision=rev, name="A valid object") self.assertNotEqual(ref, obj.reference) self.assertEqual(self.group.id, obj.group_id) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator)
def test_create_post_error_same_reference(self): """ Tests that the creation of an object with the same type and reference but a different revision is forbidden. """ data = self.DATA.copy() ref = self.controller.reference rev = "a new revision" data.update({ "type": self.TYPE, "reference": ref, "auto": False, "revision": rev, "name": "An invalid object", "group": str(self.group.id), "lifecycle": m.get_default_lifecycle().pk, "state": m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] response = self.post("/object/create/", data) qset = m.PLMObject.objects.filter(type=self.TYPE, reference=ref, revision=rev) self.assertFalse(response.context["creation_form"].is_valid()) self.assertFalse(qset.exists())
def test_create_redirect_post(self): data = self.DATA.copy() data.update({ "__next__": "/home/", "type": self.TYPE, "reference": "mapart", "auto": False, "revision": "a", "name": "MaPart", "group": str(self.group.id), "lifecycle": m.get_default_lifecycle().pk, "state": m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] page = "files" if issubclass(model_cls, m.Document) else "attributes" response = self.post("/object/create/", data, follow=False, status_code=302) self.assertRedirects(response, "/home/") obj = m.PLMObject.objects.get(type=self.TYPE, reference="mapart", revision="a") self.assertEqual("MaPart", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator)
def test_create_and_attach_post(self): part = self.get_part("part1") data = self.DATA.copy() data.update({ "__next__": "/home/", "related_part": part.id, "type": self.TYPE, "reference": "doc2", "auto": False, "revision": "a", "name": "Docc", "group": str(self.group.id), "lifecycle": m.get_default_lifecycle().pk, "state": m.get_default_state().pk, }) response = self.post("/object/create/", data, follow=False, status_code=302) self.assertRedirects(response, "/home/") obj = m.PLMObject.objects.get(type=self.TYPE, reference="doc2", revision="a") self.assertEqual("Docc", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) link = m.DocumentPartLink.current_objects.get(document=obj, part=part.id)
def test_create_and_attach_post_error(self): part = self.get_part("part1") # cancels the part so that it can not be attached part.cancel() data = self.DATA.copy() data.update({ "__next__": "/home/", "related_part": part.id, "type": self.TYPE, "reference": "doc2", "auto": False, "revision": "a", "name": "Docc", "group": str(self.group.id), "lifecycle": m.get_default_lifecycle().pk, "state": m.get_default_state().pk, }) response = self.post("/object/create/", data, follow=True, page="parts") msgs = list(response.context["messages"]) self.assertEqual(2, len(msgs)) self.assertEqual(messages.INFO, msgs[0].level) self.assertEqual(messages.ERROR, msgs[1].level) obj = m.PLMObject.objects.get(type=self.TYPE, reference="doc2", revision="a") self.assertEqual("Docc", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) self.assertFalse( m.DocumentPartLink.current_objects.filter(document=obj, part=part.id).exists())
def test_create_and_attach_post_error(self): doc = self.attach_to_official_document() # cancels the doc so that it can not be attached doc.cancel() data = self.DATA.copy() data.update({ "__next__" : "/home/", "related_doc" : doc.id, "type" : self.TYPE, "reference" : "mapart", "auto" : False, "revision" : "a", "name" : "MaPart", "group" : str(self.group.id), "lifecycle" : m.get_default_lifecycle().pk, "state" : m.get_default_state().pk, }) response = self.post("/object/create/", data, follow=True, page="doc-cad") msgs = list(response.context["messages"]) self.assertEqual(2, len(msgs)) self.assertEqual(messages.INFO, msgs[0].level) self.assertEqual(messages.ERROR, msgs[1].level) obj = m.PLMObject.objects.get(type=self.TYPE, reference="mapart", revision="a") self.assertEqual("MaPart", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) self.assertFalse(m.DocumentPartLink.current_objects.filter( document=doc.object, part=obj).exists())
def test_create_from_template_post(self): data = self.DATA.copy() data["lifecycle"] = m.Lifecycle.objects.get(name="Template") template = self.CONTROLLER.create('TPL_1', 'Document', 'a', self.user, data, True, True) template.add_file(self.get_file("data.test", "plop")) template.promote(checked=True) data = self.DATA.copy() data.update({ "type": self.TYPE, "reference": "doc2", "auto": False, "revision": "a", "name": "Docc", "group": str(self.group.id), "lifecycle": m.get_default_lifecycle().pk, "state": m.get_default_state().pk, "template": str(template.id), }) response = self.post("/object/create/", data) obj = m.Document.objects.get(type=self.TYPE, reference="doc2", revision="a") self.assertEqual(obj, response.context["obj"].object) self.assertEqual("Docc", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) df, = obj.files self.assertEqual("data.test", df.filename) self.assertEqual("plop", open(df.file.path).read()) self.assertNotEqual(template.files[0].id, df.id) self.assertEqual(template.object, obj.template)
def get_initial_creation_data(cls, start=0): u""" Returns initial data to create a new object (from :func:`get_creation_form`). :param cls: class of the created object :param start: used to generate the reference, see :func:`get_new_reference` """ if issubclass(cls, m.PLMObject): data = { 'reference' : get_new_reference(cls, start), 'revision' : 'a', 'lifecycle' : str(m.get_default_lifecycle().pk), } else: data = {} return data
def get_initial_creation_data(user, cls, start=0, inbulk_cache=None): u""" Returns initial data to create a new object (from :func:`get_creation_form`). :param user: user who will create the object :param cls: class of the created object :param start: used to generate the reference, see :func:`.get_new_reference` """ if issubclass(cls, m.PLMObject): data = { 'reference': get_new_reference(user, cls, start, inbulk_cache), 'revision': 'a', 'lifecycle': str(m.get_default_lifecycle().pk), } else: data = {} return data
def test_create_post(self): data = self.DATA.copy() data.update({ "type" : self.TYPE, "reference" : "mapart", "auto" : False, "revision" : "a", "name" : "MaPart", "group" : str(self.group.id), "lifecycle" : m.get_default_lifecycle().pk, "state" : m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] page = "files" if issubclass(model_cls, m.Document) else "attributes" response = self.post("/object/create/", data, page=page) obj = m.PLMObject.objects.get(type=self.TYPE, reference="mapart", revision="a") self.assertEqual(obj.id, response.context["obj"].id) self.assertEqual("MaPart", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator)
def test_create_post_error_same_reference_and_revision(self): """ Tests that the creation of an object with the same type , reference and revision is forbidden when auto is not True. """ data = self.DATA.copy() ref = self.controller.reference rev = self.controller.revision data.update({ "type" : self.TYPE, "reference" : ref, "auto" : False, "revision" : rev, "name" : "An invalid object", "group" : str(self.group.id), "lifecycle" : m.get_default_lifecycle().pk, "state" : m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] response = self.post("/object/create/", data) qset = m.PLMObject.objects.filter(type=self.TYPE, reference=ref, revision=rev) self.assertFalse(response.context["creation_form"].is_valid())
def test_create_and_attach_post(self): part = self.get_part("part1") data = self.DATA.copy() data.update({ "__next__" : "/home/", "related_part" : part.id, "type" : self.TYPE, "reference" : "doc2", "auto" : False, "revision" : "a", "name" : "Docc", "group" : str(self.group.id), "lifecycle" : m.get_default_lifecycle().pk, "state" : m.get_default_state().pk, }) response = self.post("/object/create/", data, follow=False, status_code=302) self.assertRedirects(response, "/home/") obj = m.PLMObject.objects.get(type=self.TYPE, reference="doc2", revision="a") self.assertEqual("Docc", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) link = m.DocumentPartLink.current_objects.get(document=obj, part=part.id)
def test_create_and_attach_post(self): doc = self.attach_to_official_document() data = self.DATA.copy() data.update({ "__next__" : "/home/", "related_doc" : doc.id, "type" : self.TYPE, "reference" : "mapart", "auto" : False, "revision" : "a", "name" : "MaPart", "group" : str(self.group.id), "lifecycle" : m.get_default_lifecycle().pk, "state" : m.get_default_state().pk, }) model_cls = m.get_all_plmobjects()[self.TYPE] response = self.post("/object/create/", data, follow=False, status_code=302) self.assertRedirects(response, "/home/") obj = m.PLMObject.objects.get(type=self.TYPE, reference="mapart", revision="a") self.assertEqual("MaPart", obj.name) self.assertEqual(self.user, obj.owner) self.assertEqual(self.user, obj.creator) link = m.DocumentPartLink.current_objects.get(document=doc.object, part=obj)
def test_create_post(self): self.assertEqual(1, models.Part.objects.count()) self.assertViewErrorPost("/object/create/", type="Part", reference="reff", revision="rev", name="e", lifecycle=models.get_default_lifecycle().pk, group=self.group.id) self.assertEqual(1, models.Part.objects.count())
def test_get_default(self): lifecycle = get_default_lifecycle()
def test_to_list(self): lifecycle = get_default_lifecycle() lc_list = lifecycle.to_states_list() self.assertEqual(lc_list.name, lifecycle.name) lcs = LifecycleStates.objects.filter(lifecycle=lifecycle).order_by("rank") self.assertEqual(len(lcs), len(lc_list))