示例#1
0
def test_handle_login_email_failure(app, client):
    res = client.post('/handle-login',
                      data=dict(email="", password="******"),
                      follow_redirects=False)
    assert res.status_code == 302
    assert_redirect(res, "http://localhost/login")
    assert_flashes(client, "Email is required for login")
示例#2
0
def test_delete_user_doesnt_match(app, client):
    user = create_user()
    image = create_image('image1', "s3://path-to-image-1", user.user_id)
    create_logged_in_user(client, 1234)
    res = client.post(f"/image/delete/{image.image_id}")

    assert_flashes(client, "Cannot modify other people's images")
    assert_redirect(res, "http://localhost/")
def test_handle_user_already_exists(app, client):
    user = User(email="*****@*****.**", password="******")
    db.session.add(user)
    db.session.commit()
    res = client.post('/handle-registration',
                      data=dict(email="*****@*****.**", password="******"),
                      follow_redirects=False)
    assert_flashes(client, "This user already exists")
    assert_redirect(res, "http://localhost/login")
示例#4
0
def test_handle_success_login(app, client):
    user = User(email="*****@*****.**", password="******")
    db.session.add(user)
    db.session.commit()
    res = client.post('/handle-login',
                      data=dict(email="*****@*****.**", password="******"),
                      follow_redirects=False)
    assert_flashes(client, "Login successful")
    assert_redirect(res, "http://localhost/upload")
示例#5
0
def test_handle_wrong_credentials_email(app, client):
    user = User(email="*****@*****.**", password="******")
    db.session.add(user)
    db.session.commit()
    res = client.post('/handle-login',
                      data=dict(email="*****@*****.**",
                                password="******"),
                      follow_redirects=False)
    assert_flashes(client, "Incorrect Credentials")
    assert_redirect(res, "http://localhost/register")
示例#6
0
def test_delete_image_success(app, client, mocker):
    # Creating no-op mocks for S3 / DB
    mocker.patch("server.delete_from_s3", return_value=True)
    mocker.patch("server.delete_from_db", return_value=True)

    user = create_user()
    image = create_image('image1', "s3://path-to-image-1", user.user_id)
    create_logged_in_user(client, user.user_id)
    res = client.post(f"/image/delete/{image.image_id}")
    assert_redirect(res, "http://localhost/my-images")
def test_handle_registration_success(app, client):
    res = client.post('/handle-registration',
                      data=dict(email="*****@*****.**",
                                password="******"),
                      follow_redirects=False)
    User.query.filter_by(email="*****@*****.**").first()
    users = User.query.all()
    assert_flashes(client, "New user created")
    assert len(users) == 1
    assert_logged_in_user(client, users[0].user_id)
    assert_redirect(res, "http://localhost/upload")
def test_process_upload_success(app, client, mocker):
    # Creating no-op mocks for S3 / DB
    mocker.patch(
        "server.save_image_to_s3", 
        return_value=True)
    
    mocker.patch(
        "server.save_image_to_db", 
        return_value=True)

    create_logged_in_user(client)
    file = create_file_data()
    res = client.post('/process-upload', data=dict(file=file), follow_redirects=False, content_type="multipart/form-data") 
    assert_redirect(res, "http://localhost/my-images")
def test_upload_failure(app, client):
    res = client.get("/upload")
    assert_redirect(res, "http://localhost/")
示例#10
0
def test_user_has_no_images(app, client):
    user = create_user()
    res = client.get(f"user/{user.user_id}")
    if not user.images:
        assert_flashes(client, "User doesn't have any images")
        assert_redirect(res, "http://localhost/")
示例#11
0
def test_if_not_user_to_visit(app, client):
    res = client.get("user/3")
    assert_flashes(client, "User doesn't exist")
    assert_redirect(res, "http://localhost/")
示例#12
0
def test_image_delete_failure(app, client):
    res = client.post(f"/image/delete/9")
    assert_redirect(res, "http://localhost/")
def test_handle_register_email_failure(app, client):
    res = client.post('/handle-registration',
                      data=dict(email="", password="******"),
                      follow_redirects=False)
    assert_redirect(res, "http://localhost/register")
    assert_flashes(client, "Email required for registration")
示例#14
0
def test_logout_failure(app, client):
    res = client.get("/logout")
    assert_redirect(res, "http://localhost/")
示例#15
0
def test_image_id_doesnt_exist(app, client):
    create_logged_in_user(client)
    res = client.put(f"/image/update/10", data={"action" : 'publish'})
    assert_flashes(client, "Image doesn't exist")
    assert_redirect(res, "http://localhost/")
示例#16
0
def test_handle_login_password_failure(app, client):
    res = client.post('/handle-login',
                      data=dict(email="*****@*****.**", password=""),
                      follow_redirects=False)
    assert_redirect(res, "http://localhost/login")
    assert_flashes(client, "Password is required for login")
def test_my_images_failure(app, client):
    res = client.get("/my-images")
    assert_redirect(res, "http://localhost/")
示例#18
0
def test_my_images_failure(app, client):
    res = client.put(f"/image/update/9")
    assert_redirect(res, "http://localhost/")
示例#19
0
def test_logout_success(app, client):
    create_logged_in_user(client)
    res = client.get('/logout')
    assert_flashes(client, "Logout successful")
    assert_redirect(res, "http://localhost/")
示例#20
0
def test_delete_image_id_doesnt_exist(app, client):
    create_logged_in_user(client)
    res = client.post(f"/image/delete/10")
    assert_flashes(client, "Image doesn't exist")
    assert_redirect(res, "http://localhost/")