def test_is_img_id_exists(self): self.assertFalse(is_img_id_exists('default:abcde1234_ab12_myname.jpeg')) r = self.client.post(self.upload_url, { 'images[]': [ get_img_file(create_test_image(1000, 1000)), get_img_file(create_test_image(900, 900)), get_img_file(create_test_image(800, 800)), get_img_file(create_test_image(700, 700)), ], 'profile': 'simple0', 'label': 'world0', }) self.assertEqual(r.status_code, 200) d = self.get_json(r) self.assertEqual(len(d['errors']), 0) self.assertUploadedFilesExist(d) for item in d['uploaded']: self.assertTrue(item['img_id'])
def test_is_img_id_exists(self): self.assertFalse( is_img_id_exists('default:abcde1234_ab12_myname.jpeg')) r = self.client.post( self.upload_url, { 'images[]': [ get_img_file(create_test_image(1000, 1000)), get_img_file(create_test_image(900, 900)), get_img_file(create_test_image(800, 800)), get_img_file(create_test_image(700, 700)), ], 'profile': 'simple0', 'label': 'world0', }) self.assertEqual(r.status_code, 200) d = self.get_json(r) self.assertEqual(len(d['errors']), 0) self.assertUploadedFilesExist(d) for item in d['uploaded']: self.assertTrue(item['img_id'])
remove_all_files_of_img_id(d1['uploaded'][0]['img_id']) self.assertUploadedFilesExist(d2) self.assertUploadedFilesNotExist(d1) remove_all_files_of_img_id(d2['uploaded'][0]['img_id']) self.assertUploadedFilesNotExist(d2) def test_upload_from_fs(self): fn = save_img_file('t1.jpeg', create_test_image(600, 600)) try: img_id = upload_from_fs(fn) except (ValueError, RuntimeError), e: raise self.failureException(e) else: self.assertTrue(is_img_id_valid(img_id)) self.assertTrue(is_img_id_exists(img_id)) with self.assertRaises(ValueError): upload_from_fs('none') fn = save_img_file('t2.jpeg', create_test_image(500, 500)) with self.assertRaises(RuntimeError): upload_from_fs(fn, profile='simple2') fn = save_img_file('t3.jpeg', create_test_image(400, 400)) try: img_id = upload_from_fs(fn, profile='simple1', label='ttt') except (ValueError, RuntimeError), e: raise self.failureException(e) else: self.assertTrue(is_img_id_valid(img_id))