diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-09-19 19:18:00 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-09-19 19:19:07 (GMT) |
commit | 600d3235cda58e6c8a862ececbac1705951879bd (patch) | |
tree | 414f6fca66c5b6bcc949f0a873ef73bc385b6da8 /webapp | |
parent | 1851df5bc6b0bb69e2c4f32bed4643b7d21bc277 (diff) |
Cleaning tmp directory for option images
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/polls/models.py | 30 | ||||
-rw-r--r-- | webapp/polls/tests/structure_tests.py | 26 |
2 files changed, 42 insertions, 14 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py index 2783c67..41d5bdf 100644 --- a/webapp/polls/models.py +++ b/webapp/polls/models.py @@ -1292,28 +1292,30 @@ class Structure(AbstractObject, ComponentStructure): lambda opt: opt.img is not None, valid_img_options) tmp_path = self.get_image_options_tmp_path() + path = self.get_image_options_path() if len(imgs_to_store): if tmp: self.__storing_image_options(tmp_path, imgs_to_store) else: - path = self.get_image_options_path() self.__storing_image_options(path, imgs_to_store) - # Moving tmp images options to the final place for store them - for img_opt in imgs_to_store: - src = '%s/%s' % (tmp_path, img_opt.img_name) - dst = '%s/%s' % (path, img_opt.img_name) - if os.path.exists(src): - shutil.move(src, dst) + if not tmp: + # Moving tmp images options to the final place for store them + for img_opt in valid_img_options: + #for img_opt in imgs_to_store: + src = '%s/%s' % (tmp_path, img_opt.img_name) + dst = '%s/%s' % (path, img_opt.img_name) + if os.path.exists(src): + shutil.move(src, dst) - try: - os.removedirs(tmp_path) - except: - # TODO: tmp must be empty, - # if raise exception here is someting bad - # TODO: LOG! - pass + try: + os.removedirs(tmp_path) + except: + # TODO: tmp must be empty, + # if raise exception here is someting bad + # TODO: LOG! + pass class NodePollResult(object): diff --git a/webapp/polls/tests/structure_tests.py b/webapp/polls/tests/structure_tests.py index 2f793c6..7508248 100644 --- a/webapp/polls/tests/structure_tests.py +++ b/webapp/polls/tests/structure_tests.py @@ -372,5 +372,31 @@ class UploadOptionImagesTest(MongoTestCase): saved_on_disk = os.path.exists(os.path.join(images_dir, img_filename)) self.assertTrue(saved_on_disk) + def test_save_imgs_when_exists_a_valid_structure_with_temp_imgs(self): + option_id = self.option_id + poll = self.poll + data = self.data + data_option = data['groups']['0']['fields']['0']['options'][option_id] + img_filename = self.img_filename + img = self.img + + data_option['img'] = img + structure = Structure(data=data, poll=poll) + structure.save_image_options(tmp=True) + images_tmp_dir = structure.get_image_options_tmp_path() + saved_on_tmp_dir = os.path.exists( + os.path.join(images_tmp_dir, img_filename)) + self.assertTrue(saved_on_tmp_dir) + + data = structure.to_python() + structure = Structure(data=data, poll=poll) + structure.save_image_options(tmp=False) + + images_dir = structure.get_image_options_path() + saved_on_right_place = os.path.exists( + os.path.join(images_dir, img_filename)) + self.assertTrue(saved_on_right_place) + self.assertFalse(os.path.exists(images_tmp_dir)) + def tearDown(self): remove_option_images_dir() |