def test_invalid_token(reg_user, test_img): clear_v2() reg_user(0) img = test_img w = img['width'] h = img['height'] with pytest.raises(AccessError): user_profile_uploadphoto_v1('Invalid token', img['url'], 0, 0, w, h)
def test_invalid_token(): clear_v1() auth_register_v2('*****@*****.**', 'password', 'comp', 'student') with pytest.raises(AccessError): user_profile_uploadphoto_v1( 'abcdef', 'https://media.vanityfair.com/photos/5a9069131d14714f6de43ff5/7:3/w_1995,h_855,c_limit/tout-and-lede_Lisa-Simpson.jpg', 0, 0, 200, 200)
def test_not_jpg(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student') with pytest.raises(InputError): user_profile_uploadphoto_v1( result1['token'], 'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png', 0, 0, 200, 200)
def test_HTTP_status(): clear_v1() auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy", "Dandy") auth_user_1_token = auth_user_1_data["token"] img_url = "https://google.com/1.jpg" with pytest.raises(InputError): user_profile_uploadphoto_v1(auth_user_1_token, img_url, 0, 0, 650, 650)
def test_simple(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student') user1 = user_profile_v2(result1['token'], result1['auth_user_id']) user_profile_uploadphoto_v1( result1['token'], 'https://media.vanityfair.com/photos/5a9069131d14714f6de43ff5/7:3/w_1995,h_855,c_limit/tout-and-lede_Lisa-Simpson.jpg', 0, 0, 200, 200) user2 = user_profile_v2(result1['token'], result1['auth_user_id']) assert user1['user']['profile_img_url'] != user2['user']['profile_img_url']
def test_dimensions(): clear_v1() auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy", "Dandy") auth_user_1_token = auth_user_1_data["token"] img_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTD9LU7ZYs8ge6HCNaZ-B5eDOnoZFfW4F6nXg&usqp=CAU" with pytest.raises(InputError): user_profile_uploadphoto_v1(auth_user_1_token, img_url, 999999, 999999, 999999, 999999)
def test_user_profile_uploadphoto_v1(): clear_v1() auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy", "Dandy") auth_user_1_token = auth_user_1_data["token"] auth_user_1_id = auth_user_1_data["auth_user_id"] auth_user_1_img_url = generate_user_profile_photo(auth_user_1_id)["profile_img_url"] img_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTD9LU7ZYs8ge6HCNaZ-B5eDOnoZFfW4F6nXg&usqp=CAU" user_profile_uploadphoto_v1(auth_user_1_token, img_url, 0, 0, 1, 1) profile_img_url = user_profile_v2(auth_user_1_token, auth_user_1_id)["user"]["profile_img_url"] assert auth_user_1_img_url == profile_img_url
def test_success_valid_crop(reg_user, test_img): clear_v2() token = reg_user(0)['token'] img = test_img w = int(img['width']/2) h = int(img['height']/2) return_val = user_profile_uploadphoto_v1(token, img['url'], 0, 0, w, h) assert return_val == {}
def test_repeated_success(reg_user, test_img, test_img_2): clear_v2() token = reg_user(0)['token'] img = test_img w = img['width'] h = img['height'] user_profile_uploadphoto_v1(token, img['url'], 0, 0, w, h) img = test_img_2 w = img['width'] h = img['height'] return_val = user_profile_uploadphoto_v1(token, img['url'], 0, 0, w, h) assert return_val == {}
def uploadphoto(): parameters = request.get_json() token = parameters['token'] img_url = parameters['img_url'] x_start = parameters['x_start'] y_start = parameters['y_start'] x_end = parameters['x_end'] y_end = parameters['y_end'] output = user_profile_uploadphoto_v1(token, img_url, x_start, y_start, x_end, y_end) return dumps(output)
def user_uploadphoto(): data = request.get_json() token = data['token'] img_url = data['img_url'] print(data) x_start = int(data['x_start']) y_start = int(data['y_start']) x_end = int(data['x_end']) y_end = int(data['y_end']) output = user_profile_uploadphoto_v1(token, img_url, x_start, y_start, x_end, y_end) return dumps(output)
def test_crop_error(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student') with pytest.raises(InputError): user_profile_uploadphoto_v1( result1['token'], 'https://media.vanityfair.com/photos/5a9069131d14714f6de43ff5/7:3/w_1995,h_855,c_limit/tout-and-lede_Lisa-Simpson.jpg', -1, 0, 200, 200) with pytest.raises(InputError): user_profile_uploadphoto_v1( result1['token'], 'https://media.vanityfair.com/photos/5a9069131d14714f6de43ff5/7:3/w_1995,h_855,c_limit/tout-and-lede_Lisa-Simpson.jpg', 0, -1, 200, 200) with pytest.raises(InputError): user_profile_uploadphoto_v1( result1['token'], 'https://media.vanityfair.com/photos/5a9069131d14714f6de43ff5/7:3/w_1995,h_855,c_limit/tout-and-lede_Lisa-Simpson.jpg', 0, 0, 100000, 200) with pytest.raises(InputError): user_profile_uploadphoto_v1( result1['token'], 'https://media.vanityfair.com/photos/5a9069131d14714f6de43ff5/7:3/w_1995,h_855,c_limit/tout-and-lede_Lisa-Simpson.jpg', -1, 0, 100000, 100000)
def test_invalid_url(reg_user): clear_v2() token = reg_user(0)['token'] with pytest.raises(InputError): user_profile_uploadphoto_v1(token, 'https://bogus/url/v1', 100, 100, 200, 200)
def test_invalid_dimensions(reg_user, test_img): clear_v2() token = reg_user(0)['token'] img = test_img w = img['width'] h = img['height'] # Test each coordinate being invalid separately with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], w+1, 0, w, h) with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], 0, h+1, w, h) with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], 0, 0, w+1, h) with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], 0, 0, w, h+1) with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], -1, 0, w, h) with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], 0, -1, w, h) with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], 0, 0, -1, h) with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], 0, 0, w, -1)
def test_non_jpg(reg_user, png_img): clear_v2() token = reg_user(0)['token'] img = png_img with pytest.raises(InputError): user_profile_uploadphoto_v1(token, img['url'], 0, 0, img['width'], img['height'])
def test_success_no_crop(reg_user, test_img): clear_v2() token = reg_user(0)['token'] img = test_img return_val = user_profile_uploadphoto_v1(token, img['url'], 0, 0, img['width'], img['height']) assert return_val == {}
def test_invalid_url(): clear_v1() result1 = auth_register_v2('*****@*****.**', 'password', 'comp', 'student') with pytest.raises(InputError): user_profile_uploadphoto_v1(result1['token'], 'abcdef', 0, 0, 200, 200)
def test_non_200_status_code(reg_user): clear_v2() token = reg_user(0)['token'] with pytest.raises(InputError): user_profile_uploadphoto_v1(token, 'https://webcms3.cse.unsw.edu.au/COMP1532/21T1/', 100, 100, 200, 200)