Updated test_api.
Had to change hotel_ids used in test_requests. Previously any hotel_id was valid now only registered ones are. Doesn't make a difference in prod
This commit is contained in:
@@ -417,7 +417,7 @@ class TestGenericWebhookEndpoint:
|
|||||||
"""Test successful generic webhook submission with real form data."""
|
"""Test successful generic webhook submission with real form data."""
|
||||||
unique_id = uuid.uuid4().hex[:8]
|
unique_id = uuid.uuid4().hex[:8]
|
||||||
test_data = {
|
test_data = {
|
||||||
"hotel_data": {"hotelname": "Bemelmans", "hotelcode": "39054_001"},
|
"hotel_data": {"hotelname": "Bemelmans", "hotelcode": "HOTEL123"},
|
||||||
"form_data": {
|
"form_data": {
|
||||||
"sprache": "it",
|
"sprache": "it",
|
||||||
"anreise": "14.10.2025",
|
"anreise": "14.10.2025",
|
||||||
@@ -451,14 +451,14 @@ class TestGenericWebhookEndpoint:
|
|||||||
assert "timestamp" in data
|
assert "timestamp" in data
|
||||||
assert (
|
assert (
|
||||||
data["message"]
|
data["message"]
|
||||||
== "Generic webhook data received and processed successfully"
|
== "Generic webhook data processed successfully"
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_generic_webhook_creates_customer_and_reservation(self, client):
|
def test_generic_webhook_creates_customer_and_reservation(self, client):
|
||||||
"""Test that webhook creates customer and reservation in database."""
|
"""Test that webhook creates customer and reservation in database."""
|
||||||
unique_id = uuid.uuid4().hex[:8]
|
unique_id = uuid.uuid4().hex[:8]
|
||||||
test_data = {
|
test_data = {
|
||||||
"hotel_data": {"hotelname": "Test Hotel", "hotelcode": "TEST123"},
|
"hotel_data": {"hotelname": "Test Hotel", "hotelcode": "HOTEL123"},
|
||||||
"form_data": {
|
"form_data": {
|
||||||
"sprache": "de",
|
"sprache": "de",
|
||||||
"anreise": "25.12.2025",
|
"anreise": "25.12.2025",
|
||||||
@@ -517,7 +517,7 @@ class TestGenericWebhookEndpoint:
|
|||||||
(r for r in reservations if r.customer_id == customer.id), None
|
(r for r in reservations if r.customer_id == customer.id), None
|
||||||
)
|
)
|
||||||
assert reservation is not None, "Reservation should be created"
|
assert reservation is not None, "Reservation should be created"
|
||||||
assert reservation.hotel_code == "TEST123"
|
assert reservation.hotel_code == "HOTEL123"
|
||||||
assert reservation.hotel_name == "Test Hotel"
|
assert reservation.hotel_name == "Test Hotel"
|
||||||
assert reservation.num_adults == 2
|
assert reservation.num_adults == 2
|
||||||
assert reservation.num_children == 1
|
assert reservation.num_children == 1
|
||||||
@@ -537,7 +537,7 @@ class TestGenericWebhookEndpoint:
|
|||||||
def test_generic_webhook_missing_dates(self, client):
|
def test_generic_webhook_missing_dates(self, client):
|
||||||
"""Test webhook with missing required dates."""
|
"""Test webhook with missing required dates."""
|
||||||
test_data = {
|
test_data = {
|
||||||
"hotel_data": {"hotelname": "Test", "hotelcode": "123"},
|
"hotel_data": {"hotelname": "Test", "hotelcode": "HOTEL123"},
|
||||||
"form_data": {
|
"form_data": {
|
||||||
"sprache": "de",
|
"sprache": "de",
|
||||||
"name": "John",
|
"name": "John",
|
||||||
@@ -555,7 +555,7 @@ class TestGenericWebhookEndpoint:
|
|||||||
def test_generic_webhook_invalid_date_format(self, client):
|
def test_generic_webhook_invalid_date_format(self, client):
|
||||||
"""Test webhook with invalid date format."""
|
"""Test webhook with invalid date format."""
|
||||||
test_data = {
|
test_data = {
|
||||||
"hotel_data": {"hotelname": "Test", "hotelcode": "123"},
|
"hotel_data": {"hotelname": "Test", "hotelcode": "HOTEL123"},
|
||||||
"form_data": {
|
"form_data": {
|
||||||
"sprache": "en",
|
"sprache": "en",
|
||||||
"anreise": "2025-10-14", # Wrong format, should be DD.MM.YYYY
|
"anreise": "2025-10-14", # Wrong format, should be DD.MM.YYYY
|
||||||
@@ -577,7 +577,7 @@ class TestGenericWebhookEndpoint:
|
|||||||
"""Test webhook properly handles children ages."""
|
"""Test webhook properly handles children ages."""
|
||||||
unique_id = uuid.uuid4().hex[:8]
|
unique_id = uuid.uuid4().hex[:8]
|
||||||
test_data = {
|
test_data = {
|
||||||
"hotel_data": {"hotelname": "Family Hotel", "hotelcode": "FAM001"},
|
"hotel_data": {"hotelname": "Family Hotel", "hotelcode": "HOTEL123"},
|
||||||
"form_data": {
|
"form_data": {
|
||||||
"sprache": "it",
|
"sprache": "it",
|
||||||
"anreise": "01.08.2025",
|
"anreise": "01.08.2025",
|
||||||
@@ -608,9 +608,9 @@ class TestGenericWebhookEndpoint:
|
|||||||
result = await session.execute(select(Reservation))
|
result = await session.execute(select(Reservation))
|
||||||
reservations = result.scalars().all()
|
reservations = result.scalars().all()
|
||||||
reservation = next(
|
reservation = next(
|
||||||
(r for r in reservations if r.hotel_code == "FAM001"), None
|
(r for r in reservations if r.hotel_code == "HOTEL123"), None
|
||||||
)
|
)
|
||||||
assert reservation is not None
|
assert reservation is not None, "Reservation should be created"
|
||||||
assert reservation.num_children == 3
|
assert reservation.num_children == 3
|
||||||
# children_ages is stored as CSV string
|
# children_ages is stored as CSV string
|
||||||
children_ages = [
|
children_ages = [
|
||||||
@@ -631,9 +631,9 @@ class TestGenericWebhookEndpoint:
|
|||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
assert customer is not None
|
assert customer is not None, "Customer should be created"
|
||||||
assert customer.phone is None # Empty phone should be None
|
assert customer.phone is None, "Empty phone should be None"
|
||||||
assert customer.name_prefix is None # -- should be filtered out
|
assert customer.name_prefix is None, "Name prefix '--' should be filtered out"
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
@@ -914,7 +914,7 @@ class TestErrorHandling:
|
|||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 422
|
assert response.status_code == 400
|
||||||
|
|
||||||
def test_wix_webhook_missing_required_fields(self, client):
|
def test_wix_webhook_missing_required_fields(self, client):
|
||||||
"""Test webhook with missing required fields."""
|
"""Test webhook with missing required fields."""
|
||||||
|
|||||||
Reference in New Issue
Block a user