-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from pydantic import BaseModel | ||
from pydantic import BaseModel, Field | ||
|
||
from typeguard import typechecked | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
|
||
from ..permissions import Permission | ||
|
||
from pydantic import ValidationError | ||
|
||
|
||
def test_permission_creation(): | ||
permission = Permission(name="read", description="Can read data") | ||
assert permission.name == "read" | ||
assert permission.description == "Can read data" | ||
|
||
|
||
def test_permission_without_name(): | ||
with pytest.raises(ValidationError): | ||
permission = Permission(description="Can read data") | ||
|
||
|
||
def test_permission_without_description(): | ||
with pytest.raises(ValidationError): | ||
permission = Permission(name="read") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
from ..roles import Role | ||
from ..permissions import Permission | ||
|
||
|
||
from pydantic import ValidationError | ||
|
||
|
||
def test_role_creation(): | ||
role = Role(name="admin", description="Admin role") | ||
assert role.name == "admin" | ||
assert role.description == "Admin role" | ||
|
||
|
||
def test_role_without_name(): | ||
with pytest.raises(ValidationError): | ||
role = Role(description="Admin role") | ||
|
||
|
||
def test_role_without_description(): | ||
with pytest.raises(ValidationError): | ||
role = Role(name="admin") | ||
|
||
|
||
def test_role_with_permissions(): | ||
permissions = [ | ||
Permission(name="read", description="Can read data"), | ||
Permission(name="write", description="Can write data"), | ||
] | ||
role = Role(name="admin", description="Admin role", permissions=permissions) | ||
assert role.permissions == permissions | ||
|
||
|
||
def test_role_creation(): | ||
perm1 = Permission(name="read", description="Read permission") | ||
perm2 = Permission(name="write", description="Write permission") | ||
role = Role(name="admin", description="Adminstrator role", permissions=[perm1, perm2]) | ||
assert role.name == "admin" | ||
|
||
assert perm1 in role.permissions | ||
assert perm2 in role.permissions | ||
|
||
perm3 = Permission(name="delete", description="Delete permission") | ||
assert perm3 not in role.permissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
from typing import Optional | ||
|
||
from .roles import Role | ||
|
||
|