Commit 5185df62 authored by Kevin Morris's avatar Kevin Morris
Browse files

move aurweb.testing to its own package



+ Added aurweb.testing.setup_test_db(*tables)
+ Added aurweb.testing.models.make_user(**kwargs)
+ Added aurweb.testing.models.make_session(**kwargs)
+ Added aurweb.testing.requests.Client
+ Added aurweb.testing.requests.Request
* Updated test_l10n.py to use our new Request

Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 64bc9392
from aurweb.db import get_engine
import aurweb.db
def setup_test_db(*args):
......@@ -21,7 +21,7 @@ def setup_test_db(*args):
test_tables = ["Users", "Sessions"];
setup_test_db(*test_tables)
"""
engine = get_engine()
engine = aurweb.db.get_engine()
conn = engine.connect()
tables = list(args)
......
import warnings
from sqlalchemy import exc
import aurweb.db
def make_user(**kwargs):
with warnings.catch_warnings():
warnings.simplefilter("ignore", exc.SAWarning)
from aurweb.models.user import User
user = User(**kwargs)
aurweb.db.session.add(user)
aurweb.db.session.commit()
return user
def make_session(**kwargs):
with warnings.catch_warnings():
warnings.simplefilter("ignore", exc.SAWarning)
from aurweb.models.session import Session
session = Session(**kwargs)
aurweb.db.session.add(session)
aurweb.db.session.commit()
return session
class Client:
host = "127.0.0.1"
class Request:
client = Client()
cookies = dict()
headers = dict()
""" Test our l10n module. """
from aurweb import l10n
class FakeRequest:
""" A fake Request doppleganger; use this to change request.cookies
easily and with no side-effects. """
def __init__(self, *args, **kwargs):
self.cookies = kwargs.pop("cookies", dict())
from aurweb.testing.requests import Request
def test_translator():
......@@ -18,7 +11,7 @@ def test_translator():
def test_get_request_language():
""" First, tests default_lang, then tests a modified AURLANG cookie. """
request = FakeRequest()
request = Request()
assert l10n.get_request_language(request) == "en"
request.cookies["AURLANG"] = "de"
......@@ -28,8 +21,8 @@ def test_get_request_language():
def test_get_raw_translator_for_request():
""" Make sure that get_raw_translator_for_request is giving us
the translator we expect. """
request = FakeRequest(cookies={"AURLANG": "de"})
request = Request()
request.cookies["AURLANG"] = "de"
translator = l10n.get_raw_translator_for_request(request)
assert translator.gettext("Home") == \
l10n.translator.translate("Home", "de")
......@@ -38,7 +31,8 @@ def test_get_raw_translator_for_request():
def test_get_translator_for_request():
""" Make sure that get_translator_for_request is giving us back
our expected translation function. """
request = FakeRequest(cookies={"AURLANG": "de"})
request = Request()
request.cookies["AURLANG"] = "de"
translate = l10n.get_translator_for_request(request)
assert translate("Home") == "Startseite"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment