morethantext-web/tests/step_defs/test_session.py

32 lines
779 B
Python
Raw Normal View History

2022-06-22 12:03:17 -04:00
"""tests for server sessions."""
from pytest_bdd import given, scenarios, then, when
scenarios("../features/session.feature")
@given("a running server")
def start_server(server):
"""Make a running server."""
server.set_safe_port()
server.start()
@when("the home page is accessed")
def access_home_page(server, page):
"""Access the home page."""
url = f"http://{server.base_url}/"
page.request_url(url)
2022-06-24 08:22:17 -04:00
@then("there is a default session id")
2022-06-22 12:03:17 -04:00
def confirm_session(page):
"""Confirm session id exists."""
2022-06-24 08:22:17 -04:00
cookies = page.get_cookies()
name = "morethantext.sid"
cookie = None
for holder in cookies:
if holder.name == name:
cookie = holder
assert cookie, f"Did not find cookie {name}, but retrieved {cookies}"