mirror of
https://github.com/enpaul/keyosk.git
synced 2025-12-18 09:27:38 +00:00
Add tests for unique field assurances on domain and account models
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import copy
|
||||
|
||||
import passlib
|
||||
import peewee
|
||||
import pytest
|
||||
from fixtures import demo_database
|
||||
|
||||
from keyosk import database
|
||||
@@ -60,3 +64,40 @@ def test_crypto(demo_database):
|
||||
database.Account.username == "jack.oneill@airforce.gov"
|
||||
)
|
||||
assert account.verify_server_set_secret(new_autopass)
|
||||
|
||||
|
||||
def test_unique(demo_database):
|
||||
new_base = database.Account(
|
||||
username="garbage",
|
||||
encrypted_client_set_secret=passlib.hash.pbkdf2_sha512.hash("garbage"),
|
||||
encrypted_server_set_secret=passlib.hash.pbkdf2_sha512.hash("garbage"),
|
||||
enabled=True,
|
||||
extras={"gar": "bage"},
|
||||
)
|
||||
|
||||
vader = database.Account.get(database.Account.username == "dvader")
|
||||
|
||||
unique = ["username"]
|
||||
nonunique = ["extras"]
|
||||
|
||||
for item in unique:
|
||||
new = copy.deepcopy(new_base)
|
||||
setattr(new, item, getattr(vader, item))
|
||||
# Using bulk create as a hacky work around for a weird issue. When using numeric
|
||||
# TIDs peewee apparently raises an integrity error when calling ``save()``,
|
||||
# however when using UUID TIDs it just returns 0 (for the number of edited rows)
|
||||
# The second is the behavior as documented, but I want the integrity error. I
|
||||
# don't care enough to figure out why its behaving differently here, and bulk
|
||||
# create gives me that integrity error I'm after
|
||||
with pytest.raises(peewee.IntegrityError):
|
||||
with database.interface.atomic():
|
||||
database.Account.bulk_create([new])
|
||||
|
||||
for item in nonunique:
|
||||
new = copy.deepcopy(new_base)
|
||||
setattr(new, item, getattr(vader, item))
|
||||
with database.interface.atomic():
|
||||
database.Account.bulk_create([new])
|
||||
|
||||
with database.interface.atomic():
|
||||
new.delete_instance()
|
||||
|
||||
Reference in New Issue
Block a user