-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a3360f
commit 49b6cb5
Showing
4 changed files
with
323 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
|
||
import pytest | ||
from flask import Flask | ||
from flask import render_template | ||
from flask import request | ||
from flask import send_from_directory | ||
from selenium.webdriver.common.keys import Keys | ||
|
||
|
||
def pytest_configure(config): | ||
|
@@ -89,11 +91,13 @@ def submit_form(): | |
# access form data submitted by the client | ||
form_data = request.form | ||
|
||
# print the form data | ||
print("Form Data:", form_data) | ||
# log data | ||
print(request.form) | ||
|
||
return "Form submitted successfully!\n" | ||
# render the template with the form data | ||
return render_template("form_response_template.html", form_data=form_data) | ||
|
||
# return configured and route decorated Flask app | ||
return app | ||
|
||
|
||
|
@@ -125,6 +129,28 @@ def update_form_backend_config( | |
json.dump(config, json_file, indent=2) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def form_inputs() -> Dict[str, Any]: | ||
"""Defines the values to be submitted for each input type during form tests.""" | ||
return { | ||
"email": "[email protected]", | ||
"date": {"date": "01012000"}, | ||
"datetime-local": { | ||
"date": "01012000", | ||
"tab": Keys.TAB, | ||
"time": "1200", | ||
"period": "AM", | ||
}, | ||
"number": "42", | ||
"selectbox": None, | ||
"tel": "18005554444", | ||
"text": "Sample text for input of type=text.", | ||
"textarea": "Sample text for Textarea.", | ||
"time": {"time": "1200", "period": "AM"}, | ||
"url": "http://example.com", | ||
} | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sb_test_url() -> str: | ||
"""Simply defines the test URL for seleniumbase fixture testing.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Contact Form Response</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #222; | ||
color: #ddd; /* Light text color */ | ||
padding: 20px; | ||
} | ||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
background-color: #333; /* Darker background color */ | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
label { | ||
font-weight: bold; | ||
color: #fff; /* White label color */ | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2>Contact Form Response</h2> | ||
{% for key, value in form_data.items() %} | ||
<label>{{ key }}:</label> | ||
<p>{{ value }}</p> | ||
{% endfor %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import json | ||
from pathlib import Path | ||
from typing import Any | ||
from typing import Dict | ||
from typing import Tuple | ||
|
||
import pytest | ||
|
@@ -37,6 +39,23 @@ def test_websrc_in_temp_dir( | |
assert check_files_subset(session_websrc_tmp_dir, website_files) | ||
|
||
|
||
@pytest.mark.fixture | ||
def test_config_keys_in_form_inputs( | ||
default_site_config: Dict[str, Any], form_inputs: Dict[str, Any] | ||
) -> None: | ||
"""Check that keys from config.json are present in form input testing fixture.""" | ||
# get types from questions section of config.json | ||
question_types = [q["type"] for q in default_site_config["questions"]] | ||
|
||
# check config question types missing form inputs (if any) | ||
missing_keys = set(question_types) - set(form_inputs) | ||
|
||
# no missing keys | ||
assert ( | ||
not missing_keys | ||
), f"Keys found in config.json are absent from test inputs : {missing_keys}" | ||
|
||
|
||
@pytest.mark.fixture | ||
def test_hello_world_sb(sb: BaseCase, sb_test_url: str) -> None: | ||
"""Just test if SeleniumBase can work on hello world example from docs.""" | ||
|
@@ -93,6 +112,32 @@ def test_serve_scripts_route(session_web_app: Flask) -> None: | |
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.flask | ||
@pytest.mark.fixture | ||
def test_submit_form_route(session_web_app: Flask, submit_route: str) -> None: | ||
"""Test the route for submitting a form.""" | ||
# get client | ||
client = session_web_app.test_client() | ||
|
||
# simulate a form submission | ||
form_data = { | ||
"name": "John Doe", | ||
"email": "[email protected]", | ||
"message": "This is a test message.", | ||
} | ||
response = client.post(submit_route, data=form_data) | ||
|
||
# assert that the response status code is 200 (OK) | ||
assert response.status_code == 200 | ||
|
||
# get content | ||
content = response.data.decode("utf-8") | ||
|
||
# Optionally, you can check the response content | ||
assert "Contact Form Response" in content | ||
assert all(form_data[key] in content for key in form_data) | ||
|
||
|
||
@pytest.mark.flask | ||
@pytest.mark.fixture | ||
def test_port_in_app_config(session_web_app: Flask) -> None: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters