Exemplo n.º 1
0
def test_check_image(default_settings):
    # test200_100.png
    img_width = "http://i.imgur.com/4dAWAZI.png"
    # test100_200.png
    img_height = "http://i.imgur.com/I7GwF3D.png"
    # test100_100.png
    img_ok = "http://i.imgur.com/CYV6NzT.png"
    # random too big image
    img_size = "http://i.imgur.com/l3Vmp4m.gif"
    # random image wrong type
    img_type = "https://d11xdyzr0div58.cloudfront.net/static/logos/archlinux-logo-black-scalable.f931920e6cdb.svg"

    data = check_image(img_width)
    assert "wide" in data[0]
    assert not data[1]

    data = check_image(img_height)
    assert "high" in data[0]
    assert not data[1]

    data = check_image(img_type)
    assert "type" in data[0]
    assert not data[1]

    data = check_image(img_ok)
    assert data[0] is None
    assert data[1]

    flaskbb_config["AVATAR_WIDTH"] = 1000
    flaskbb_config["AVATAR_HEIGHT"] = 1000
    data = check_image(img_size)
    assert "big" in data[0]
    assert not data[1]
Exemplo n.º 2
0
def test_check_image(default_settings):
    # test200_100.png
    img_width = "http://i.imgur.com/4dAWAZI.png"
    # test100_200.png
    img_height = "http://i.imgur.com/I7GwF3D.png"
    # test100_100.png
    img_ok = "http://i.imgur.com/CYV6NzT.png"
    # random too big image
    img_size = "http://i.imgur.com/l3Vmp4m.gif"
    # random image wrong type
    img_type = "https://flaskbb.org/static/imgs/flask.svg"

    data = check_image(img_width)
    assert "wide" in data[0]
    assert not data[1]

    data = check_image(img_height)
    assert "high" in data[0]
    assert not data[1]

    data = check_image(img_type)
    assert "type" in data[0]
    assert not data[1]

    data = check_image(img_ok)
    assert data[0] is None
    assert data[1]

    flaskbb_config["AVATAR_WIDTH"] = 1000
    flaskbb_config["AVATAR_HEIGHT"] = 1000
    data = check_image(img_size)
    assert "big" in data[0]
    assert not data[1]
Exemplo n.º 3
0
def test_check_image(default_settings):
    # test200_100.png
    img_width = "http://i.imgur.com/4dAWAZI.png"
    # test100_200.png
    img_height = "http://i.imgur.com/I7GwF3D.png"
    # test100_100.png
    img_ok = "http://i.imgur.com/CYV6NzT.png"
    # random too big image
    img_size = "http://i.imgur.com/l3Vmp4m.gif"
    # random image wrong type
    img_type = "https://d11xdyzr0div58.cloudfront.net/static/logos/archlinux-logo-black-scalable.f931920e6cdb.svg"

    data = check_image(img_width)
    assert "wide" in data[0]
    assert not data[1]

    data = check_image(img_height)
    assert "high" in data[0]
    assert not data[1]

    data = check_image(img_type)
    assert "type" in data[0]
    assert not data[1]

    data = check_image(img_ok)
    assert data[0] is None
    assert data[1]

    flaskbb_config["AVATAR_WIDTH"] = 1000
    flaskbb_config["AVATAR_HEIGHT"] = 1000
    data = check_image(img_size)
    assert "big" in data[0]
    assert not data[1]
Exemplo n.º 4
0
def test_check_image(default_settings):
    # test200_100.png
    img_width = "http://i.imgur.com/4dAWAZI.png"
    # test100_200.png
    img_height = "http://i.imgur.com/I7GwF3D.png"
    # test100_100.png
    img_ok = "http://i.imgur.com/CYV6NzT.png"
    # random too big image
    img_size = "http://i.imgur.com/l3Vmp4m.gif"
    # random image wrong type
    img_type = "https://flaskbb.org/static/imgs/flask.svg"

    data = check_image(img_width)
    assert "wide" in data[0]
    assert not data[1]

    data = check_image(img_height)
    assert "high" in data[0]
    assert not data[1]

    data = check_image(img_type)
    assert "type" in data[0]
    assert not data[1]

    data = check_image(img_ok)
    assert data[0] is None
    assert data[1]

    flaskbb_config["AVATAR_WIDTH"] = 1000
    flaskbb_config["AVATAR_HEIGHT"] = 1000
    data = check_image(img_size)
    assert "big" in data[0]
    assert not data[1]
Exemplo n.º 5
0
 def validate_avatar(self, field):
     if field.data is not None:
         error, status = check_image(field.data)
         if error is not None:
             raise ValidationError(error)
         return status
Exemplo n.º 6
0
def test_check_image_just_right(image_just_right, default_settings, responses):
    responses.add(image_just_right)

    result = check_image(image_just_right.url)
    assert result[1]
Exemplo n.º 7
0
def test_check_image_wrong_mime(image_wrong_mime, default_settings, responses):
    responses.add(image_wrong_mime)

    assert_bad_image_check(check_image(image_wrong_mime.url), "type")
Exemplo n.º 8
0
def test_check_image_too_wide(image_too_wide, default_settings, responses):
    responses.add(image_too_wide)

    assert_bad_image_check(check_image(image_too_wide.url), "wide")
Exemplo n.º 9
0
def test_check_image_too_tall(image_too_tall, default_settings, responses):
    responses.add(image_too_tall)

    assert_bad_image_check(check_image(image_too_tall.url), "high")
Exemplo n.º 10
0
def test_check_image_too_big(image_too_big, default_settings, responses):
    responses.add(image_too_big)

    flaskbb_config["AVATAR_WIDTH"] = 1000
    flaskbb_config["AVATAR_HEIGHT"] = 1000
    assert_bad_image_check(check_image(image_too_big.url), "big")
Exemplo n.º 11
0
def test_check_image_just_right(image_just_right, default_settings, responses):
    responses.add(image_just_right)

    result = check_image(image_just_right.url)
    assert result[1]
Exemplo n.º 12
0
def test_check_image_wrong_mime(image_wrong_mime, default_settings, responses):
    responses.add(image_wrong_mime)

    assert_bad_image_check(check_image(image_wrong_mime.url), "type")
Exemplo n.º 13
0
def test_check_image_too_wide(image_too_wide, default_settings, responses):
    responses.add(image_too_wide)

    assert_bad_image_check(check_image(image_too_wide.url), "wide")
Exemplo n.º 14
0
def test_check_image_too_tall(image_too_tall, default_settings, responses):
    responses.add(image_too_tall)

    assert_bad_image_check(check_image(image_too_tall.url), "high")
Exemplo n.º 15
0
def test_check_image_too_big(image_too_big, default_settings, responses):
    responses.add(image_too_big)

    flaskbb_config["AVATAR_WIDTH"] = 1000
    flaskbb_config["AVATAR_HEIGHT"] = 1000
    assert_bad_image_check(check_image(image_too_big.url), "big")
Exemplo n.º 16
0
 def validate_avatar(self, field):
     if field.data is not None:
         error, status = check_image(field.data)
         if error is not None:
             raise ValidationError(error)
         return status