2020-02-25 04:54:28 +00:00
|
|
|
import copy
|
|
|
|
import datetime
|
|
|
|
|
2020-02-25 04:03:59 +00:00
|
|
|
import peewee
|
2020-02-25 04:54:28 +00:00
|
|
|
import pytest
|
2020-02-25 04:03:59 +00:00
|
|
|
from fixtures import demo_database
|
|
|
|
|
|
|
|
from keyosk import database
|
|
|
|
|
|
|
|
|
|
|
|
def test_formatting(demo_database):
|
2020-03-09 04:14:29 +00:00
|
|
|
for domain in database.KeyoskDomain.select():
|
2020-02-25 04:03:59 +00:00
|
|
|
assert str(domain.uuid) in str(domain)
|
|
|
|
assert domain.name in str(domain)
|
|
|
|
|
2020-02-25 04:54:28 +00:00
|
|
|
|
|
|
|
def test_unique(demo_database):
|
2020-03-09 04:14:29 +00:00
|
|
|
new_base = database.KeyoskDomain(
|
2020-02-25 04:54:28 +00:00
|
|
|
name="garbage",
|
|
|
|
audience="garbage",
|
|
|
|
title="garbage",
|
|
|
|
description="garbage",
|
|
|
|
contact="garbage",
|
|
|
|
enabled=True,
|
|
|
|
enable_client_set_auth=True,
|
|
|
|
enable_server_set_auth=True,
|
|
|
|
enable_refresh=True,
|
|
|
|
lifespan_access=datetime.timedelta(minutes=30),
|
|
|
|
lifespan_refresh=datetime.timedelta(days=30),
|
|
|
|
)
|
|
|
|
|
2020-03-09 04:14:29 +00:00
|
|
|
starwars = database.KeyoskDomain.get(database.KeyoskDomain.name == "star-wars")
|
2020-02-25 04:54:28 +00:00
|
|
|
|
|
|
|
unique = ["name", "audience"]
|
|
|
|
nonunique = ["title", "description", "contact"]
|
|
|
|
|
|
|
|
for item in unique:
|
|
|
|
new = copy.deepcopy(new_base)
|
|
|
|
setattr(new, item, getattr(starwars, item))
|
|
|
|
with pytest.raises(peewee.IntegrityError):
|
|
|
|
with database.interface.atomic():
|
2020-03-09 04:14:29 +00:00
|
|
|
database.KeyoskDomain.bulk_create([new])
|
2020-02-25 04:54:28 +00:00
|
|
|
|
|
|
|
for item in nonunique:
|
|
|
|
new = copy.deepcopy(new_base)
|
|
|
|
setattr(new, item, getattr(starwars, item))
|
|
|
|
with database.interface.atomic():
|
2020-03-09 04:14:29 +00:00
|
|
|
database.KeyoskDomain.bulk_create([new])
|
2020-02-25 04:54:28 +00:00
|
|
|
|
|
|
|
with database.interface.atomic():
|
|
|
|
new.delete_instance()
|
|
|
|
|
|
|
|
|
|
|
|
def test_unique_access_lists(demo_database):
|
2020-03-09 04:14:29 +00:00
|
|
|
new_base = database.KeyoskDomainAccessList(
|
2020-02-25 04:54:28 +00:00
|
|
|
name="imperial-star-destroyer",
|
2020-03-09 04:14:29 +00:00
|
|
|
domain=database.KeyoskDomain.get(database.KeyoskDomain.name == "star-wars"),
|
2020-02-25 04:54:28 +00:00
|
|
|
)
|
|
|
|
|
2020-03-09 04:14:29 +00:00
|
|
|
isd = database.KeyoskDomainAccessList.get(
|
|
|
|
database.KeyoskDomainAccessList.name == "imperial-star-destroyer"
|
2020-02-25 04:54:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
unique = ["name"]
|
|
|
|
|
|
|
|
for item in unique:
|
|
|
|
new = copy.deepcopy(new_base)
|
|
|
|
setattr(new, item, getattr(isd, item))
|
|
|
|
with pytest.raises(peewee.IntegrityError):
|
|
|
|
with database.interface.atomic():
|
2020-03-09 04:14:29 +00:00
|
|
|
database.KeyoskDomainAccessList.bulk_create([new])
|