diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-01-03 20:46:15 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-01-03 20:52:20 +0100 |
commit | f4fe38385be425494e6b6dfffd77607f2d61e5b0 (patch) | |
tree | 33485c5922100a7c48786a7efb256accbe323a53 /tests/playwright | |
parent | 876f098c14c2a51fee12627e852b4264e10566e6 (diff) | |
download | fietsboek-f4fe38385be425494e6b6dfffd77607f2d61e5b0.tar.gz fietsboek-f4fe38385be425494e6b6dfffd77607f2d61e5b0.tar.bz2 fietsboek-f4fe38385be425494e6b6dfffd77607f2d61e5b0.zip |
add tests for adding/removing friends
Diffstat (limited to 'tests/playwright')
-rw-r--r-- | tests/playwright/test_friends.py | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/playwright/test_friends.py b/tests/playwright/test_friends.py new file mode 100644 index 0000000..e19bdea --- /dev/null +++ b/tests/playwright/test_friends.py @@ -0,0 +1,117 @@ +import datetime + +from playwright.sync_api import Page, expect +from sqlalchemy import select + +from fietsboek import models + +from .conftest import Helper # pylint: disable=relative-beyond-top-level + + +def test_friend_not_found(page: Page, playwright_helper: Helper): + playwright_helper.login() + + page.goto("/me") + + page.get_by_label("Email of the friend").fill("does-not-exist@example.com") + page.get_by_role("button", name="Send friend request").click() + + expect(page.locator(".alert")).to_have_text("The friend was not found") + + +def test_send_friend_request(page: Page, playwright_helper: Helper, dbaccess): + with dbaccess: + user = models.User(name="Volker", email="vol@ker.de", is_verified=True) + user.set_password("raboof") + dbaccess.add(user) + dbaccess.flush() + dbaccess.commit() + + playwright_helper.login() + + page.goto("/me") + + page.get_by_label("Email of the friend").fill("vol@ker.de") + page.get_by_role("button", name="Send friend request").click() + + john = playwright_helper.john_doe() + reqs = list( + dbaccess.execute(select(models.FriendRequest).filter_by(sender_id=john.id)).scalars() + ) + assert len(reqs) == 1 + assert reqs[0].recipient.name == "Volker" + + +def test_accept_friend_request(page: Page, playwright_helper: Helper, dbaccess): + john = playwright_helper.john_doe() + with dbaccess: + volker = models.User(name="Volker", email="vol@ker.de", is_verified=True) + volker.set_password("raboof") + dbaccess.add(volker) + dbaccess.add( + models.FriendRequest(sender=john, recipient=volker, date=datetime.datetime.now()) + ) + dbaccess.commit() + + volker = dbaccess.merge(volker) + john = dbaccess.merge(john) + playwright_helper.login(volker) + + page.goto("/me") + + page.get_by_role("button", name="Accept").click() + + assert "John Doe" in page.content() + + friends = list(volker.get_friends()) + assert len(friends) == 1 + assert john.id in [friend.id for friend in friends] + + +def test_accept_by_sending(page: Page, playwright_helper: Helper, dbaccess): + john = playwright_helper.john_doe() + with dbaccess: + volker = models.User(name="Volker", email="vol@ker.de", is_verified=True) + volker.set_password("raboof") + dbaccess.add(volker) + dbaccess.add( + models.FriendRequest(sender=john, recipient=volker, date=datetime.datetime.now()) + ) + dbaccess.commit() + + volker = dbaccess.merge(volker) + john = dbaccess.merge(john) + playwright_helper.login(volker) + + page.goto("/me") + + page.get_by_label("Email of the friend").fill("john@doe.com") + page.get_by_role("button", name="Send friend request").click() + + assert "John Doe" in page.content() + + friends = list(volker.get_friends()) + assert len(friends) == 1 + assert john.id in [friend.id for friend in friends] + + +def test_unfriend(page: Page, playwright_helper: Helper, dbaccess): + john = playwright_helper.john_doe() + with dbaccess: + john = dbaccess.merge(john) + volker = models.User(name="Volker", email="vol@ker.de", is_verified=True) + volker.set_password("raboof") + dbaccess.add(volker) + dbaccess.flush() + volker.add_friend(john) + dbaccess.commit() + + volker = dbaccess.merge(volker) + john = dbaccess.merge(john) + playwright_helper.login(volker) + + page.goto("/me") + page.get_by_role("button", name="Unfriend").click() + + friends = list(volker.get_friends()) + assert not friends |