def test_build_barcodes_pdf(self):
        self.assertIn('%PDF-1.', m.build_barcodes_pdf(['000000011']))

        old_get_image = m.get_image

        # replace get_image method to change behaviour.
        def mock_get_image1(barcodes):
            font = join(dirname(realpath(__file__)), '../', 'FreeSans.ttf')
            for b in barcodes:
                yield code128_image(b, height=150, width=300, font=font,
                                    thickness=2, show_text=True,
                                    quiet_zone=False)
        m.get_image = mock_get_image1
        self.assertIn('%PDF-1.', m.build_barcodes_pdf(['000000011']))

        # replace get_image method to change behaviour
        def mock_get_image2(barcodes):
            font = join(dirname(realpath(__file__)), '../', 'FreeSans.ttf')
            for b in barcodes:
                yield code128_image(b, height=150, width=303, font=font,
                                    thickness=2, show_text=True,
                                    quiet_zone=False)
        m.get_image = mock_get_image2
        self.assertRaisesRegexp(AttributeError,
                                "shape",
                                m.build_barcodes_pdf,
                                ['000000011'])
        # reset function
        m.get_image = old_get_image
Example #2
0
    def test_build_barcodes_pdf(self):
        self.assertIn('%PDF-1.4\n%', m.build_barcodes_pdf(['000000011']))

        old_get_image = m.get_image

        # replace get_image method to change behaviour.
        def mock_get_image1(barcodes):
            font = join(dirname(realpath(__file__)), '../', 'FreeSans.ttf')
            for b in barcodes:
                yield code128_image(b, height=150, width=300, font=font,
                                    thickness=2, show_text=True,
                                    quiet_zone=False)
        m.get_image = mock_get_image1
        self.assertIn('%PDF-1.4\n%', m.build_barcodes_pdf(['000000011']))

        # replace get_image method to change behaviour
        def mock_get_image2(barcodes):
            font = join(dirname(realpath(__file__)), '../', 'FreeSans.ttf')
            for b in barcodes:
                yield code128_image(b, height=150, width=303, font=font,
                                    thickness=2, show_text=True,
                                    quiet_zone=False)
        m.get_image = mock_get_image2
        self.assertRaisesRegexp(AttributeError,
                                "shape",
                                m.build_barcodes_pdf,
                                ['000000011'])
        # reset function
        m.get_image = old_get_image
Example #3
0
 def test_tmpdir(self):
     # test that a temporary directory cannot collide with an existing one
     random.seed(7)
     fake_tmp_dir = 'tmp_IDQBN'
     if not path.exists(fake_tmp_dir):
         mkdir(fake_tmp_dir)
     self.assertTrue(m.build_barcodes_pdf(['000000011']))
 def test_tmpdir(self):
     # test that a temporary directory cannot collide with an existing one
     random.seed(7)
     fake_tmp_dir = 'tmp_IDQBN'
     if not path.exists(fake_tmp_dir):
         mkdir(fake_tmp_dir)
     self.assertTrue(m.build_barcodes_pdf(['000000011']))
Example #5
0
 def post(self):
     barcodes = self.get_argument('barcodes').split(",")
     pdf = build_barcodes_pdf(barcodes)
     self.add_header('Content-type',  'application/pdf')
     self.add_header('Content-Transfer-Encoding', 'binary')
     self.add_header('Accept-Ranges', 'bytes')
     self.add_header('Content-Encoding', 'none')
     self.add_header('Content-Disposition', 'attachment; filename=barcodes.pdf')
     self.write(pdf)
     self.flush()
     self.finish()
 def post(self):
     barcodes = self.get_argument('barcodes').split(",")
     pdf = build_barcodes_pdf(barcodes)
     self.add_header('Content-type', 'application/pdf')
     self.add_header('Content-Transfer-Encoding', 'binary')
     self.add_header('Accept-Ranges', 'bytes')
     self.add_header('Content-Encoding', 'none')
     self.add_header('Content-Disposition',
                     'attachment; filename=barcodes.pdf')
     self.write(pdf)
     self.flush()
     self.finish()
Example #7
0
    def test_build_barcodes_pdf_two_pages(self):
        pdf = m.build_barcodes_pdf(['000000011'] * 72)

        self.assertTrue(TWO_PAGES_HEADER in pdf)
Example #8
0
    def test_build_barcodes_pdf_one_page(self):
        pdf = m.build_barcodes_pdf(['000000011'] * 36)

        self.assertTrue(ONE_PAGE_HEADER in pdf)
    def test_build_barcodes_pdf_two_pages(self):
        pdf = m.build_barcodes_pdf(['000000011'] * 72)

        self.assertTrue(TWO_PAGES_HEADER in pdf)
    def test_build_barcodes_pdf_one_page(self):
        pdf = m.build_barcodes_pdf(['000000011'] * 36)

        self.assertTrue(ONE_PAGE_HEADER in pdf)