Exemple #1
0
    def setUp(self):
        super(ArchiveViewTestCase, self).setUp()
        self.document = DocumentController.create('doc1', 'Document',
                'a', self.user, self.DATA)
        self.filenames = []
        self.contents = {}
        for i in range(5):
            name = "file_%d.test" % i
            content = "content_%d" % i
            self.filenames.append(name)
            self.contents[name] = content
            self.document.add_file(self.get_file(name, content))
       
        # add another file named "file_4.test"
        self.filenames.append("file_4_1.test")
        self.contents["file_4_1.test"] = content
        self.document.add_file(self.get_file(name, content))
        
        # create another document
        self.document_bis = DocumentController.create('doc2', 'Document',
                'a', self.user, self.DATA)
        self.file_bis = "file_bis.test"
        self.document_bis.add_file(self.get_file(self.file_bis, "file_bis"))
        self.contents[self.file_bis] = "file_bis"

        self.controller.attach_to_document(self.document)
        self.controller.attach_to_document(self.document_bis)
Exemple #2
0
    def setUp(self):
        super(ArchiveViewTestCase, self).setUp()
        self.document = DocumentController.create('doc1', 'Document', 'a',
                                                  self.user, self.DATA)
        self.filenames = []
        self.contents = {}
        for i in range(5):
            name = "file_%d.test" % i
            content = "content_%d" % i
            self.filenames.append(name)
            self.contents[name] = content
            self.document.add_file(self.get_file(name, content))

        # add another file named "file_4.test"
        self.filenames.append("file_4_1.test")
        self.contents["file_4_1.test"] = content
        self.document.add_file(self.get_file(name, content))

        # create another document
        self.document_bis = DocumentController.create('doc2', 'Document', 'a',
                                                      self.user, self.DATA)
        self.file_bis = "file_bis.test"
        self.document_bis.add_file(self.get_file(self.file_bis, "file_bis"))
        self.contents[self.file_bis] = "file_bis"

        self.controller.attach_to_document(self.document)
        self.controller.attach_to_document(self.document_bis)
Exemple #3
0
 def test_can_attach_attached(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     self.controller.attach_to_document(doc)
     data = self.get("/ajax/can_attach/%d/" % self.controller.id,
             type=doc.type, reference=doc.reference, revision=doc.revision)
     self.assertFalse(data["can_attach"])
Exemple #4
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()])
Exemple #5
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"]])
Exemple #6
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)
Exemple #7
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)
Exemple #8
0
 def test_can_attach_doc_part(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.get("/ajax/can_attach/%d/" % doc.id,
             type=self.controller.type, reference=self.controller.reference,
             revision=self.controller.revision)
     self.assertTrue(data["can_attach"])
Exemple #9
0
 def test_can_add_child_document(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
                                     self.DATA)
     data = self.get("/ajax/can_add_child/%d/" % self.controller.id,
                     type=doc.type,
                     reference=doc.reference,
                     revision=doc.revision)
     self.assertFalse(data["can_add"])
Exemple #10
0
 def test_can_attach_doc_part(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
                                     self.DATA)
     data = self.get("/ajax/can_attach/%d/" % doc.id,
                     type=self.controller.type,
                     reference=self.controller.reference,
                     revision=self.controller.revision)
     self.assertTrue(data["can_attach"])
Exemple #11
0
 def test_attach_doc_part_post_error(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     self.controller.attach_to_document(doc)
     data = self.post("/ajax/attach/%d/" % doc.id,
             type=self.controller.type, reference=self.controller.reference,
             revision=self.controller.revision)
     self.assertEqual("error", data["result"])
Exemple #12
0
 def test_attach_part_doc_post(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.post("/ajax/attach/%d/" % self.controller.id,
             type=doc.type, reference=doc.reference, revision=doc.revision)
     self.assertEqual("ok", data["result"])
     link = self.controller.get_attached_documents()[0]
     self.assertEqual(doc.id, link.document.id)
Exemple #13
0
 def test_can_attach_doc_doc(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
                                     self.DATA)
     data = self.post("/ajax/can_attach/%d/" % doc.id,
                      type=doc.type,
                      reference=doc.reference,
                      revision=doc.revision)
     self.assertFalse(data["can_attach"])
Exemple #14
0
 def test_can_attach_attached(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
                                     self.DATA)
     self.controller.attach_to_document(doc)
     data = self.get("/ajax/can_attach/%d/" % self.controller.id,
                     type=doc.type,
                     reference=doc.reference,
                     revision=doc.revision)
     self.assertFalse(data["can_attach"])
Exemple #15
0
 def test_checkin(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     df = doc.add_file(self.get_file())
     mock_file = self.get_file(data="robert")
     data = self.post("/api/object/%d/checkin/%d/" % (doc.id, df.id), 
             filename=mock_file)
     self.assertEqual("ok", data["result"])
     self.assertEqual("robert", doc.files[0].file.read())
Exemple #16
0
 def test_attach_doc_part_post_error(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
                                     self.DATA)
     self.controller.attach_to_document(doc)
     data = self.post("/ajax/attach/%d/" % doc.id,
                      type=self.controller.type,
                      reference=self.controller.reference,
                      revision=self.controller.revision)
     self.assertEqual("error", data["result"])
Exemple #17
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)
Exemple #18
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"])
Exemple #19
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"])
Exemple #20
0
 def test_attach_doc_part_post(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
                                     self.DATA)
     data = self.post("/ajax/attach/%d/" % doc.id,
                      type=self.controller.type,
                      reference=self.controller.reference,
                      revision=self.controller.revision)
     self.assertEqual("ok", data["result"])
     link = self.controller.get_attached_documents()[0]
     self.assertEqual(doc.id, link.document.id)
Exemple #21
0
 def test_attach_get(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.get("/ajax/attach/%d/" % self.controller.id,
             type=doc.type, reference=doc.reference, revision=doc.revision)
     plmobject = data["plmobject"]
     self.assertEqual(self.controller.id, plmobject["id"])
     self.assertEqual(self.controller.type, plmobject["type"])
     self.assertEqual(self.controller.reference, plmobject["reference"])
     self.assertEqual(self.controller.revision, plmobject["revision"])
     self.assertTrue("form" in data)
Exemple #22
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"])
Exemple #23
0
 def test_attach_get(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
                                     self.DATA)
     data = self.get("/ajax/attach/%d/" % self.controller.id,
                     type=doc.type,
                     reference=doc.reference,
                     revision=doc.revision)
     plmobject = data["plmobject"]
     self.assertEqual(self.controller.id, plmobject["id"])
     self.assertEqual(self.controller.type, plmobject["type"])
     self.assertEqual(self.controller.reference, plmobject["reference"])
     self.assertEqual(self.controller.revision, plmobject["revision"])
     self.assertTrue("form" in data)
Exemple #24
0
    def test_search_with_file_only(self):
        doc = DocumentController.create("Doc", "Document", "a", self.user,
                self.DATA)
        data = self.get("/api/search/true/true/", type="Document")
        self.assertEqual("ok", data["result"])
        self.assertEqual(0, len(data["objects"]))

        doc.add_file(self.get_file())
        data = self.get("/api/search/true/true/", type="Document")
        self.assertEqual("ok", data["result"])
        self.assertEqual(1, len(data["objects"]))
        
        d = data["objects"][0]
        self.assertEqual(doc.name, d["name"])
        self.assertEqual(doc.id, d["id"])
        self.assertEqual(doc.revision, d["revision"])
Exemple #25
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)

        data = self.get("/ajax/thumbnails/%s/%s/%s/" % (doc.type, doc.reference,
            doc.revision))
        files = data["files"]
        self.assertEqual(1, len(files))
        # download the file and the thumbnail
        response_file = self.client.get(files[0]["url"])
        self.assertEqual(response_file.status_code, 200)
        response_img = self.client.get(files[0]["img"])
        self.assertEqual(response_img.status_code, 200)
Exemple #26
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)

        data = self.get("/ajax/thumbnails/%s/%s/%s/" %
                        (doc.type, doc.reference, doc.revision))
        files = data["files"]
        self.assertEqual(1, len(files))
        # download the file and the thumbnail
        response_file = self.client.get(files[0]["url"])
        self.assertEqual(response_file.status_code, 200)
        response_img = self.client.get(files[0]["img"])
        self.assertEqual(response_img.status_code, 200)
Exemple #27
0
 def test_can_add_child_document(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.get("/ajax/can_add_child/%d/" % self.controller.id,
             type=doc.type, reference=doc.reference, revision=doc.revision)
     self.assertFalse(data["can_add"])
Exemple #28
0
 def test_add_file_error_missing_file(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.post("/api/object/%d/add_file/" % doc.id)
     self.assertEqual("error", data["result"])
     self.assertFalse(doc.files)
Exemple #29
0
 def test_get_files_empty(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.get("/api/object/%d/files/" % doc.id)
     self.assertEqual("ok", data["result"])
     self.assertEqual([], data["files"])
Exemple #30
0
 def test_revise_error_missing_revision(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.post("/api/object/%d/revise/" % doc.id)
     self.assertEqual("error", data["result"])
Exemple #31
0
 def test_next_revision(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.get("/api/object/%d/next_revision/" % doc.id)
     self.assertEqual("ok", data["result"])
     self.assertEqual("b", data["revision"])
 def setUp(self):
     super(DocNativeTestCase, self).setUp()
     self.document = DocumentController.create('doc1', 'Document', 'a',
                                               self.user, self.DATA)
 def setUp(self):
     super(DocNativeTestCase, self).setUp()
     self.document = DocumentController.create('doc1', 'Document',
             'a', self.user, self.DATA)
Exemple #34
0
 def test_can_attach_doc_doc(self):
     doc = DocumentController.create("Doc", "Document", "a", self.user,
             self.DATA)
     data = self.post("/ajax/can_attach/%d/" % doc.id,
             type=doc.type, reference=doc.reference, revision=doc.revision)
     self.assertFalse(data["can_attach"])