open-law/tests/test_get_or_create_permissi...

33 lines
1.0 KiB
Python
Raw Normal View History

2023-05-24 11:49:04 +00:00
from app import models as m
from app.controllers.get_or_create_permission import get_or_create_permission
def test_get_or_create_permission(client):
access = m.Permission.Access
2023-05-24 14:06:33 +00:00
entity_type = m.Permission.Entity
2023-05-24 11:49:04 +00:00
book_u: m.Permission = m.Permission.query.filter_by(
2023-05-24 14:06:33 +00:00
access=access.U, entity_type=entity_type.BOOK
2023-05-24 11:49:04 +00:00
).first()
assert not book_u
assert not m.Permission.query.count()
2023-05-24 14:06:33 +00:00
book_u: m.Permission = get_or_create_permission(
access=access.U, entity_type=entity_type.BOOK
)
2023-05-24 11:49:04 +00:00
assert book_u
assert book_u.access == access.U
2023-05-24 14:06:33 +00:00
assert book_u.entity_type == entity_type.BOOK
2023-05-24 11:49:04 +00:00
assert m.Permission.query.count() == 1
book_u: m.Permission = m.Permission.query.filter_by(
2023-05-24 14:06:33 +00:00
access=access.U, entity_type=entity_type.BOOK
2023-05-24 11:49:04 +00:00
).first()
assert book_u
assert book_u.access == access.U
2023-05-24 14:06:33 +00:00
assert book_u.entity_type == entity_type.BOOK
2023-05-24 11:49:04 +00:00
2023-05-24 14:06:33 +00:00
get_or_create_permission(access=access.U, entity_type=entity_type.BOOK)
2023-05-24 11:49:04 +00:00
assert m.Permission.query.count() == 1