def test_get_options_from_storage(self): image_url = "/some/image.jpg" custom_security_key = "custom-sec" cryptor = Cryptor(security_key=custom_security_key) decryptor = Cryptor(security_key="something") expected_options = dict( width=300, height=300, smart=True, adaptive=False, full=False, fit_in=False, flip_horizontal=True, flip_vertical=True, halign="center", valign="middle", trim=True, crop_left=10, crop_top=11, crop_right=12, crop_bottom=13, filters='some_filter()', image=image_url, ) encrypted_str = cryptor.encrypt(**expected_options) mock_storage = mock.Mock() decryptor.context = mock.Mock( config=mock.Mock( STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True ), modules=mock.Mock( storage=mock_storage ), ) mock_storage.get_crypto.return_value = custom_security_key options = decryptor.get_options(encrypted_str, image_url) expect(options).not_to_be_null() expected_options = { 'trim': 'trim', 'full': False, 'halign': 'center', 'fit_in': False, 'vertical_flip': True, 'image': '/some/image.jpg', 'crop': {'top': 11, 'right': 12, 'bottom': 13, 'left': 10}, 'height': 300, 'width': 300, 'meta': False, 'horizontal_flip': True, 'filters': 'some_filter()', 'valign': 'middle', 'debug': False, 'hash': 'e2baf424fa420b73a97476956dfb858f', 'adaptive': False, 'smart': True } expect(options).to_be_like(expected_options)
def test_get_options_from_storage_returns_null_if_key_not_found(self): image_url = "/some/image.jpg" custom_security_key = "custom-sec" cryptor = Cryptor(security_key=custom_security_key) decryptor = Cryptor(security_key="something") expected_options = dict( width=300, height=300, smart=True, adaptive=False, full=False, fit_in=False, flip_horizontal=True, flip_vertical=True, halign="center", valign="middle", trim=True, crop_left=10, crop_top=11, crop_right=12, crop_bottom=13, filters='some_filter()', image=image_url, ) encrypted_str = cryptor.encrypt(**expected_options) mock_storage = mock.Mock() decryptor.context = mock.Mock( config=mock.Mock( STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True ), modules=mock.Mock( storage=mock_storage ), ) mock_storage.get_crypto.return_value = None options = decryptor.get_options(encrypted_str, image_url) expect(options).to_be_null()
def test_get_options_from_storage_returns_null_if_key_not_found(self): image_url = "/some/image.jpg" custom_security_key = "custom-sec" cryptor = Cryptor(security_key=custom_security_key) decryptor = Cryptor(security_key="something") expected_options = dict( width=300, height=300, smart=True, adaptive=False, full=False, fit_in=False, flip_horizontal=True, flip_vertical=True, halign="center", valign="middle", trim=True, crop_left=10, crop_top=11, crop_right=12, crop_bottom=13, filters='some_filter()', image=image_url, ) encrypted_str = cryptor.encrypt(**expected_options) mock_storage = mock.Mock() decryptor.context = mock.Mock( config=mock.Mock(STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True), modules=mock.Mock(storage=mock_storage), ) mock_storage.get_crypto.return_value = None options = decryptor.get_options(encrypted_str, image_url) expect(options).to_be_null()
def test_get_options_from_storage(self): image_url = "/some/image.jpg" custom_security_key = "custom-sec" cryptor = Cryptor(security_key=custom_security_key) decryptor = Cryptor(security_key="something") expected_options = dict( width=300, height=300, smart=True, adaptive=False, full=False, fit_in=False, flip_horizontal=True, flip_vertical=True, halign="center", valign="middle", trim=True, crop_left=10, crop_top=11, crop_right=12, crop_bottom=13, filters='some_filter()', image=image_url, ) encrypted_str = cryptor.encrypt(**expected_options) mock_storage = mock.Mock() decryptor.context = mock.Mock( config=mock.Mock(STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True), modules=mock.Mock(storage=mock_storage), ) mock_storage.get_crypto.return_value = custom_security_key options = decryptor.get_options(encrypted_str, image_url) expect(options).not_to_be_null() expected_options = { 'trim': 'trim', 'full': False, 'halign': 'center', 'fit_in': False, 'vertical_flip': True, 'image': '/some/image.jpg', 'crop': { 'top': 11, 'right': 12, 'bottom': 13, 'left': 10 }, 'height': 300, 'width': 300, 'meta': False, 'horizontal_flip': True, 'filters': 'some_filter()', 'valign': 'middle', 'debug': False, 'hash': 'e2baf424fa420b73a97476956dfb858f', 'adaptive': False, 'smart': True } expect(options).to_be_like(expected_options)