From 90cae5ffc98b3922e91d37b7d4cc8cef188ceec1 Mon Sep 17 00:00:00 2001 From: yann Date: Wed, 2 Jul 2025 11:36:51 +0200 Subject: [PATCH] first try with fixture for login --- tests/conftest.py | 17 +++++++++++++++++ tests/test_connection.py | 23 +++++++++++++++++++++++ tests/test_purchase.py | 5 +++++ 3 files changed, 45 insertions(+) create mode 100644 tests/conftest.py create mode 100644 tests/test_connection.py create mode 100644 tests/test_purchase.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..50e7972 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +import pytest +from server import app + +EMAIL1 = "admin@irontemple.com" +EMAIL2 = "john@simplylift.co" + +@pytest.fixture +def client(): + with app.test_client() as client: + yield client + + +@pytest.fixture +def connect(client): + response = client.post('/showSummary', data={"email": EMAIL}) + soup = BeautifulSoup(response.data, 'html.parser') + diff --git a/tests/test_connection.py b/tests/test_connection.py new file mode 100644 index 0000000..22b664f --- /dev/null +++ b/tests/test_connection.py @@ -0,0 +1,23 @@ +from flask import session +from bs4 import BeautifulSoup + + +def test_should_status_code_ok(client): + response = client.get('/') + assert response.status_code == 200 + + +def test_should_display_sorry_with_unknown_email(client): + email = "test@test.com" + response = client.post('/showSummary', data={"email": email}) + assert "_flashes" in session + assert session["_flashes"] == [("message", "Sorry, that email wasn't found")] + + +def test_shoul_display_page_on_known_email(client): + email = "admin@irontemple.com" + response = client.post('/showSummary', data={"email": email}) + soup = BeautifulSoup(response.data, 'html.parser') + assert soup.h2.text == "Welcome, "+email + + diff --git a/tests/test_purchase.py b/tests/test_purchase.py new file mode 100644 index 0000000..abb03e3 --- /dev/null +++ b/tests/test_purchase.py @@ -0,0 +1,5 @@ +from bs4 import BeautifulSoup + + +def test_should_not_when_try_more_points_than_available(connect): + print(response.data)