[themotte/rDrama#451] New fixture for submissions
This commit is contained in:
parent
9468e217f0
commit
4bfb66272c
2 changed files with 43 additions and 0 deletions
|
@ -2,3 +2,4 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .fixture_accounts import accounts
|
from .fixture_accounts import accounts
|
||||||
|
from .fixture_submissions import submissions
|
||||||
|
|
42
files/tests/fixture_submissions.py
Normal file
42
files/tests/fixture_submissions.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from . import util
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from files.__main__ import app, db_session
|
||||||
|
from files.classes import Submission
|
||||||
|
from functools import lru_cache
|
||||||
|
import pytest
|
||||||
|
from time import time, sleep
|
||||||
|
|
||||||
|
class SubmissionsFixture:
|
||||||
|
def submission_for_client(self, client, data):
|
||||||
|
submit_get_response = client.get("/submit")
|
||||||
|
assert submit_get_response.status_code == 200
|
||||||
|
post_title = data.get('title', util.generate_text())
|
||||||
|
post_body = data.get('body', util.generate_text())
|
||||||
|
submit_post_response = client.post("/submit", data={
|
||||||
|
**data,
|
||||||
|
"title": post_title,
|
||||||
|
"body": post_body,
|
||||||
|
"formkey": util.formkey_from(submit_get_response.text),
|
||||||
|
})
|
||||||
|
assert submit_post_response.status_code == 200
|
||||||
|
assert post_title in submit_post_response.text
|
||||||
|
assert post_body in submit_post_response.text
|
||||||
|
post_info = util.ItemData.from_html(submit_post_response.text)
|
||||||
|
post_id_full = post_info.id_full
|
||||||
|
assert post_id_full.startswith('t2_')
|
||||||
|
|
||||||
|
post_id = int(post_id_full[3:])
|
||||||
|
|
||||||
|
db = db_session()
|
||||||
|
submission = db.query(Submission).filter_by(id=post_id).first()
|
||||||
|
assert Submission == type(submission)
|
||||||
|
return submission
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def submissions():
|
||||||
|
return SubmissionsFixture()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue