mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep(fastapi): rewrite test_ban with fixtures
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
eb396813a8
commit
de0f919077
1 changed files with 10 additions and 7 deletions
|
@ -11,20 +11,21 @@ from aurweb.db import create
|
||||||
from aurweb.models.ban import Ban, is_banned
|
from aurweb.models.ban import Ban, is_banned
|
||||||
from aurweb.testing.requests import Request
|
from aurweb.testing.requests import Request
|
||||||
|
|
||||||
ban = request = None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup(db_test):
|
def setup(db_test):
|
||||||
global ban, request
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def ban() -> Ban:
|
||||||
ts = datetime.utcnow() + timedelta(seconds=30)
|
ts = datetime.utcnow() + timedelta(seconds=30)
|
||||||
with db.begin():
|
with db.begin():
|
||||||
ban = create(Ban, IPAddress="127.0.0.1", BanTS=ts)
|
ban = create(Ban, IPAddress="127.0.0.1", BanTS=ts)
|
||||||
request = Request()
|
yield ban
|
||||||
|
|
||||||
|
|
||||||
def test_ban():
|
def test_ban(ban: Ban):
|
||||||
assert ban.IPAddress == "127.0.0.1"
|
assert ban.IPAddress == "127.0.0.1"
|
||||||
assert bool(ban.BanTS)
|
assert bool(ban.BanTS)
|
||||||
|
|
||||||
|
@ -45,11 +46,13 @@ def test_invalid_ban():
|
||||||
db.rollback()
|
db.rollback()
|
||||||
|
|
||||||
|
|
||||||
def test_banned():
|
def test_banned(ban: Ban):
|
||||||
|
request = Request()
|
||||||
request.client.host = "127.0.0.1"
|
request.client.host = "127.0.0.1"
|
||||||
assert is_banned(request)
|
assert is_banned(request)
|
||||||
|
|
||||||
|
|
||||||
def test_not_banned():
|
def test_not_banned(ban: Ban):
|
||||||
|
request = Request()
|
||||||
request.client.host = "192.168.0.1"
|
request.client.host = "192.168.0.1"
|
||||||
assert not is_banned(request)
|
assert not is_banned(request)
|
||||||
|
|
Loading…
Add table
Reference in a new issue