Example #1
0
 def test_should_keep_permissisions_of_source_file(self):
     original_mode = os.stat(self.source).st_mode
     try:
         os.chmod(self.source, original_mode|stat.S_IXUSR)
         imagemagick.resize(self.source, self.target, 320, 200)
         self.assertEquals(os.stat(self.source).st_mode, os.stat(self.target).st_mode)    
     finally:
         os.chmod(self.source, original_mode)
Example #2
0
 def test_should_keep_permissisions_of_source_file(self):
     original_mode = os.stat(self.source).st_mode
     try:
         os.chmod(self.source, original_mode | stat.S_IXUSR)
         imagemagick.resize(self.source, self.target, 320, 200)
         self.assertEquals(
             os.stat(self.source).st_mode,
             os.stat(self.target).st_mode)
     finally:
         os.chmod(self.source, original_mode)
Example #3
0
    def test_should_work_on_temporary_file(self):
        temp_file = self.tmp_dir + "/tempfile.png"
        @contextmanager
        def mock_temp_file(target): 
            yield temp_file
            open(target, 'a').close() # create dummy target

        imagemagick.temp_file = mock_temp_file
        imagemagick.resize(self.source, self.target, 320, 200)
        self.assertTrue(os.path.isfile(temp_file))
Example #4
0
    def test_should_work_on_temporary_file(self):
        temp_file = self.tmp_dir + "/tempfile.png"

        @contextmanager
        def mock_temp_file(target):
            yield temp_file
            open(target, 'a').close()  # create dummy target

        imagemagick.temp_file = mock_temp_file
        imagemagick.resize(self.source, self.target, 320, 200)
        self.assertTrue(os.path.isfile(temp_file))
Example #5
0
 def test_should_match_both_upper_and_lower_cases_when_no_extension_is_provided(self):
     source = settings.TEST_MEDIA_ROOT + "/Case"
     target = self.tmp_dir + "/Case.PNG"
     imagemagick.resize(source, target, 320, 200)
     self.assertTrue(os.path.isfile(target))
Example #6
0
 def test_should_be_case_sensitive(self):
     source = settings.TEST_MEDIA_ROOT + "/Case.PNG"
     target = self.tmp_dir + "/Case.PNG"
     imagemagick.resize(source, target, 320, 200)
     self.assertTrue(os.path.isfile(target))
Example #7
0
 def test_should_raise_exception_if_source_file_is_missing(self):
     imagemagick.resize("missing_file.png", self.target, 320, 200)
Example #8
0
 def test_should_not_resize_file_if_target_already_exists(self):
     imagemagick.resize(self.source, self.target, 320, 200)
     time = os.path.getmtime(self.target)
     imagemagick.resize(self.source, self.target, 320, 200)
     self.assertEquals(time, os.path.getmtime(self.target))
Example #9
0
 def test_should_create_target_path_if_not_exists(self):
     target = self.tmp_dir + "/newdir/target.png"
     imagemagick.resize(self.source, target, 320, 200)
     self.assertTrue(os.path.isfile(target))
Example #10
0
 def test_should_create_a_new_resized_image_on_disk(self):
     imagemagick.resize(self.source, self.target, 320, 200)
     self.assertTrue(os.path.isfile(self.target))
Example #11
0
 def test_should_be_case_sensitive(self):
     source = settings.TEST_MEDIA_ROOT + "/Case.PNG"
     target = self.tmp_dir + "/Case.PNG"
     imagemagick.resize(source, target, 320, 200)
     self.assertTrue(os.path.isfile(target))
Example #12
0
 def test_should_raise_exception_if_source_file_is_missing(self):
     imagemagick.resize("missing_file.png", self.target, 320, 200)
Example #13
0
 def test_should_not_resize_file_if_target_already_exists(self):
     imagemagick.resize(self.source, self.target, 320, 200)
     time = os.path.getmtime(self.target)
     imagemagick.resize(self.source, self.target, 320, 200)
     self.assertEquals(time, os.path.getmtime(self.target))
Example #14
0
 def test_should_create_target_path_if_not_exists(self):
     target = self.tmp_dir + "/newdir/target.png"
     imagemagick.resize(self.source, target, 320, 200)
     self.assertTrue(os.path.isfile(target))
Example #15
0
 def test_should_create_a_new_resized_image_on_disk(self):
     imagemagick.resize(self.source, self.target, 320, 200)
     self.assertTrue(os.path.isfile(self.target))
Example #16
0
 def test_should_match_both_upper_and_lower_cases_when_no_extension_is_provided(
         self):
     source = settings.TEST_MEDIA_ROOT + "/Case"
     target = self.tmp_dir + "/Case.PNG"
     imagemagick.resize(source, target, 320, 200)
     self.assertTrue(os.path.isfile(target))