WIP
This commit is contained in:
+32
-16
@@ -1,9 +1,10 @@
|
||||
import pytest
|
||||
from grung.db import GrungDB
|
||||
from tinydb import where
|
||||
from tinydb.storages import MemoryStorage
|
||||
|
||||
import ttfrog.app
|
||||
from ttfrog import schema
|
||||
from grung.db import GrungDB
|
||||
from tinydb.storages import MemoryStorage
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -43,23 +44,38 @@ def test_permissions(app):
|
||||
players = app.db.save(schema.Group(name="players", members=[john]))
|
||||
notes = app.db.save(schema.Page(name="notes"))
|
||||
|
||||
# default read-only
|
||||
assert players.can_read(notes, app.db)
|
||||
assert not players.can_write(notes, app.db)
|
||||
assert not players.can_delete(notes, app.db)
|
||||
# default no access
|
||||
assert not players.can_read(notes)
|
||||
assert not players.can_write(notes)
|
||||
assert not players.can_delete(notes)
|
||||
assert not john.can_read(notes)
|
||||
assert not john.can_write(notes)
|
||||
assert not john.can_delete(notes)
|
||||
|
||||
# set to rw, no delete
|
||||
notes.set_permissions(players, [schema.Permissions.READ, schema.Permissions.WRITE], app.db)
|
||||
assert players.can_read(notes, app.db)
|
||||
assert players.can_write(notes, app.db)
|
||||
assert not players.can_delete(notes, app.db)
|
||||
notes.set_permissions(players, [schema.Permissions.READ, schema.Permissions.WRITE])
|
||||
notes = app.db.Page.get(doc_id=notes.doc_id)
|
||||
|
||||
assert players.can_read(notes)
|
||||
assert players.can_write(notes)
|
||||
assert not players.can_delete(notes)
|
||||
|
||||
# members of the group inherit group permissions
|
||||
assert john.can_read(notes, app.db)
|
||||
assert john.can_write(notes, app.db)
|
||||
assert not john.can_delete(notes, app.db)
|
||||
assert john.can_read(notes)
|
||||
assert john.can_write(notes)
|
||||
assert not john.can_delete(notes)
|
||||
|
||||
# permissions are the union of user + group permissions
|
||||
notes.set_permissions(john, [schema.Permissions.DELETE], app.db)
|
||||
assert not players.can_delete(notes, app.db)
|
||||
assert john.can_delete(notes, app.db)
|
||||
notes.set_permissions(john, [schema.Permissions.DELETE])
|
||||
assert not players.can_delete(notes)
|
||||
assert john.can_delete(notes)
|
||||
|
||||
|
||||
def test_bootstrap(app):
|
||||
from ttfrog.bootstrap import bootstrap
|
||||
|
||||
bootstrap()
|
||||
|
||||
admins = app.db.Group.get(where("name") == "administrators")
|
||||
admin = app.db.User.get(where("name") == "admin")
|
||||
assert admin.reference in admins.members
|
||||
|
||||
Reference in New Issue
Block a user