Exemple #1
0
def test_img_url_no_server(user_1):
    """ Test case where server is not running in the background
    """
    img_url = "https://www.ottophoto.com/kirlian/kirlian_1/kirlian12.jpg"
    with pytest.raises(AccessError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 0, 100, 100)
    clear()
Exemple #2
0
def test_img_url_forbidden_access(user_1):
    """ Test case where image uploaded cannot fetch its url due to a forbidden access
    """
    img_url = "http://pngimg.com/uploads/circle/circle_PNG62.png"
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 0, 100, 100)
    clear()
Exemple #3
0
def test_img_url_not_jpg(user_1):
    """ Test case where image uploaded is not a JPG
    """
    img_url = "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 0, 100, 100)
    clear()
Exemple #4
0
def test_img_url_invalid_token(user_1, logout_user_1):
    """Test for a non-registered/invalid user. (Invalid token)
    """
    img_url = "https://www.ottophoto.com/kirlian/kirlian_1/kirlian12.jpg"
    with pytest.raises(AccessError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 0, 1, 1)
    clear()
Exemple #5
0
def test_img_url_status_not_200(user_1):
    """ Test case where img_url returns a HTTP status other than 200.
    """
    x_start = 0
    x_end = 1
    y_start = 0
    y_end = 1
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], 'https://fake_img',
                                      x_start, y_start, x_end, y_end)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], 'https://', x_start,
                                      y_start, x_end, y_end)
    clear()
Exemple #6
0
def route_user_profile_uploadphoto():
    """Given a URL of an image on the internet, crops the image within bounds (x_start, y_start) and (x_end, y_end). Position (0,0) is the top left.

    Args:
        token (string)
        img_url (string)
        x_start (int)
        y_start (int)
        x_end (int)
        y_end (int)

    Returns:
        (dict): {}
    """
    payload = request.get_json()
    x_start = int(payload['x_start'])
    y_start = int(payload['y_start'])
    x_end = int(payload['x_end'])
    y_end = int(payload['y_end'])
    try:
        return dumps(
            user.user_profile_uploadphoto(payload['token'], payload['img_url'],
                                          x_start, y_start, x_end, y_end))
    except (InputError, AccessError) as e:
        return e
Exemple #7
0
def test_img_url_x_in_width(user_1):
    """Test invalid x_start and x_end values
    """
    img_url = "https://www.ottophoto.com/kirlian/kirlian_1/kirlian12.jpg"
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, -1, 100, 100,
                                      100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 10000, 100,
                                      100, 100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 10000, 100,
                                      100, 100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 100, -1,
                                      100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 100, 10000,
                                      100)
Exemple #8
0
def test_img_url_xy_dimensions_not_valid(user_1):
    """ Test case when any of x_start, y_start, x_end, y_end are not within the
    dimensions of the image at the URL.
    """
    img_url = "https://www.ottophoto.com/kirlian/kirlian_1/kirlian12.jpg"
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, -1, 0, 100,
                                      100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 9999, 100,
                                      100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 0, -1, 100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 0, 100,
                                      9999)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 200, 0, 100,
                                      100)
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 100, 100, 1)
    clear()
Exemple #9
0
def test_img_url_y_start_greater_y_end(user_1):
    img_url = "https://www.ottophoto.com/kirlian/kirlian_1/kirlian12.jpg"
    with pytest.raises(InputError):
        user.user_profile_uploadphoto(user_1['token'], img_url, 0, 1000, 100,
                                      100)