Example #1
0
def test_adaptive_full_fit_in_fails_if_no_width_supplied():
    with expect.error_to_happen(
        ValueError,
        message="When using fit-in or full-fit-in, "
        "you must specify width and/or height.",
    ):
        url_for(adaptive_full_fit_in=True, image_url=IMAGE_URL)
Example #2
0
def test_proper_haligns():
    """test_proper_haligns"""
    try:
        url_for(halign="wrong", image_url=IMAGE_URL)
    except ValueError, err:
        assert str(err) == 'Only "left", "center" and "right"' + " are valid values for horizontal alignment."
        return True
Example #3
0
def test_proper_valigns():
    """test_proper_haligns"""
    try:
        url_for(valign="wrong", image_url=IMAGE_URL)
    except ValueError, err:
        assert str(err) == 'Only "top", "middle" and "bottom"' + " are valid values for vertical alignment."
        return True
Example #4
0
def test_proper_valigns():
    '''test_proper_haligns'''
    try:
        url_for(valign='wrong', image_url=IMAGE_URL)
    except ValueError, err:
        assert str(err) == 'Only "top", "middle" and "bottom"' + \
                           ' are valid values for vertical alignment.'
        return True
Example #5
0
def test_adaptive_full_fit_in_fails_if_no_width_supplied():
    try:
        url_for(adaptive_full_fit_in=True, image_url=IMAGE_URL)
    except ValueError:
        err = sys.exc_info()[1]
        assert err is not None
    else:
        assert False, "Should not have gotten this far"
Example #6
0
def test_proper_haligns():
    """test_proper_haligns"""
    with expect.error_to_happen(
            ValueError,
            message=('Only "left", "center" and "right"'
                     " are valid values for horizontal alignment."),
    ):
        url_for(halign="wrong", image_url=IMAGE_URL)
Example #7
0
def test_proper_valigns():
    '''test_proper_haligns'''
    try:
        url_for(valign='wrong', image_url=IMAGE_URL)
    except ValueError, err:
        assert str(err) == 'Only "top", "middle" and "bottom"' + \
                           ' are valid values for vertical alignment.'
        return True
Example #8
0
def test_proper_haligns():
    '''test_proper_haligns'''
    try:
        url_for(halign='wrong', image_url=IMAGE_URL)
    except ValueError, err:
        assert str(err) == 'Only "left", "center" and "right"' + \
                           ' are valid values for horizontal alignment.'
        return True
Example #9
0
def test_proper_valigns():
    """test_proper_haligns"""
    with expect.error_to_happen(
            ValueError,
            message=('Only "top", "middle" and "bottom"'
                     " are valid values for vertical alignment."),
    ):
        url_for(valign="wrong", image_url=IMAGE_URL)
Example #10
0
def test_proper_haligns():
    '''test_proper_haligns'''
    try:
        url_for(halign='wrong', image_url=IMAGE_URL)
    except ValueError, err:
        assert str(err) == 'Only "left", "center" and "right"' + \
                           ' are valid values for horizontal alignment.'
        return True
def test_adaptive_full_fit_in_fails_if_no_width_supplied():
    try:
        url_for(adaptive_full_fit_in=True, image_url=IMAGE_URL)
    except ValueError:
        err = sys.exc_info()[1]
        assert err is not None
    else:
        assert False, "Should not have gotten this far"
Example #12
0
def test_url_raises_if_no_url():
    """test_url_raises_if_no_url
    Given
        An image URL of "" or null
    When
        I ask my library for an URL
    Then
        I get an exception that says image URL is mandatory
    """
    with expect.error_to_happen(
            ValueError, message="The image_url argument is mandatory."):
        url_for()
Example #13
0
def test_url_raises_if_no_url():
    '''test_url_raises_if_no_url
    Given
        An image URL of "" or null
    When
        I ask my library for an URL
    Then
        I get an exception that says image URL is mandatory
    '''
    try:
        url_for()
    except ValueError, err:
        assert str(err) == 'The image_url argument is mandatory.'
        return True
Example #14
0
def test_url_raises_if_no_url():
    '''test_url_raises_if_no_url
    Given
        An image URL of "" or null
    When
        I ask my library for an URL
    Then
        I get an exception that says image URL is mandatory
    '''
    try:
        url_for()
    except RuntimeError, err:
        assert str(err) == 'The image_url argument is mandatory.'
        return True
def test_url_raises_if_no_url():
    '''test_url_raises_if_no_url
    Given
        An image URL of "" or null
    When
        I ask my library for an URL
    Then
        I get an exception that says image URL is mandatory
    '''
    try:
        url_for()
    except ValueError as err:
        assert str(err) == 'The image_url argument is mandatory.'
        return True
    assert False, 'Should not have gotten this far'
Example #16
0
 def generate_old(self, options):
     url = url_for(**options)
     url = bytes(url, encoding='ascii')
     pad = lambda s: s + (16 - len(s) % 16) * "{"
     cypher = AES.new(self.computed_key)
     encrypted = base64.urlsafe_b64encode(cypher.encrypt(pad(url)))
     return "/%s/%s" % (str(encrypted, encoding='utf-8'), options['image_url'])
Example #17
0
    def generate(self, **options):
        '''Generates an encrypted URL with the specified options'''

        url = url_for(**options)

        pad = lambda s: s + (16 - len(s) % 16) * "{"
        cypher = AES.new(self.computed_key)
        encrypted = base64.urlsafe_b64encode(cypher.encrypt(pad(url)))

        return "/%s/%s" % (encrypted, options['image_url'])
Example #18
0
    def generate_old(self, options):
        url = url_for(**options)

        pad = lambda s: s + (16 - len(s) % 16) * "{"
        cypher = AES.new(self.computed_key)
        encrypted = base64.urlsafe_b64encode(cypher.encrypt(pad(url)))

        if PY3:
            encrypted = encrypted.decode('ascii')
        return "/%s/%s" % (encrypted, options['image_url'])
Example #19
0
    def generate(self, **options):
        '''Generates an encrypted URL with the specified options'''

        url = url_for(**options)

        pad = lambda s: s + (16 - len(s) % 16) * "{"
        cypher = AES.new(self.computed_key)
        encrypted = base64.urlsafe_b64encode(cypher.encrypt(pad(url)))

        return "/%s/%s" % (encrypted, options['image_url'])
Example #20
0
def test_no_options_specified():
    '''test_no_options_specified
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(image_url=IMAGE_URL)

    assert url == IMAGE_MD5, url
def test_no_options_specified():
    '''test_no_options_specified
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(image_url=IMAGE_URL)

    assert url == IMAGE_MD5, url
Example #22
0
def test_no_options_specified():
    """test_no_options_specified
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(image_url=IMAGE_URL)

    expect(url).to_equal(IMAGE_MD5)
Example #23
0
def test_url_width_height_4():
    '''test_url_width_height_4
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of orig
    When
        I ask my library for an URL
    Then
        I get "origx0/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(width="orig", image_url=IMAGE_URL)

    assert url == "origx0/84996242f65a4d864aceb125e1c4c5ba", url
Example #24
0
def test_url_width_height_1():
    """test_url_width_height_1
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 300
    When
        I ask my library for an URL
    Then
        I get "300x0/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(width=300, image_url=IMAGE_URL)

    assert url == "300x0/84996242f65a4d864aceb125e1c4c5ba", url
Example #25
0
def test_proper_meta():
    """test_proper_meta
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'meta' flag
    When
        I ask my library for an URL
    Then
        I get "meta/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(meta=True, image_url=IMAGE_URL)

    assert url == "meta/84996242f65a4d864aceb125e1c4c5ba", url
Example #26
0
def test_url_width_height_2():
    """test_url_width_height_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a height of 300
    When
        I ask my library for an URL
    Then
        I get "0x300/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(height=300, image_url=IMAGE_URL)

    expect(url).to_equal("0x300/84996242f65a4d864aceb125e1c4c5ba")
Example #27
0
def test_url_width_height_4():
    """test_url_width_height_4
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of orig
    When
        I ask my library for an URL
    Then
        I get "origx0/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(width="orig", image_url=IMAGE_URL)

    expect(url).to_equal("origx0/84996242f65a4d864aceb125e1c4c5ba")
Example #28
0
def test_vertical_alignment2():
    """test_vertical_alignment2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'middle' vertical alignment option
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(valign="middle", image_url=IMAGE_URL)

    assert url == "84996242f65a4d864aceb125e1c4c5ba", url
Example #29
0
def test_horizontal_alignment():
    """test_horizontal_alignment
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'left' horizontal alignment option
    When
        I ask my library for an URL
    Then
        I get "left/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(halign="left", image_url=IMAGE_URL)

    assert url == "left/84996242f65a4d864aceb125e1c4c5ba", url
Example #30
0
def test_flop_1():
    """test_flop_1
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And the flop flag
    When
        I ask my library for an URL
    Then
        I get "0x-0/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(flop=True, image_url=IMAGE_URL)

    assert url == "0x-0/84996242f65a4d864aceb125e1c4c5ba", url
Example #31
0
def test_proper_meta():
    """test_proper_meta
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'meta' flag
    When
        I ask my library for an URL
    Then
        I get "meta/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(meta=True, image_url=IMAGE_URL)

    expect("meta/84996242f65a4d864aceb125e1c4c5ba").to_equal(url)
Example #32
0
def test_vertical_alignment2():
    '''test_vertical_alignment2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'middle' vertical alignment option
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(valign='middle', image_url=IMAGE_URL)

    assert url == '84996242f65a4d864aceb125e1c4c5ba', url
def test_url_width_height_2():
    '''test_url_width_height_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a height of 300
    When
        I ask my library for an URL
    Then
        I get "0x300/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(height=300, image_url=IMAGE_URL)

    assert url == "0x300/84996242f65a4d864aceb125e1c4c5ba", url
def test_url_width_height_4():
    '''test_url_width_height_4
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of orig
    When
        I ask my library for an URL
    Then
        I get "origx0/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(width="orig", image_url=IMAGE_URL)

    assert url == "origx0/84996242f65a4d864aceb125e1c4c5ba", url
Example #35
0
def test_url_width_height_5():
    """test_url_width_height_5
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a height of orig
    When
        I ask my library for an URL
    Then
        I get "0xorig/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(height="orig", image_url=IMAGE_URL)

    assert url == "0xorig/84996242f65a4d864aceb125e1c4c5ba", url
Example #36
0
def test_flop_1():
    '''test_flop_1
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And the flop flag
    When
        I ask my library for an URL
    Then
        I get "0x-0/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(flop=True, image_url=IMAGE_URL)

    assert url == "0x-0/84996242f65a4d864aceb125e1c4c5ba", url
Example #37
0
def test_flop_1():
    """test_flop_1
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And the flop flag
    When
        I ask my library for an URL
    Then
        I get "0x-0/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(flop=True, image_url=IMAGE_URL)

    expect(url).to_equal("0x-0/84996242f65a4d864aceb125e1c4c5ba")
Example #38
0
def test_vertical_alignment2():
    """test_vertical_alignment2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'middle' vertical alignment option
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(valign="middle", image_url=IMAGE_URL)

    expect(url).to_equal("84996242f65a4d864aceb125e1c4c5ba")
Example #39
0
def test_horizontal_alignment():
    """test_horizontal_alignment
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'left' horizontal alignment option
    When
        I ask my library for an URL
    Then
        I get "left/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(halign="left", image_url=IMAGE_URL)

    expect(url).to_equal("left/84996242f65a4d864aceb125e1c4c5ba")
Example #40
0
def test_proper_meta():
    '''test_proper_meta
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'meta' flag
    When
        I ask my library for an URL
    Then
        I get "meta/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(meta=True, image_url=IMAGE_URL)

    assert url == 'meta/84996242f65a4d864aceb125e1c4c5ba', url
Example #41
0
def test_url_width_height_2():
    '''test_url_width_height_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a height of 300
    When
        I ask my library for an URL
    Then
        I get "0x300/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(height=300, image_url=IMAGE_URL)

    assert url == "0x300/84996242f65a4d864aceb125e1c4c5ba", url
Example #42
0
def test_horizontal_alignment():
    '''test_horizontal_alignment
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'left' horizontal alignment option
    When
        I ask my library for an URL
    Then
        I get "left/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(halign='left', image_url=IMAGE_URL)

    assert url == 'left/84996242f65a4d864aceb125e1c4c5ba', url
def test_vertical_alignment():
    '''test_vertical_alignment
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'top' vertical alignment option
    When
        I ask my library for an URL
    Then
        I get "top/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(valign='top',
                  image_url=IMAGE_URL)

    assert url == 'top/84996242f65a4d864aceb125e1c4c5ba', url
Example #44
0
def test_flip_2():
    """test_flip_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 200
        And the flip flag
    When
        I ask my library for an URL
    Then
        I get "-200x0/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(flip=True, width=200, image_url=IMAGE_URL)

    assert url == "-200x0/84996242f65a4d864aceb125e1c4c5ba", url
Example #45
0
def test_flip_2():
    """test_flip_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 200
        And the flip flag
    When
        I ask my library for an URL
    Then
        I get "-200x0/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(flip=True, width=200, image_url=IMAGE_URL)

    expect(url).to_equal("-200x0/84996242f65a4d864aceb125e1c4c5ba")
Example #46
0
def test_manual_crop_2():
    """test_manual_crop_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a manual crop left-top point of (0, 0)
        And a manual crop right-bottom point of (0, 0)
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(crop=((0, 0), (0, 0)), image_url=IMAGE_URL)

    assert url == "84996242f65a4d864aceb125e1c4c5ba", url
Example #47
0
def test_manual_crop_2():
    """test_manual_crop_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a manual crop left-top point of (0, 0)
        And a manual crop right-bottom point of (0, 0)
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(crop=((0, 0), (0, 0)), image_url=IMAGE_URL)

    expect("84996242f65a4d864aceb125e1c4c5ba").to_equal(url)
Example #48
0
def test_manual_crop_2():
    '''test_manual_crop_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a manual crop left-top point of (0, 0)
        And a manual crop right-bottom point of (0, 0)
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(crop=((0, 0), (0, 0)), image_url=IMAGE_URL)

    assert url == '84996242f65a4d864aceb125e1c4c5ba', url
def test_horizontal_alignment2():
    '''test_horizontal_alignment2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'center' horizontal alignment option
    When
        I ask my library for an URL
    Then
        I get "84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(halign='center',
                  image_url=IMAGE_URL)

    assert url == '84996242f65a4d864aceb125e1c4c5ba', url
Example #50
0
def test_flip_2():
    '''test_flip_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 200
        And the flip flag
    When
        I ask my library for an URL
    Then
        I get "-200x0/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(flip=True, width=200, image_url=IMAGE_URL)

    assert url == "-200x0/84996242f65a4d864aceb125e1c4c5ba", url
Example #51
0
def test_fit_in_url():
    """test_fit_in_url
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 200
        And a height of 300
        And the fit-in flag
    When
        I ask my library for an URL
    Then
        I get "fit-in/200x300/84996242f65a4d864aceb125e1c4c5ba" as URL
    """
    url = url_for(width=200, height=300, fit_in=True, image_url=IMAGE_URL)

    assert url == "fit-in/200x300/84996242f65a4d864aceb125e1c4c5ba", url
Example #52
0
def test_full_fit_in_url():
    '''test_full_fit_in_url
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 200
        And a height of 300
        And the full-fit-in flag
    When
        I ask my library for an URL
    Then
        I get "full-fit-in/200x300/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(width=200, height=300, full_fit_in=True, image_url=IMAGE_URL)

    assert url == "full-fit-in/200x300/84996242f65a4d864aceb125e1c4c5ba", url
def test_manual_crop_1():
    '''test_manual_crop_1
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a manual crop left-top point of (10, 20)
        And a manual crop right-bottom point of (30, 40)
    When
        I ask my library for an URL
    Then
        I get "10x20:30x40/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(crop=((10, 20), (30, 40)),
                  image_url=IMAGE_URL)

    assert url == '10x20:30x40/84996242f65a4d864aceb125e1c4c5ba', url
def test_smart_after_alignments():
    '''test_smart_after_alignments
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a 'smart' flag
        And a 'left' horizontal alignment option
    When
        I ask my library for an URL
    Then
        I get "left/smart/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(smart=True,
                  halign='left',
                  image_url=IMAGE_URL)

    assert url == 'left/smart/84996242f65a4d864aceb125e1c4c5ba', url
def test_flop_2():
    '''test_flop_2
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a height of 200
        And the flop flag
    When
        I ask my library for an URL
    Then
        I get "0x-200/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(flop=True,
                  height=200,
                  image_url=IMAGE_URL)

    assert url == "0x-200/84996242f65a4d864aceb125e1c4c5ba", url
def test_smart_url():
    '''test_smart_url
    Given
        An image URL of "my.server.com/some/path/to/image.jpg"
        And a width of 200
        And a height of 300
        And the smart flag
    When
        I ask my library for an URL
    Then
        I get "200x300/smart/84996242f65a4d864aceb125e1c4c5ba" as URL
    '''
    url = url_for(width=200,
                  height=300,
                  smart=True,
                  image_url=IMAGE_URL)

    assert url == "200x300/smart/84996242f65a4d864aceb125e1c4c5ba", url
def test_trim_tolerance_only():
    url = url_for(trim=(None, 15),
                  image_url=IMAGE_URL)
    assert url == 'trim::15/84996242f65a4d864aceb125e1c4c5ba', url
def test_trim_pixel_only():
    url = url_for(trim=('top-left', None),
                  image_url=IMAGE_URL)
    assert url == 'trim:top-left/84996242f65a4d864aceb125e1c4c5ba', url