"""Test for Image Location Model.""" import pytest from assets import config from assets.models import image_location @pytest.fixture def fixture_cdn_url(): """Fixture to set CDN Url.""" config.CDN_URL = 'https://fakesite.cloudfront.net' return config.CDN_URL @pytest.fixture def fixture_filename(): """Fixture for a s3 filename.""" return 'product/cover/e10adc3949ba59abbe56e057f20f883e.jpg' def test_get_image_filename(fixture_filename): """Test getting an image filename for a product.""" response = image_location.get_image_filename( entity_id=123456, image_type='product', image_format='cover') assert response == fixture_filename def test_get_image_location_by_filename(fixture_filename, fixture_cdn_url): """Test getting an image location on the cdn for an s3 file.""" response = image_location.get_image_location_by_filename(fixture_filename) assert response.status == 200 assert response.message == '{cdn}/{filename}'.format( cdn=fixture_cdn_url, filename=fixture_filename) def test_get_backend_image_location(fixture_filename): """Test that the expected path is returned.""" result = image_location.get_backend_image_filename( entity_id=123456, image_type='product', image_format='cover') assert result.status == 200 assert result.message == 'images/{}'.format(fixture_filename)