Exemplo n.º 1
0
 def test_rf_task(self):
     rf = RawFile()
     rf.file = self.uploadFile('test.png')
     rf.save()
     rf.task()
     rf = RawFile.objects.get(id=rf.id)
     self.assertEqual(rf.mhash,
                      UUID('5abd147d-ceb8-218a-a160-1c7821db6654'))
Exemplo n.º 2
0
    def test_task(self):
        rf = RawFile()
        rf.file = self.uploadFile('test.png')
        rf.save()
        rf.task()
        rf = RawFile.objects.get(id=rf.id)
        saved = RawFile.objects.first()
        self.assertEqual(rf, saved)

        self.assertNotEqual(rf.mhash, None)
        self.assertEqual(rf.same, None)

        self.assertEqual(saved.mhash, rf.mhash)
        self.assertEqual(saved.same, rf.same)

        rf2 = RawFile()
        rf2.file = self.uploadFile('test.jpg')
        rf2.save()
        rf2.task()
        rf2 = RawFile.objects.get(id=rf2.id)
        self.assertEqual(rf.same, None)
        self.assertEqual(rf2.same, None)

        rf3 = RawFile()
        rf3.file = self.uploadFile('test.png')
        rf3.save()
        rf3_old_file_path = rf3.file.path
        rf3.task()
        rf3 = RawFile.objects.get(id=rf3.id)
        self.assertEqual(rf3.file.path, rf3_old_file_path)
        self.assertEqual(rf.same, None)
        self.assertEqual(rf2.same, None)
        self.assertEqual(rf3.same, rf)
        self.assertEqual(rf.sames.count(), 1)
        self.assertEqual(rf.sames.first(), rf3)

        f = Path(rf.file.path)
        f2 = Path(rf2.file.path)
        f3 = Path(rf3.file.path)
        self.assertEqual(f.is_symlink(), False)
        self.assertEqual(f2.is_symlink(), False)
        self.assertEqual(f3.is_symlink(), True)

        rf.task()
        rf2.task()
        f = Path(rf.file.path)
        f2 = Path(rf2.file.path)
        f3 = Path(rf3.file.path)
        self.assertEqual(f.is_symlink(), False)
        self.assertEqual(f2.is_symlink(), False)
        self.assertEqual(f3.is_symlink(), True)

        rf4 = RawFile()
        rf4.file = self.uploadFile('test_org.jpg')
        rf4.save()
        self.assertEqual(rf4.mhash, None)
        pil4_1 = PIL_Image.open(rf4.file.path)
        self.assertEqual(pil4_1.size, (4160, 2340))
        rf4.task()
        self.assertEqual(rf4.mhash, UUID('f34bb180-a108-e20f-4167-2b734c497f0f'))
        pil4_2 = PIL_Image.open(rf4.file.path)
        self.assertEqual(pil4_2.size, (1280, 720))

        rf4.task()
        self.assertEqual(rf4.mhash, UUID('f34bb180-a108-e20f-4167-2b734c497f0f'))
        pil4_3 = PIL_Image.open(rf4.file.path)
        self.assertEqual(pil4_3.size, (1280, 720))