Initial e2e testing
Authored by @FatherInire
This commit is contained in:
parent
3e3cb7e2f9
commit
a12123ca01
10 changed files with 55 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -10,4 +10,5 @@ venv/
|
|||
.sass-cache/
|
||||
flask_session/
|
||||
.DS_Store
|
||||
site_settings.json
|
||||
site_settings.json
|
||||
.venv
|
||||
|
|
|
@ -2,6 +2,7 @@ version: '2.3'
|
|||
|
||||
services:
|
||||
files:
|
||||
container_name: "themotte"
|
||||
build:
|
||||
context: .
|
||||
volumes:
|
||||
|
|
0
files/__init__.py
Normal file
0
files/__init__.py
Normal file
|
@ -24,6 +24,7 @@ app.jinja_env.cache = {}
|
|||
app.jinja_env.auto_reload = True
|
||||
faulthandler.enable()
|
||||
|
||||
|
||||
app.config["SITE_NAME"]=environ.get("SITE_NAME").strip()
|
||||
app.config["GUMROAD_LINK"]=environ.get("GUMROAD_LINK", "https://marsey1.gumroad.com/l/tfcvri").strip()
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
|
@ -34,7 +35,7 @@ app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3153600
|
|||
app.config["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_NAME").strip().lower()
|
||||
app.config["VERSION"] = "1.0.0"
|
||||
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
|
||||
app.config["SESSION_COOKIE_SECURE"] = True
|
||||
app.config["SESSION_COOKIE_SECURE"] = "localhost" not in environ.get("DOMAIN")
|
||||
app.config["SESSION_COOKIE_SAMESITE"] = "Lax"
|
||||
app.config["PERMANENT_SESSION_LIFETIME"] = 60 * 60 * 24 * 365
|
||||
app.config["DEFAULT_COLOR"] = environ.get("DEFAULT_COLOR", "ff0000").strip()
|
||||
|
|
|
@ -9,7 +9,7 @@ from flask import request
|
|||
|
||||
SITE = environ.get("DOMAIN", '').strip()
|
||||
SITE_NAME = environ.get("SITE_NAME", '').strip()
|
||||
if SITE == "localhost": SITE_FULL = 'http://' + SITE
|
||||
if "localhost" in SITE: SITE_FULL = 'http://' + SITE
|
||||
else: SITE_FULL = 'https://' + SITE
|
||||
|
||||
|
||||
|
|
|
@ -291,7 +291,6 @@ def sanitize(sanitized, alert=False, comment=False, edit=False):
|
|||
|
||||
if bans: abort(403, description=f"Remove the banned domains {bans} and try again!")
|
||||
|
||||
|
||||
signal.alarm(0)
|
||||
|
||||
return sanitized
|
||||
|
|
0
files/tests/__init__.py
Normal file
0
files/tests/__init__.py
Normal file
42
files/tests/test_e2e.py
Normal file
42
files/tests/test_e2e.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from bs4 import BeautifulSoup
|
||||
from time import time, sleep
|
||||
from files.__main__ import app
|
||||
|
||||
# these tests require `docker-compose up` first
|
||||
|
||||
def test_rules():
|
||||
response = app.test_client().get("/rules")
|
||||
assert response.status_code == 200
|
||||
assert response.text.startswith("<!DOCTYPE html>")
|
||||
|
||||
|
||||
def test_signup():
|
||||
client = app.test_client()
|
||||
with client: # this keeps the session between requests, which we need
|
||||
signup_get_response = client.get("/signup")
|
||||
assert signup_get_response.status_code == 200
|
||||
soup = BeautifulSoup(signup_get_response.text, 'html.parser')
|
||||
# these hidden input values seem to be used for anti-bot purposes and need to be submitted
|
||||
formkey = next(tag for tag in soup.find_all("input") if tag.get("name") == "formkey").get("value")
|
||||
form_timestamp = next(tag for tag in soup.find_all("input") if tag.get("name") == "now").get("value")
|
||||
|
||||
sleep(5) # too-fast submissions are rejected (bot check?)
|
||||
username = "testuser" + str(round(time()))
|
||||
signup_post_response = client.post("/signup", data={
|
||||
"username": username,
|
||||
"password": "password",
|
||||
"password_confirm": "password",
|
||||
"email": "",
|
||||
"formkey": formkey,
|
||||
"now": form_timestamp
|
||||
})
|
||||
print(f"Signing up as {username}")
|
||||
assert signup_post_response.status_code == 302
|
||||
assert "error" not in signup_post_response.location
|
||||
|
||||
# we should now be logged in and able to post
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -21,3 +21,9 @@ docker-compose up
|
|||
4 - That's it! Visit `localhost` in your browser.
|
||||
|
||||
5 - Optional: to change the domain from "localhost" to something else and configure the site settings, as well as integrate it with the external services the website uses, please edit the variables in the `env` file and then restart the docker container.
|
||||
|
||||
# Run the E2E tests:
|
||||
|
||||
(after `docker-compose up`)
|
||||
`docker exec themotte bash -c "cd service && python3 -m pytest -s"`
|
||||
|
||||
|
|
|
@ -26,3 +26,4 @@ pyenchant
|
|||
youtube-dl
|
||||
yattag
|
||||
webptools
|
||||
pytest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue