morethantext-web/tests/step_defs/test_session.py

32 lines
779 B
Python

"""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)
@then("there is a default session id")
def confirm_session(page):
"""Confirm session id exists."""
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}"