def test_save_persona_image_not_an_image(self, pngcrush_image_mock): # If the source is not an image, save_persona_image() should just # return early without writing the destination or calling pngcrush. expected_dst = tempfile.NamedTemporaryFile(mode='r+w+b', suffix=".png", delete=False, dir=settings.TMP_PATH) save_persona_image(get_image_path('non-image.png'), expected_dst.name) # pngcrush_image should not have been called. assert pngcrush_image_mock.call_count == 0 # the destination file should not have been written to. assert os.stat(expected_dst.name).st_size == 0
def test_save_persona_image(self, pngcrush_image_mock): # save_persona_image() simply saves an image as a png to the # destination file. The image should be processed with pngcrush. expected_dst = tempfile.NamedTemporaryFile(mode='r+w+b', suffix=".png", delete=False, dir=settings.TMP_PATH) save_persona_image(get_image_path('persona-header.jpg'), expected_dst.name) # pngcrush_image should have been called once. assert pngcrush_image_mock.call_count == 1 assert pngcrush_image_mock.call_args_list[0][0][0] == expected_dst.name
def test_save_persona_image(self, pngcrush_image_mock): # save_persona_image() simply saves an image as a png to the # destination file. The image should be processed with pngcrush. expected_dst = tempfile.NamedTemporaryFile( mode='wb', suffix=".png", delete=False, dir=settings.TMP_PATH) save_persona_image( get_image_path('persona-header.jpg'), expected_dst.name ) # pngcrush_image should have been called once. assert pngcrush_image_mock.call_count == 1 assert pngcrush_image_mock.call_args_list[0][0][0] == expected_dst.name
def test_save_persona_image_not_an_image(self, pngcrush_image_mock): # If the source is not an image, save_persona_image() should just # return early without writing the destination or calling pngcrush. expected_dst = tempfile.NamedTemporaryFile( mode='wb', suffix=".png", delete=False, dir=settings.TMP_PATH) save_persona_image( get_image_path('non-image.png'), expected_dst.name ) # pngcrush_image should not have been called. assert pngcrush_image_mock.call_count == 0 # the destination file should not have been written to. assert os.stat(expected_dst.name).st_size == 0