Exemple #1
0
    def test_large_s3_images_should_be_resized(self):
        s3.load()

        maximum_filesize = 100000
        s3_filename = '_test-large-image'

        # Even if resizing is disabled, if its greater than the max filesize we should resize it.
        Config.MAXIMUM_S3_FILESIZE = maximum_filesize
        Config.IMAGE_RESIZE = False

        large_url = 'https://upload.wikimedia.org/wikipedia/commons/6/64/A_massive_dust_storm_blew_through_central_Asia_on_May_7,_2007.jpg'
        response = requests.head(large_url)
        filesize_in_bytes = int(response.headers['content-length'])
        assert filesize_in_bytes > maximum_filesize

        result = s3.put(s3_filename, [large_url], override_existing_file=True)
        assert result

        s3_url = s3.get(s3_filename)
        response = requests.get(s3_url)
        filesize_in_bytes = int(response.headers['content-length'])
        assert filesize_in_bytes < maximum_filesize
Exemple #2
0
    google_spreadsheets,
    piles,
    s3
)
from corji.exceptions import CorgiNotFoundException
import corji.settings as settings
from corji.utils.emoji import (
    emoji_contains_skin_tone,
    text_contains_emoji
)

logger = logging.getLogger(settings.Config.LOGGER_NAME)
google_spreadsheets.load(settings.Config.SPREADSHEET_URL)
piles.load(settings.Config.PILES_URL)
if settings.Config.REMOTE_CACHE_RETRIEVE:
    s3.load()


class CorgiResource(Resource):
    def get(self, emoji=None):
        """Returns an emoji associated with the given emoji.
        If no emoji is supplied, a random corji is returned."""

        if not emoji:
            emoji = random.choice(google_spreadsheets.keys())

        corgi_urls = []

        # Check for skin-toned emojis and fallback to the undecorated one.
        if len(emoji) == 2 and emoji_contains_skin_tone(emoji):
            emoji = emoji[0]