[themotte/rDrama#451] Sometimes we also want the user, not just their session
This commit is contained in:
parent
f78345a4fb
commit
6905710b18
1 changed files with 17 additions and 5 deletions
|
@ -2,37 +2,49 @@
|
||||||
from . import util
|
from . import util
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from files.__main__ import app
|
from files.__main__ import app, db_session
|
||||||
|
from files.classes import User
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
import pytest
|
import pytest
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
|
|
||||||
class AccountsFixture:
|
class AccountsFixture:
|
||||||
@lru_cache(maxsize=None)
|
@lru_cache(maxsize=None)
|
||||||
def client_for_account(self, name = "default"):
|
def client_and_user_for_account(self, name):
|
||||||
|
|
||||||
client = app.test_client()
|
client = app.test_client()
|
||||||
|
|
||||||
signup_get_response = client.get("/signup")
|
signup_get_response = client.get("/signup")
|
||||||
assert signup_get_response.status_code == 200
|
assert signup_get_response.status_code == 200
|
||||||
soup = BeautifulSoup(signup_get_response.text, 'html.parser')
|
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
|
# these hidden input values seem to be used for anti-bot purposes and need to be submitted
|
||||||
|
# The specific logic seems to be "if it took less than 5 seconds between getting
|
||||||
|
# the signup page and submitting it, you're probably a bot".
|
||||||
form_timestamp = next(tag for tag in soup.find_all("input") if tag.get("name") == "now").get("value")
|
form_timestamp = next(tag for tag in soup.find_all("input") if tag.get("name") == "now").get("value")
|
||||||
|
|
||||||
username = f"test-{name}-{str(round(time()))}"
|
username = f"test-{name}-{str(round(time()))}"
|
||||||
print(f"Signing up as {username}")
|
print(f"Signing up as {username}")
|
||||||
|
|
||||||
signup_post_response = client.post("/signup", data={
|
signup_post_response = client.post("/signup", data={
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": "password",
|
"password": "password",
|
||||||
"password_confirm": "password",
|
"password_confirm": "password",
|
||||||
"email": "",
|
"email": "",
|
||||||
"formkey": util.formkey_from(signup_get_response.text),
|
"formkey": util.formkey_from(signup_get_response.text),
|
||||||
"now": form_timestamp
|
"now": form_timestamp,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert signup_post_response.status_code == 302
|
assert signup_post_response.status_code == 302
|
||||||
assert "error" not in signup_post_response.location
|
assert "error" not in signup_post_response.location
|
||||||
|
|
||||||
|
db = db_session
|
||||||
|
user = db.query(User).filter_by(username=username).first()
|
||||||
|
|
||||||
|
assert User == type(user)
|
||||||
|
|
||||||
|
return client, user
|
||||||
|
|
||||||
|
def client_for_account(self, name = "default"):
|
||||||
|
client, user = client_and_user_for_account(name)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
def logged_off(self):
|
def logged_off(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue