Esempio n. 1
0
    def test_doc_cad_update_post_empty_selection(self):
        doc1 = DocumentController.create("doc1", "Document", "a", self.user,
                self.DATA)
        doc2 = DocumentController.create("doc2", "Document", "a", self.user,
                self.DATA)
        self.controller.attach_to_document(doc1)
        self.controller.attach_to_document(doc2)
        data = {
                'form-TOTAL_FORMS' : '2',
                'form-INITIAL_FORMS' : '2',
                'form-MAX_NUM_FORMS' : '',

                'form-0-id' : doc1.get_attached_parts()[0].id,
                'form-0-part' : self.controller.id,
                'form-0-document' : doc1.id,
                'form-0-delete' : '',

                'form-1-id' : doc2.get_attached_parts()[0].id,
                'form-1-part' : self.controller.id,
                'form-1-document' : doc2.id,
                'form-1-delete' : '',
            }
        response = self.post(self.base_url + "doc-cad/", data, page="doc-cad")
        self.assertEqual(2, response.context["documents"].count())
        forms_ = response.context["forms"]
        self.assertEqual(set((doc1.id, doc2.id)),
                set(f.instance.document.id for f in forms_.values()))
Esempio n. 2
0
 def test_attached_documents_two_parts(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     doc.attach_to_part(self.controller)
     doc2 = DocumentController.create("Doc2", "Document", "a", self.user,
             self.DATA)
     doc2.attach_to_part(self.controller)
     wanted = [
         {
             "id": doc.id,
             "reference": doc.reference,
             "type": doc.type,
             "revision": doc.revision,
             "name": doc.name,
         },
         {
             "id": doc2.id,
             "reference": doc2.reference,
             "type": doc2.type,
             "revision": doc2.revision,
             "name": doc2.name,
         },
     ]
     key = lambda x: x["id"]
     url = "/api/object/%d/attached_documents/" % self.controller.id
     data = self.get(url)
     self.assertEqual(sorted(data["documents"], key=key), sorted(wanted, key=key))
Esempio n. 3
0
def search(request, editable_only="true", with_file_only="true"):
    """
    Returns all objects matching a query.

    :param editable_only: if ``"true"`` (the default), returns only editable objects
    :param with_file_only: if ``"true"`` (the default), returns only documents with 
                           at least one file

    :implements: :func:`http_api.search`
    """
    if request.GET and "type" in request.GET:
        attributes_form = forms.TypeForm(request.GET)
        if attributes_form.is_valid():
            query_dict = {}
            cls = models.get_all_plmobjects()[attributes_form.cleaned_data["type"]]
            extra_attributes_form = forms.get_search_form(cls, request.GET)
            results = cls.objects.all()
            if extra_attributes_form.is_valid():
                results = extra_attributes_form.search(results)
                objects = []
                for res in results:
                    if editable_only == "false" or res.is_editable:
                        if with_file_only == "true" and hasattr(res, "files") \
                           and not bool(res.files):
                            continue
                        if editable_only == "true":
                            obj = DocumentController(res, request.user)
                            if not obj.check_permission("owner", False):
                                continue
                        objects.append(object_to_dict(res))
                return {"objects" : objects} 
    return {"result": "error"}
Esempio n. 4
0
 def test_doc_cad_update_post_empty_selection(self):
     doc1 = DocumentController.create("doc1", "Document", "a", self.user,
                                      self.DATA)
     doc2 = DocumentController.create("doc2", "Document", "a", self.user,
                                      self.DATA)
     self.controller.attach_to_document(doc1)
     self.controller.attach_to_document(doc2)
     data = {
         'form-TOTAL_FORMS': '2',
         'form-INITIAL_FORMS': '2',
         'form-MAX_NUM_FORMS': '',
         'form-0-id': doc1.get_attached_parts()[0].id,
         'form-0-part': self.controller.id,
         'form-0-document': doc1.id,
         'form-0-delete': '',
         'form-1-id': doc2.get_attached_parts()[0].id,
         'form-1-part': self.controller.id,
         'form-1-document': doc2.id,
         'form-1-delete': '',
     }
     response = self.post(self.base_url + "doc-cad/", data, page="doc-cad")
     self.assertEqual(2, response.context["documents"].count())
     forms_ = response.context["forms"]
     self.assertEqual(set((doc1.id, doc2.id)),
                      set(f.instance.document.id for f in forms_.values()))
Esempio n. 5
0
 def test_revise_two_attached_documents_get(self):
     """
     Tests a get request to revise a part with two attached documents.
     One document is a draft, the other is official.
     """
     d1 = DocumentController.create("RefDocument", "Document", "a",
                                    self.user, self.DATA)
     self.controller.attach_to_document(d1)
     d2 = DocumentController.create("document_2", "Document", "a",
                                    self.user, self.DATA)
     self.controller.attach_to_document(d2)
     d2.object.is_promotable = lambda: True
     d2.promote()
     response = self.get(self.base_url + "revisions/")
     # checks that it is necessary to confirm the revision
     self.assertTrue(response.context["confirmation"])
     formset = response.context["doc_formset"]
     self.assertEqual(2, formset.total_form_count())
     form1, form2 = formset.forms
     self.assertTrue(form1.fields["selected"].initial)
     self.assertTrue(form2.fields["selected"].initial)
     self.assertEqual([d1.id, d2.id],
                      sorted([
                          form1.initial["document"].id,
                          form2.initial["document"].id
                      ]))
Esempio n. 6
0
 def test_doc_cad(self):
     doc1 = DocumentController.create("doc1", "Document", "a", self.user, self.DATA)
     doc2 = DocumentController.create("doc2", "Document", "a", self.user, self.DATA)
     self.controller.attach_to_document(doc1)
     self.controller.attach_to_document(doc2)
     response = self.get(self.base_url + "doc-cad/", page="doc-cad")
     self.assertEqual(2, len(list(response.context["object_doc_cad"])))
Esempio n. 7
0
    def test_doc_cad_update_post_all_selected(self):
        doc1 = DocumentController.create("doc1", "Document", "a", self.user,
                self.DATA)
        doc2 = DocumentController.create("doc2", "Document", "a", self.user,
                self.DATA)
        self.controller.attach_to_document(doc1)
        self.controller.attach_to_document(doc2)
        data = {
                'form-TOTAL_FORMS' : '2',
                'form-INITIAL_FORMS' : '2',
                'form-MAX_NUM_FORMS' : '',

                'form-0-id' : doc1.get_attached_parts()[0].id,
                'form-0-part' : self.controller.id,
                'form-0-document' : doc1.id,
                'form-0-delete' : 'on',

                'form-1-id' : doc2.get_attached_parts()[0].id,
                'form-1-part' : self.controller.id,
                'form-1-document' : doc2.id,
                'form-1-delete' : 'on',
            }
        response = self.post(self.base_url + "doc-cad/", data, page="doc-cad")
        self.assertEqual(0, response.context["documents"].count())
        self.assertFalse(response.context["forms"])
Esempio n. 8
0
File: api.py Progetto: amarh/openPLM
def search(request, editable_only="true", with_file_only="true"):
    """
    Returns all objects matching a query.

    :param editable_only: if ``"true"`` (the default), returns only editable objects
    :param with_file_only: if ``"true"`` (the default), returns only documents with
                           at least one file

    :implements: :func:`http_api.search`
    """
    if request.GET and "type" in request.GET:
        form = forms.SimpleSearchForm(request.GET)
        if form.is_valid():
            # object may have been deleted but not yet unindexed
            results = [r.object for r in form.search().load_all()[:30] if r is not None]
            objects = []
            ids = set()
            for res in results:
                if isinstance(res, models.DocumentFile):
                    res = res.document.get_leaf_object()
                if res.id in ids: # avoiding duplicated results
                    continue
                if editable_only == "false" or res.is_editable:
                    if with_file_only == "true" and hasattr(res, "files") \
                       and not bool(res.files):
                        continue
                    if editable_only == "true":
                        obj = DocumentController(res, request.user)
                        if not obj.check_in_group(request.user, False):
                            continue
                    ids.add(res.id)
                    objects.append(object_to_dict(res))
            return {"objects" : objects}
    return {"result": "error"}
Esempio n. 9
0
 def test_doc_cad(self):
     doc1 = DocumentController.create("doc1", "Document", "a", self.user,
             self.DATA)
     doc2 = DocumentController.create("doc2", "Document", "a", self.user,
             self.DATA)
     self.controller.attach_to_document(doc1)
     self.controller.attach_to_document(doc2)
     doc2.object.state = doc2.object.lifecycle.last_state
     doc2.object.save()
     response = self.get(self.base_url + "doc-cad/", page="doc-cad")
     self.assertEqual(2, response.context["documents"].count())
     forms_ = response.context["forms"]
     self.assertEqual([doc1.id], [f.instance.document.id for f in forms_.values()])
Esempio n. 10
0
 def test_doc_cad(self):
     doc1 = DocumentController.create("doc1", "Document", "a", self.user,
                                      self.DATA)
     doc2 = DocumentController.create("doc2", "Document", "a", self.user,
                                      self.DATA)
     self.controller.attach_to_document(doc1)
     self.controller.attach_to_document(doc2)
     doc2.object.state = doc2.object.lifecycle.last_state
     doc2.object.save()
     response = self.get(self.base_url + "doc-cad/", page="doc-cad")
     self.assertEqual(2, response.context["documents"].count())
     forms_ = response.context["forms"]
     self.assertEqual([doc1.id],
                      [f.instance.document.id for f in forms_.values()])
Esempio n. 11
0
 def test_revise_one_attached_revised_document_post(self):
     """
     Tests a post request to revise a part which has one attached document.
     The document has been revised and its revision is selected.
     """
     document = DocumentController.create("RefDocument", "Document", "a", self.user, self.DATA)
     self.controller.attach_to_document(document)
     d2 = document.revise("b")
     data = { "revision" : "b",
              "parents-TOTAL_FORMS" : "0",
              "parents-INITIAL_FORMS" : "0",
              "children-TOTAL_FORMS" : "0",
              "children-INITIAL_FORMS" : "0",
              "documents-TOTAL_FORMS" : "1",
              "documents-INITIAL_FORMS" : "1",
              "documents-0-selected" : "on",
              "documents-0-document" : d2.id,
              }
     response = self.post(self.base_url + "revisions/", data)
     revisions = self.controller.get_next_revisions()
     self.assertEqual(1, len(revisions))
     rev = revisions[0].part
     self.assertEqual("b", rev.revision)
     # ensure document is still attached to the old revision
     documents = self.controller.get_attached_documents().values_list("document", flat=True)
     self.assertEqual([document.id], list(documents))
     # ensure d2 is attached to the new revision
     documents = rev.documentpartlink_part.values_list("document", flat=True)
     self.assertEqual([d2.id], list(documents))
Esempio n. 12
0
 def test_revise_error_not_revisable(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     rev = doc.revise("n")
     data = self.post("/api/object/%d/revise/" % doc.id, revision="b")
     self.assertEqual("error", data["result"])
     self.assertEqual([rev.id], [o.id for o in doc.get_next_revisions()])
Esempio n. 13
0
 def test_attach_doc_part_post(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     self.assertAjaxErrorPost("/ajax/attach/%d/" % doc.id,
             type=self.ctrl.type, reference=self.ctrl.reference,
             revision=self.ctrl.revision)
     self.assertFalse(self.ctrl.get_attached_documents())
Esempio n. 14
0
 def test_invalid_download(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user, self.DATA)
     df = doc.add_file(self.get_file("plop"))
     doc.object.state =doc.object.lifecycle.official_state
     doc.object.save()
     doc.add_reader(self.restricted_user)
     self.assertViewErrorGet("/file/%d/" % df.id)
Esempio n. 15
0
 def test_unlock(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     df = doc.add_file(self.get_file())
     doc.lock(df)
     self.assertApiErrorGet("/api/object/%d/unlock/%d/" % (doc.id, df.id))
     self.assertTrue(doc.files[0].locked)
Esempio n. 16
0
 def test_revise_one_attached_revised_document_post_error(self):
     """
     Tests a post request to revise a part which has one attached document.
     The document has been revised and has been selected instead of its revision.
     """
     document = DocumentController.create("RefDocument", "Document", "a",
                                          self.user, self.DATA)
     self.controller.attach_to_document(document)
     d2 = document.revise("b")
     self.controller.attach_to_document(d2)
     data = {
         "revision": "b",
         "parents-TOTAL_FORMS": "0",
         "parents-INITIAL_FORMS": "0",
         "children-TOTAL_FORMS": "0",
         "children-INITIAL_FORMS": "0",
         "documents-TOTAL_FORMS": "1",
         "documents-INITIAL_FORMS": "1",
         "documents-0-selected": "on",
         "documents-0-document": document.id,
     }
     response = self.post(self.base_url + "revisions/", data)
     revisions = self.controller.get_next_revisions()
     # no revisions have been created
     self.assertEqual([], revisions)
     # ensure documents are still attached to the old revision
     documents = self.controller.get_attached_documents().values_list(
         "document", flat=True)
     self.assertEqual(set((document.id, d2.id)), set(documents))
Esempio n. 17
0
 def test_revise_one_deprecated_document_attached_post(self):
     """
     Tests a post request to revise a part which has one deprecated
     attached document.
     This document must not be suggested when the user revises the part.
     """
     document = DocumentController.create("RefDocument", "Document", "a", self.user, self.DATA)
     self.controller.attach_to_document(document)
     document.object.state = document.lifecycle.last_state
     document.object.save()
     data = { "revision" : "b",
              "parents-TOTAL_FORMS" : "0",
              "parents-INITIAL_FORMS" : "0",
              "children-TOTAL_FORMS" : "0",
              "children-INITIAL_FORMS" : "0",
              "documents-TOTAL_FORMS" : "1",
              "documents-INITIAL_FORMS" : "1",
              "documents-0-selected" : "",
              "documents-0-document" : document.id,
              }
     response = self.post(self.base_url + "revisions/", data)
     # even if we submit a formset, it should not be parsed
     revisions = self.controller.get_next_revisions()
     self.assertEqual(1, len(revisions))
     rev = revisions[0].part
     # ensure document is still attached to the old revision
     documents = self.controller.get_attached_documents().values_list("document", flat=True)
     self.assertEqual([document.id], list(documents))
     # ensure document is not attached to the new revision
     self.assertFalse(rev.documentpartlink_part.now().exists())
     # ensure only the old revision is attached to document
     self.assertEqual([self.controller.id],
         list(document.get_attached_parts().values_list("part", flat=True)))
Esempio n. 18
0
 def test_revise_one_attached_revised_document_post_error(self):
     """
     Tests a post request to revise a part which has one attached document.
     The document has been revised and has been selected instead of its revision.
     """
     document = DocumentController.create("RefDocument", "Document", "a", self.user, self.DATA)
     self.controller.attach_to_document(document)
     d2 = document.revise("b")
     self.controller.attach_to_document(d2)
     data = { "revision" : "b",
              "parents-TOTAL_FORMS" : "0",
              "parents-INITIAL_FORMS" : "0",
              "children-TOTAL_FORMS" : "0",
              "children-INITIAL_FORMS" : "0",
              "documents-TOTAL_FORMS" : "1",
              "documents-INITIAL_FORMS" : "1",
              "documents-0-selected" : "on",
              "documents-0-document" : document.id,
              }
     response = self.post(self.base_url + "revisions/", data)
     revisions = self.controller.get_next_revisions()
     # no revisions have been created
     self.assertEqual([], revisions)
     # ensure documents are still attached to the old revision
     documents = self.controller.get_attached_documents().values_list("document", flat=True)
     self.assertEqual(set((document.id, d2.id)), set(documents))
Esempio n. 19
0
 def test_get_files(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     df = doc.add_file(self.get_file())
     data = self.get("/api/object/%d/files/" % doc.id)
     self.assertEqual("ok", data["result"])
     self.assertEqual([df.id], [f["id"] for f in data["files"]])
Esempio n. 20
0
 def test_attach_to_part(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.get("/api/object/%d/attach_to_part/%d/" %
             (doc.id, self.controller.id))
     self.assertEqual("ok", data["result"])
     self.assertEqual(self.controller.id, doc.get_attached_parts()[0].id)
Esempio n. 21
0
 def test_navigate_doc_parts(self):
     """
     Tests a navigate with the "doc_parts" option set.
     """
     data = self.DATA.copy()
     data["name"] = "Coffee"
     # the company owns doc so that it does not appear if only
     # the "owned" option is set
     doc = DocumentController.create("doc", "Document", "d", self.cie, data,
                                     True, True)
     self.part.attach_to_document(doc)
     for osr, results in ((False, ()), (True, (doc.object, ))):
         self.get_graph_data(
             {
                 "owned": True,
                 OSR: osr,
                 "doc_parts": [self.part.id]
             }, results)
         self.assertTrue(3, 2)
     for result in (self.cie, self.group, self.user):
         self.get_graph_data(
             {
                 "owned": True,
                 OSR: True,
                 "doc_parts": [self.part.id]
             }, (result, ))
         self.assertCount(1, 0)
Esempio n. 22
0
 def test_revise_one_attached_revised_document_post(self):
     """
     Tests a post request to revise a part which has one attached document.
     The document has been revised and its revision is selected.
     """
     document = DocumentController.create("RefDocument", "Document", "a",
                                          self.user, self.DATA)
     self.controller.attach_to_document(document)
     d2 = document.revise("b")
     data = {
         "revision": "b",
         "parents-TOTAL_FORMS": "0",
         "parents-INITIAL_FORMS": "0",
         "children-TOTAL_FORMS": "0",
         "children-INITIAL_FORMS": "0",
         "documents-TOTAL_FORMS": "1",
         "documents-INITIAL_FORMS": "1",
         "documents-0-selected": "on",
         "documents-0-document": d2.id,
     }
     response = self.post(self.base_url + "revisions/", data)
     revisions = self.controller.get_next_revisions()
     self.assertEqual(1, len(revisions))
     rev = revisions[0].part
     self.assertEqual("b", rev.revision)
     # ensure document is still attached to the old revision
     documents = self.controller.get_attached_documents().values_list(
         "document", flat=True)
     self.assertEqual([document.id], list(documents))
     # ensure d2 is attached to the new revision
     documents = rev.documentpartlink_part.values_list("document",
                                                       flat=True)
     self.assertEqual([d2.id], list(documents))
Esempio n. 23
0
 def test_lock(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     df = doc.add_file(self.get_file())
     data = self.get("/api/object/%d/lock/%d/" % (doc.id, df.id))
     self.assertEqual("ok", data["result"])
     self.assertTrue(doc.files[0].locked)
Esempio n. 24
0
 def test_add_file(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     mock_file = self.get_file()
     self.assertApiErrorPost("/api/object/%d/add_file/" % doc.id,
             filename=mock_file)
     self.assertFalse(doc.files)
Esempio n. 25
0
 def test_files(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user, self.DATA)
     doc.object.state =doc.object.lifecycle.official_state
     doc.object.save()
     doc.add_reader(self.restricted_user)
     self.assertViewErrorGet(doc.plmobject_url + "files/")
     self.assertViewErrorGet(doc.plmobject_url + "files/add/")
Esempio n. 26
0
 def test_checkin(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     df = doc.add_file(self.get_file(data="t"))
     mock_file = self.get_file(data="robert")
     self.assertApiErrorPost("/api/object/%d/checkin/%d/" % (doc.id, df.id),
             filename=mock_file)
     self.assertEqual("t", doc.files[0].file.read())
Esempio n. 27
0
 def test_is_promotable_one_official_document(self):
     """Tests that a part with one official document attached and another
     not official is promotable."""
     doc = DocumentController.create("doc_2", "Document", "a", self.user,
             self.DATA)
     self.controller3.attach_to_document(self.document)
     self.controller3.attach_to_document(doc)
     self.failUnless(self.controller3.is_promotable())
Esempio n. 28
0
 def test_doc_add_add_post(self):
     doc1 = DocumentController.create("doc1", "Document", "a", self.user,
             self.DATA)
     data = {"type" : doc1.type, "reference" : doc1.reference,
             "revision" : doc1.revision }
     response = self.post(self.base_url + "doc-cad/add/", data)
     document = self.controller.get_attached_documents()[0].document
     self.assertEqual(doc1.object, document)
Esempio n. 29
0
 def test_add_thumbnail(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     df = doc.add_file(self.get_file(), thumbnail=False)
     thumbnail = ContentFile(file("datatests/thumbnail.png").read())
     thumbnail.name = "Thumbnail.png"
     self.assertApiErrorPost("/api/object/%d/add_thumbnail/%d/" % (doc.id, df.id),
             filename=thumbnail)
     self.assertFalse(doc.files[0].thumbnail.name)
Esempio n. 30
0
 def test_doc_cad(self):
     # get
     self.assertViewErrorGet(self.ctrl.plmobject_url + "doc-cad/")
     self.assertViewErrorGet(self.ctrl.plmobject_url + "doc-cad/add/")
     # post
     doc = DocumentController.create("Doc", "Document", "a", self.user, self.DATA)
     self.assertViewErrorPost(self.ctrl.plmobject_url + "doc-cad/",
             type="Document", reference="Doc", revision="a")
     self.assertEquals(0, models.DocumentPartLink.current_objects.count())
Esempio n. 31
0
 def test_valid_download(self):
     content = "pif paf pouf"
     doc = DocumentController.create("Doc", "Document", "a", self.user, self.DATA)
     df = doc.add_file(self.get_file(data=content))
     doc.object.state =doc.object.lifecycle.official_state
     doc.object.save()
     doc.add_reader(self.restricted_user)
     response = self.client.get("/file/public/%d/" % df.id)
     self.assertEqual(content, "".join(response.streaming_content))
Esempio n. 32
0
 def test_search_deprecated_file(self):
     doc = DocumentController.create("doccc", "Document", "d",
             self.user, self.DATA)
     df = doc.add_file(self.get_file(name="pppp.txt", data="monocle monocle"))
     results = self.search("monocle", "Document")
     df.deprecated = True
     df.save()
     results = self.search("monocle", "Document")
     self.assertEqual([], results)
Esempio n. 33
0
 def test_search_deprecated_file(self):
     doc = DocumentController.create("doccc", "Document", "d", self.user,
                                     self.DATA)
     df = doc.add_file(
         self.get_file(name="pppp.txt", data="monocle monocle"))
     results = self.search("monocle", "Document")
     df.deprecated = True
     df.save()
     results = self.search("monocle", "Document")
     self.assertEqual([], results)
Esempio n. 34
0
    def test_attach(self):
        expected = []
        result_part = []
        result_doc = []
        for pstate, dstate, powner, downer, can_attach in self.MATRICE:
            self.part.object.state = self.states[pstate]
            self.part.object.lifecycle = self.lifecycles[pstate]
            self.doc.object.state = self.states[dstate]
            self.doc.object.lifecycle = self.lifecycles[dstate]
            self.part.set_owner(self.user if powner else self.other_owner, True)
            self.doc.set_owner(self.user if downer else self.other_owner, True)

            expected.append(can_attach)
            pctrl = PartController(self.part.object, self.user)
            result_part.append(pctrl.can_attach_document(self.doc.object))
            dctrl = DocumentController(self.doc.object, self.user)
            result_doc.append(dctrl.can_attach_part(self.part.object))
        self.assertEqual(expected, result_part)
        self.assertEqual(expected, result_doc)
Esempio n. 35
0
 def test_add_thumbnail(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     df = doc.add_file(self.get_file())
     thumbnail = ContentFile(file("datatests/thumbnail.png").read())
     thumbnail.name = "Thumbnail.png"
     data = self.post("/api/object/%d/add_thumbnail/%d/" % (doc.id, df.id),
             filename=thumbnail)
     self.assertEqual("ok", data["result"])
     self.assertNotEqual(None, doc.files[0].thumbnail)
Esempio n. 36
0
 def test_revise_two_attached_documents_post(self):
     """
     Tests a post request to revise a part with two attached documents.
     One document is a draft and not selected, the other is official and selected.
     """
     d1 = DocumentController.create("RefDocument", "Document", "a",
                                    self.user, self.DATA)
     self.controller.attach_to_document(d1)
     d2 = DocumentController.create("document_2", "Document", "a",
                                    self.user, self.DATA)
     self.controller.attach_to_document(d2)
     d2.object.is_promotable = lambda: True
     d2.promote()
     data = {
         "revision": "b",
         "parents-TOTAL_FORMS": "0",
         "parents-INITIAL_FORMS": "0",
         "children-TOTAL_FORMS": "0",
         "children-INITIAL_FORMS": "0",
         "documents-TOTAL_FORMS": "2",
         "documents-INITIAL_FORMS": "2",
         "documents-0-selected": "",
         "documents-0-document": d1.id,
         "documents-1-selected": "on",
         "documents-1-document": d2.id,
     }
     response = self.post(self.base_url + "revisions/", data)
     revisions = self.controller.get_next_revisions()
     self.assertEqual(1, len(revisions))
     rev = revisions[0].part
     self.assertEqual("b", rev.revision)
     # ensure d1 and d2 are still attached to the old revision
     documents = self.controller.get_attached_documents().values_list(
         "document", flat=True)
     self.assertEqual([d1.id, d2.id], sorted(documents))
     # ensure d2 is attached to the new revision
     documents = rev.documentpartlink_part.values_list("document",
                                                       flat=True)
     self.assertEqual([d2.id], list(documents))
     # ensure both documents are attached to d2
     self.assertEqual([self.controller.id, rev.id],
                      sorted(d2.get_attached_parts().values_list(
                          "part", flat=True)))
Esempio n. 37
0
 def test_add_file(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     mock_file = self.get_file()
     data = self.post("/api/object/%d/add_file/" % doc.id,
             filename=mock_file)
     self.assertEqual("ok", data["result"])
     self.assertTrue(doc.files)
     self.assertEqual(mock_file.name, data["doc_file"]["filename"])
     self.assertEqual(doc.files[0].id, data["doc_file"]["id"])
Esempio n. 38
0
 def test_revise(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.post("/api/object/%d/revise/" % doc.id, revision="b")
     self.assertEqual("ok", data["result"])
     new_doc = data["doc"]
     revb = doc.get_next_revisions()[0]
     self.assertEqual("b", new_doc["revision"])
     self.assertEqual("b", revb.revision)
     self.assertEqual(revb.id, new_doc["id"])
Esempio n. 39
0
 def test_valid_public_attached_doc3(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user, self.DATA)
     doc.attach_to_part(self.ctrl.object)
     doc.object.state =doc.object.lifecycle.official_state
     doc.object.save()
     response = self.client.get(self.ctrl.plmobject_url + "public/")
     self.assertEqual(200, response.status_code)
     self.assertTemplateUsed(response, "public.html")
     ctx = response.context
     self.assertEquals(1, len(ctx["revisions"]))
     self.assertFalse(ctx["attached"])
Esempio n. 40
0
 def test_doc_add_add_post(self):
     doc1 = DocumentController.create("doc1", "Document", "a", self.user,
                                      self.DATA)
     data = {
         "type": doc1.type,
         "reference": doc1.reference,
         "revision": doc1.revision
     }
     response = self.post(self.base_url + "doc-cad/add/", data)
     document = self.controller.get_attached_documents()[0].document
     self.assertEqual(doc1.object, document)
Esempio n. 41
0
    def test_attach(self):
        expected = []
        result_part = []
        result_doc = []
        for pstate, dstate, powner, downer, can_attach in self.MATRICE:
            self.part.object.state = self.states[pstate]
            self.part.object.lifecycle = self.lifecycles[pstate]
            self.doc.object.state = self.states[dstate]
            self.doc.object.lifecycle = self.lifecycles[dstate]
            self.part.set_owner(self.user if powner else self.other_owner,
                                True)
            self.doc.set_owner(self.user if downer else self.other_owner, True)

            expected.append(can_attach)
            pctrl = PartController(self.part.object, self.user)
            result_part.append(pctrl.can_attach_document(self.doc.object))
            dctrl = DocumentController(self.doc.object, self.user)
            result_doc.append(dctrl.can_attach_part(self.part.object))
        self.assertEqual(expected, result_part)
        self.assertEqual(expected, result_doc)
Esempio n. 42
0
    def test_is_revisable(self):
        doc = DocumentController.create("Doc", "Document", "a", self.user,
                self.DATA)
        data = self.get("/api/object/%d/is_revisable/" % doc.id)
        self.assertEqual("ok", data["result"])
        self.assertEqual(True, data["revisable"])

        doc.revise("b")
        data = self.get("/api/object/%d/is_revisable/" % doc.id)
        self.assertEqual("ok", data["result"])
        self.assertEqual(False, data["revisable"])
Esempio n. 43
0
    def test_thumbnails(self):
        # create a document with a file
        doc = DocumentController.create("Doc", "Document", "a", self.user,
                self.DATA)
        thumbnail = ContentFile(file("datatests/thumbnail.png").read())
        thumbnail.name = "Thumbnail.png"
        doc.add_file(self.get_file())
        f2 = doc.files.all()[0]
        doc.add_thumbnail(f2, thumbnail)

        self.assertAjaxErrorGet("/ajax/thumbnails/%s/%s/%s/" % (doc.type, doc.reference,
            doc.revision))