Exemple #1
0
 def test_make_permalink(self):
     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['uploaded']), dju_settings.DJU_IMG_UPLOAD_MAX_FILES)
     self.assertEqual(len(d['errors']), 0)
     self.assertUploadedFilesExist(d)
     for item in d['uploaded']:
         new_img_id = make_permalink(item['img_id'])
         files = get_files_by_img_id(new_img_id)
         self.assertEqual(files['main'], remove_tmp_prefix_from_file_path(item['rel_url']))
         new_item = {
             'rel_url': files['main'],
             'variants': {},
         }
         for var_label, var_data in item['variants'].iteritems():
             self.assertEqual(
                 files['variants'][var_label],
                 remove_tmp_prefix_from_file_path(var_data['rel_url'])
             )
             new_item['variants'][var_label] = {'rel_url': files['variants'][var_label]}
         self.assertUploadedFilesExist({'uploaded': [new_item]})
    def test_remove_old_tmp_files(self, ):
        fn = save_img_file('t1.jpeg', create_test_image(600, 600))
        with patch_utcnow(-datetime.timedelta(hours=10)):
            upload_from_fs(fn, profile='simple1')
        with patch_utcnow(-datetime.timedelta(hours=11)):
            make_permalink(upload_from_fs(fn, profile='simple0'))

        with patch_utcnow():
            deleted, total = remove_old_tmp_files(['simple1'], max_lifetime=12)
            self.assertEqual((deleted, total), (0, 5))

            deleted, total = remove_old_tmp_files(max_lifetime=12)
            self.assertEqual((deleted, total), (0, 5))

            deleted, total = remove_old_tmp_files(['simple1'], max_lifetime=9)
            self.assertEqual((deleted, total), (5, 5))
Exemple #3
0
 def test_make_permalink(self):
     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['uploaded']),
                      dju_settings.DJU_IMG_UPLOAD_MAX_FILES)
     self.assertEqual(len(d['errors']), 0)
     self.assertUploadedFilesExist(d)
     for item in d['uploaded']:
         new_img_id = make_permalink(item['img_id'])
         files = get_files_by_img_id(new_img_id)
         self.assertEqual(files['main'],
                          remove_tmp_prefix_from_file_path(item['rel_url']))
         new_item = {
             'rel_url': files['main'],
             'variants': {},
         }
         for var_label, var_data in item['variants'].iteritems():
             self.assertEqual(
                 files['variants'][var_label],
                 remove_tmp_prefix_from_file_path(var_data['rel_url']))
             new_item['variants'][var_label] = {
                 'rel_url': files['variants'][var_label]
             }
         self.assertUploadedFilesExist({'uploaded': [new_item]})