from conftest import handler
from goalkeeper.models import Goal, Notification


def test_notifications():

    # Initilize the app and client
    h = handler
    # h = TestHandler()
    app = h.app
    client = h.client

    # register and login new user
    h.register("f", "<EMAIL>", "f")
    client.post("/accounts/login", data={"email": "<EMAIL>", "password": "f"})
    # logout new user
    assert client.get("/accounts/logout").status_code == 200

    h.register("g", "<EMAIL>", "g")
    client.post("/accounts/login", data={"email": "<EMAIL>", "password": "g"})

    assert client.get("/friends/add_friend/<EMAIL>").status_code == 302
    client.get("/accounts/logout")

    # Log in once again with <EMAIL>
    client.post("/accounts/login", data={"email": "<EMAIL>", "password": "f"})

    # Accept Friend Request from <EMAIL>
    assert client.get("/friends/add_friend/<EMAIL>").status_code == 302

    response = client.post("/goals/add_goal", data={"title": "test", "description": "test"})

    with app.app_context():
        assert (
            Notification.query.filter(Notification.user_email == "<EMAIL>").all()
            is not None
        )
    h.remove_friend("<EMAIL>")
    h.remove_friend("<EMAIL>")
    h.remove_user("<EMAIL>")
    h.remove_user("<EMAIL>")
    Notification.query.filter(Notification.user_email == "<EMAIL>").delete()
    Notification.query.filter(Notification.user_email == "<EMAIL>").delete()

from conftest import handler
from goalkeeper.models import Goal, Notification


def test_notifications():

    # Initilize the app and client
    h = handler
    # h = TestHandler()
    app = h.app
    client = h.client

    # register and login new user
    h.register("f", "<EMAIL>", "f")
    client.post("/accounts/login", data={"email": "<EMAIL>", "password": "f"})
    # logout new user
    assert client.get("/accounts/logout").status_code == 200

    h.register("g", "<EMAIL>", "g")
    client.post("/accounts/login", data={"email": "<EMAIL>", "password": "g"})

    assert client.get("/friends/add_friend/<EMAIL>").status_code == 302
    client.get("/accounts/logout")

    # Log in once again with <EMAIL>
    client.post("/accounts/login", data={"email": "<EMAIL>", "password": "f"})

    # Accept Friend Request from <EMAIL>
    assert client.get("/friends/add_friend/<EMAIL>").status_code == 302

    response = client.post("/goals/add_goal", data={"title": "test", "description": "test"})

    with app.app_context():
        assert (
            Notification.query.filter(Notification.user_email == "<EMAIL>").all()
            is not None
        )
    h.remove_friend("<EMAIL>")
    h.remove_friend("<EMAIL>")
    h.remove_user("<EMAIL>")
    h.remove_user("<EMAIL>")
    Notification.query.filter(Notification.user_email == "<EMAIL>").delete()
    Notification.query.filter(Notification.user_email == "<EMAIL>").delete()

# Initilize the app and client # h = TestHandler() # register and login new user # logout new user # Log in once again with <EMAIL> # Accept Friend Request from <EMAIL>