コード例 #1
0
 def test_get_helpers__queryset(self):
     preadjust = Preadjust()
     qs = AdjustedImage.objects.all()
     dp = ((qs, [Fit(width=50)], 'storage_path'),)
     with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
         helpers = preadjust._get_helpers()
     self.assertEqual(len(helpers), 1)
     self.assertTrue(qs._result_cache is None)
コード例 #2
0
 def test_get_helpers__queryset(self):
     preadjust = Preadjust()
     qs = AdjustedImage.objects.all()
     dp = ((qs, [Fit(width=50)], 'storage_path'), )
     with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
         helpers = preadjust._get_helpers()
     self.assertEqual(len(helpers), 1)
     self.assertTrue(qs._result_cache is None)
コード例 #3
0
    def test_get_helpers__iterable(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        adjusted = AdjustedImage.objects.create(storage_path=storage_path,
                                                adjusted=storage_path)

        def _iter():
            yield adjusted

        dp = ((_iter(), [Fit(width=50)], 'storage_path'), )

        with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
            helpers = preadjust._get_helpers()
        self.assertEqual(len(helpers), 1)
コード例 #4
0
    def test_get_helpers__iterable(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        adjusted = AdjustedImage.objects.create(storage_path=storage_path,
                                                adjusted=storage_path)

        def _iter():
            yield adjusted

        dp = ((_iter(), [Fit(width=50)], 'storage_path'),)

        with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
            helpers = preadjust._get_helpers()
        self.assertEqual(len(helpers), 1)
コード例 #5
0
    def test_preadjust__empty(self):
        preadjust = Preadjust()
        storage_path = 'does_not_exist.png'
        AdjustedImage.objects.create(storage_path=storage_path,
                                     adjusted=storage_path)
        self.assertEqual(AdjustedImage.objects.count(), 1)

        preadjust.stdout = mock.MagicMock()
        preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 1 empty path.\n'),
            mock.call('Skipped 0 paths which have already been adjusted.\n'),
            mock.call('No paths remaining to adjust.\n'),
        ])

        self.assertEqual(AdjustedImage.objects.count(), 1)
コード例 #6
0
    def test_preadjust__empty(self):
        preadjust = Preadjust()
        storage_path = 'does_not_exist.png'
        AdjustedImage.objects.create(storage_path=storage_path,
                                     adjusted=storage_path)
        self.assertEqual(AdjustedImage.objects.count(), 1)

        preadjust.stdout = mock.MagicMock()
        preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 1 empty path.\n'),
            mock.call('Skipped 0 paths which have already been adjusted.\n'),
            mock.call('No paths remaining to adjust.\n'),
        ])

        self.assertEqual(AdjustedImage.objects.count(), 1)
コード例 #7
0
    def test_preadjust__skipped(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        AdjustedImage.objects.create(storage_path=storage_path,
                                     adjusted=storage_path,
                                     requested='fit|50|')
        self.assertEqual(AdjustedImage.objects.count(), 1)

        preadjust.stdout = mock.MagicMock()
        preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 0 empty paths.\n'),
            mock.call('Skipped 1 path which has already been adjusted.\n'),
            mock.call('No paths remaining to adjust.\n'),
        ])

        self.assertEqual(AdjustedImage.objects.count(), 1)
コード例 #8
0
    def test_preadjust__skipped(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        AdjustedImage.objects.create(storage_path=storage_path,
                                     adjusted=storage_path,
                                     requested='fit|50|')
        self.assertEqual(AdjustedImage.objects.count(), 1)

        preadjust.stdout = mock.MagicMock()
        preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 0 empty paths.\n'),
            mock.call('Skipped 1 path which has already been adjusted.\n'),
            mock.call('No paths remaining to adjust.\n'),
        ])

        self.assertEqual(AdjustedImage.objects.count(), 1)
コード例 #9
0
    def test_preadjust__generate(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        self.assertEqual(AdjustedImage.objects.count(), 0)

        preadjust.stdout = mock.MagicMock()

        dp = (([storage_path], [Fit(width=50)], None), )
        with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
            preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 0 empty paths.\n'),
            mock.call('Skipped 0 paths which have already been adjusted.\n'),
            mock.call('Adjusting 1 path... '),
            mock.call('Done.\n'),
        ])

        self.assertEqual(AdjustedImage.objects.count(), 1)
コード例 #10
0
    def test_preadjust__generate(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        self.assertEqual(AdjustedImage.objects.count(), 0)

        preadjust.stdout = mock.MagicMock()

        dp = (([storage_path], [Fit(width=50)], None),)
        with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
            preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 0 empty paths.\n'),
            mock.call('Skipped 0 paths which have already been adjusted.\n'),
            mock.call('Adjusting 1 path... '),
            mock.call('Done.\n'),
        ])

        self.assertEqual(AdjustedImage.objects.count(), 1)
コード例 #11
0
    def test_preadjust__generate__failed(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        self.assertEqual(AdjustedImage.objects.count(), 0)

        preadjust.stdout = mock.MagicMock()

        dp = (([storage_path], [Fit(width=50)], None),)
        with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
            with mock.patch('daguerre.helpers.save_image', side_effect=IOError):
                preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 0 empty paths.\n'),
            mock.call('Skipped 0 paths which have already been adjusted.\n'),
            mock.call('Adjusting 1 path... '),
            mock.call('Done.\n'),
            mock.call('1 path failed due to I/O errors.')
        ])

        self.assertEqual(AdjustedImage.objects.count(), 0)
コード例 #12
0
    def test_preadjust__generate__failed(self):
        preadjust = Preadjust()
        storage_path = self.create_image('100x100.png')
        self.assertEqual(AdjustedImage.objects.count(), 0)

        preadjust.stdout = mock.MagicMock()

        dp = (([storage_path], [Fit(width=50)], None), )
        with override_settings(DAGUERRE_PREADJUSTMENTS=dp):
            with mock.patch('daguerre.helpers.save_image',
                            side_effect=IOError):
                preadjust._preadjust()
        preadjust.stdout.write.assert_has_calls([
            mock.call('Skipped 0 empty paths.\n'),
            mock.call('Skipped 0 paths which have already been adjusted.\n'),
            mock.call('Adjusting 1 path... '),
            mock.call('Done.\n'),
            mock.call('1 path failed due to I/O errors.')
        ])

        self.assertEqual(AdjustedImage.objects.count(), 0)
コード例 #13
0
 def test_get_helpers__model(self):
     preadjust = Preadjust()
     helpers = preadjust._get_helpers()
     self.assertEqual(len(helpers), 1)
コード例 #14
0
 def test_get_helpers__good_string(self):
     preadjust = Preadjust()
     helpers = preadjust._get_helpers()
     self.assertEqual(len(helpers), 1)
コード例 #15
0
 def test_get_helpers__model(self):
     preadjust = Preadjust()
     helpers = preadjust._get_helpers()
     self.assertEqual(len(helpers), 1)
コード例 #16
0
 def test_get_helpers__good_string(self):
     preadjust = Preadjust()
     helpers = preadjust._get_helpers()
     self.assertEqual(len(helpers), 1)