Ejemplo n.º 1
0
 def test_should_give_404_if_resize_fails(self):
     def mock_resize(source_file, target_file, width, height):
         raise Exception
         
     imagemagick.resize = mock_resize
     
     views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)
Ejemplo n.º 2
0
    def test_should_give_404_if_resize_fails(self):
        def mock_resize(source_file, target_file, width, height):
            raise Exception

        imagemagick.resize = mock_resize

        views.resize_image(None, self.file_name_without_extension, self.width,
                           self.height, self.file_extension)
Ejemplo n.º 3
0
 def test_should_be_case_sensitive(self):
     result = views.resize_image(None, "Case", self.width, self.height, ".PNG")
     (_, source_file_name) = os.path.split(result['source_file'])
     (_, target_file_name) = os.path.split(result['target_file'])
     
     self.assertEquals("Case.PNG", source_file_name)
     self.assertEquals("Case.100x200.PNG", target_file_name)
Ejemplo n.º 4
0
    def test_should_be_case_sensitive(self):
        result = views.resize_image(None, "Case", self.width, self.height,
                                    ".PNG")
        (_, source_file_name) = os.path.split(result['source_file'])
        (_, target_file_name) = os.path.split(result['target_file'])

        self.assertEquals("Case.PNG", source_file_name)
        self.assertEquals("Case.100x200.PNG", target_file_name)
Ejemplo n.º 5
0
    def test_file_names_of_source_and_resized_image_should_be_the_same_except_for_the_size(
            self):
        result = views.resize_image(None, self.file_name_without_extension,
                                    self.width, self.height,
                                    self.file_extension)
        (_, source_file) = os.path.split(result['source_file'])
        (_, target_file) = os.path.split(result['target_file'])

        self.assertEquals(source_file.split('.')[0], target_file.split('.')[0])
Ejemplo n.º 6
0
 def test_the_paths_of_source_and_resized_image_should_be_the_same_except_for_their_root_path(self):
     self.old_media_cache_root = settings.MEDIA_CACHE_ROOT
     
     try:
         settings.MEDIA_CACHE_ROOT = settings.MEDIA_ROOT 
         result = views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)
         (source_path, _) = os.path.split(result['source_file'])
         (target_path, _) = os.path.split(result['target_file'])
     
         self.assertEquals(source_path, target_path)
     
     finally:
         settings.MEDIA_CACHE_ROOT = self.old_media_cache_root
Ejemplo n.º 7
0
    def test_the_paths_of_source_and_resized_image_should_be_the_same_except_for_their_root_path(
            self):
        self.old_media_cache_root = settings.MEDIA_CACHE_ROOT

        try:
            settings.MEDIA_CACHE_ROOT = settings.MEDIA_ROOT
            result = views.resize_image(None, self.file_name_without_extension,
                                        self.width, self.height,
                                        self.file_extension)
            (source_path, _) = os.path.split(result['source_file'])
            (target_path, _) = os.path.split(result['target_file'])

            self.assertEquals(source_path, target_path)

        finally:
            settings.MEDIA_CACHE_ROOT = self.old_media_cache_root
Ejemplo n.º 8
0
 def test_should_support_images_without_file_extension(self):
     result = views.resize_image(None, self.file_name_without_extension, self.width, self.height, "")
     (_, file_name) = os.path.split(result['target_file'])
     self.assertEquals("hello.100x200", file_name)
Ejemplo n.º 9
0
 def test_should_append_image_size_to_resized_image(self):
     result = views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)
     (_, file_name) = os.path.split(result['target_file'])
     self.assertEquals("hello.100x200.png", file_name)
Ejemplo n.º 10
0
 def test_file_names_of_source_and_resized_image_should_be_the_same_except_for_the_size(self):
     result = views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)
     (_, source_file) = os.path.split(result['source_file'])
     (_, target_file) = os.path.split(result['target_file'])
 
     self.assertEquals(source_file.split('.')[0], target_file.split('.')[0])
Ejemplo n.º 11
0
 def test_should_store_resized_image_under_cached_media_root(self):
     result = views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)
     self.assertTrue(result['target_file'].startswith(settings.MEDIA_CACHE_ROOT))
Ejemplo n.º 12
0
 def test_should_fetch_source_image_from_media_root(self):
     result = views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)
     self.assertTrue(result['target_file'].startswith(settings.MEDIA_ROOT))
Ejemplo n.º 13
0
 def test_should_fetch_source_image_from_media_root(self):
     result = views.resize_image(None, self.file_name_without_extension,
                                 self.width, self.height,
                                 self.file_extension)
     self.assertTrue(result['target_file'].startswith(settings.MEDIA_ROOT))
Ejemplo n.º 14
0
 def test_should_store_resized_image_under_cached_media_root(self):
     result = views.resize_image(None, self.file_name_without_extension,
                                 self.width, self.height,
                                 self.file_extension)
     self.assertTrue(result['target_file'].startswith(
         settings.MEDIA_CACHE_ROOT))
Ejemplo n.º 15
0
 def test_should_render_resized_image_to_http_response(self):
     result = views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)
     self.assertTrue(result['rendered_to_http_response'])
Ejemplo n.º 16
0
 def test_should_render_resized_image_to_http_response(self):
     result = views.resize_image(None, self.file_name_without_extension,
                                 self.width, self.height,
                                 self.file_extension)
     self.assertTrue(result['rendered_to_http_response'])
Ejemplo n.º 17
0
 def test_should_support_images_without_file_extension(self):
     result = views.resize_image(None, self.file_name_without_extension,
                                 self.width, self.height, "")
     (_, file_name) = os.path.split(result['target_file'])
     self.assertEquals("hello.100x200", file_name)
Ejemplo n.º 18
0
 def test_should_append_image_size_to_resized_image(self):
     result = views.resize_image(None, self.file_name_without_extension,
                                 self.width, self.height,
                                 self.file_extension)
     (_, file_name) = os.path.split(result['target_file'])
     self.assertEquals("hello.100x200.png", file_name)
Ejemplo n.º 19
0
 def test_should_limit_maximum_width(self):
     self.width = settings.RESIZE_MAX_WIDTH + 1;
     views.resize_image(None, self.file_name_without_extension, self.width, self.height, self.file_extension)   
Ejemplo n.º 20
0
 def test_should_limit_maximum_width(self):
     self.width = settings.RESIZE_MAX_WIDTH + 1
     views.resize_image(None, self.file_name_without_extension, self.width,
                        self.height, self.file_extension)