Beispiel #1
0
    def test_post_view_of_thumbnails_files_accessible(self):
        from pdfexploder.views import ThumbnailViews

        pdf_name = "resources/known_unittest.pdf"
        pdf_file = DeformMockFieldStorage(pdf_name)
        pdf_upload_dict = {"upload": pdf_file}

        post_dict = {
            "submit": "submit",
            "serial": "UT1234",
            "pdf_upload": pdf_upload_dict
        }
        request = testing.DummyRequest(post_dict)
        inst = ThumbnailViews(request)
        result = inst.generate_thumbnails()

        request = testing.DummyRequest()
        request.matchdict["serial"] = "UT1234"
        inst = ThumbnailViews(request)

        result = inst.top_thumbnail()
        img_size = result.content_length
        self.assertTrue(size_range(img_size, 105238, ok_range=5000))

        # Mosaic has randomization
        result = inst.mosaic_thumbnail()
        img_size = result.content_length
        self.assertTrue(size_range(img_size, 21000, ok_range=2000))
Beispiel #2
0
 def test_mosaic_thumbnail_from_blob(self):
     filename = "resources/known_unittest.pdf"
     pdf_file = open(filename)
     thumb = ThumbnailGenerator(blob=pdf_file.read())
     png_img = thumb.mosaic_thumbnail()
     # Image has randomized components
     self.assertTrue(size_range(len(png_img), 21000, ok_range=2000))
Beispiel #3
0
    def test_submit_with_all_values_image_links_available(self):
        res = self.testapp.get("/")
        form = res.forms["deform"]
        form["serial"] = "ft789"
        form.set("upload", Upload("resources/known_unittest.pdf"), 0)
        submit_res = form.submit("submit")

        top_link = "src=\"/top/ft789"
        self.assertTrue(top_link in submit_res.body)

        res = self.testapp.get("/top/ft789")
        img_size = res.content_length
        self.assertTrue(size_range(img_size, 105238, ok_range=5000))

        mosaic_link = "src=\"/mosaic/ft789"
        self.assertTrue(mosaic_link in submit_res.body)

        res = self.testapp.get("/mosaic/ft789")
        img_size = res.content_length
        self.assertTrue(size_range(img_size, 21000, ok_range=4000))
Beispiel #4
0
 def test_mosaic_thumbnail_from_pdf(self):
     filename = "resources/known_unittest.pdf"
     thumg = ThumbnailGenerator(filename)
     png_img = thumg.mosaic_thumbnail()
     # Image has randomized components
     self.assertTrue(size_range(len(png_img), 21000, ok_range=2000))
Beispiel #5
0
 def test_top_page_thumbnail_from_pdf(self):
     filename = "resources/known_unittest.pdf"
     thumg = ThumbnailGenerator(filename)
     png_img = thumg.top_thumbnail()
     img_size = len(png_img)
     self.assertTrue(size_range(img_size, 105238, ok_range=5000))