コード例 #1
0
def test_upload_successfully():
    reset_data()
    A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning")
    token = A['token']
    img_url = "http://ichef.bbci.co.uk/onesport/cps/480/mcs/media/images/57210000/jpg/_57210683_57210682.jpg"
    x_start = 0
    y_start = 0
    x_end = 199
    y_end = 199
    base = 5001
    UF.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end,
                                 y_end, base)
コード例 #2
0
def test_photo_invalidToken():
    token = None
    img_url = "http://ichef.bbci.co.uk/onesport/cps/480/mcs/media/images/57210000/jpg/_57210683_57210682.jpg"
    x_start = 0
    y_start = 0
    x_end = 200
    y_end = 200
    base = 5001

    with pytest.raises(TypeError):
        UF.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end,
                                     y_end, base)
コード例 #3
0
def test_end_invalid():
    reset_data()
    A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning")
    token = A['token']
    img_url = "http://ichef.bbci.co.uk/onesport/cps/480/mcs/media/images/57210000/jpg/_57210683_57210682.jpg"
    x_start = -1
    y_start = -1
    x_end = 200
    y_end = 200
    base = 5001
    with pytest.raises(UF.ValueError):
        UF.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end,
                                     y_end, base)
コード例 #4
0
def test_valid_img_URL():
    reset_data()
    A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning")
    token = A['token']
    img_url = "http://google.com.au.jpg"
    x_start = 0
    y_start = 0
    x_end = 480
    y_end = 290
    base = 5001
    with pytest.raises(UF.ValueError):
        UF.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end,
                                     y_end, base)
コード例 #5
0
def test_upload_base_error():
    reset_data()
    A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning")
    token = A['token']
    CF.channels_create(token, 'UploadError', "True")
    img_url = "http://ichef.bbci.co.uk/onesport/cps/480/mcs/media/images/57210000/jpg/_57210683_57210682.jpg"
    x_start = '0'
    y_start = '0'
    x_end = '200'
    y_end = '200'
    base = None

    UF.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end,
                                 y_end, base)
コード例 #6
0
def user_profiles_uploadphoto():
    '''
    Given a URL of an image on the internet, crops the image within x and 
    y coordinates

    '''
    token = request.form.get("token")
    img_url = request.form.get("img_url")
    x_start = to_int(request.form.get("x_start"))
    y_start = to_int(request.form.get("y_start"))
    x_end = to_int(request.form.get("x_end"))
    y_end = to_int(request.form.get("y_end"))

    return dumps(
        user.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end,
                                       y_end))
コード例 #7
0
def test_profiles_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.
    '''

    # Initialisation
    global_var.initialise_all()

    # Creating a user
    user = auth_functions.auth_register("*****@*****.**", "pass123", "Rayden",\
        "Smith")

    token = user["token"]

    # URL does not exist
    with pytest.raises(ValueError, match="The server cannot be reached"):
        funcs.user_profiles_uploadphoto(token, \
            "https://invalid_url.jpg", 10, 10, 20, 20)

    # Testing photo url (750 x 738 dimension)
    test_url = "https://i.redd.it/51p5c1efueoy.jpg"

    # A valid photo is uploaded and cropped
    assert funcs.user_profiles_uploadphoto(token, test_url, 300, 300, \
        500, 500) == {}

    # A valid photo is uploaded and cropped - replace current photo
    assert funcs.user_profiles_uploadphoto(token, test_url, 200, 200, \
        500, 500) == {}

    # Size of img = (0, 0, 750, 738)
    with pytest.raises(ValueError, match="x_start is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, -1, 0, 700, 700)

    with pytest.raises(ValueError, match="x_start is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, 760, 0, 700, 700)

    with pytest.raises(ValueError, match="x_end is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, 0, 0, -1, 700)

    with pytest.raises(ValueError, match="x_end is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, 0, 0, 800, 700)

    with pytest.raises(ValueError, match="y_start is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, 0, -1, 700, 700)

    with pytest.raises(ValueError, match="y_start is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, 0, 800, 700, 700)

    with pytest.raises(ValueError, match="y_end is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, 0, 0, 700, -1)

    with pytest.raises(ValueError, match="y_end is invalid"):
        funcs.user_profiles_uploadphoto(token, test_url, 0, 0, 700, 800)

    # If x_start == x_end
    with pytest.raises(ValueError, match=\
        "An image of no pixels is not an image"):
        funcs.user_profiles_uploadphoto(token, test_url, 10, 0, 10, 700)

    # If y_start == y_end
    with pytest.raises(ValueError, match=\
        "An image of no pixels is not an image"):
        funcs.user_profiles_uploadphoto(token, test_url, 0, 10, 700, 10)

    with pytest.raises(ValueError, match="Image uploaded is not a JPG"):
        funcs.user_profiles_uploadphoto(token, \
            "https://myrealdomain.com/images/corgi-dogs-pictures-7.png", \
                0, 10, 200, 700)

    # An exception occurs when token is invalid
    with pytest.raises(AccessError, match="Invalid token"):
        funcs.user_profiles_uploadphoto("invalid_tok", test_url, 10, 10, 20,
                                        20)

    # Clean up test images
    files = glob.glob('server/assets/images/*')
    for image_file in files:
        # Don't delete default image
        if image_file != "server/assets/images/default.jpg":
            os.remove(image_file)