-
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
1 changed file
with
33 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
from pydantic import ValidationError | ||
from ..users import User | ||
from ..roles import Role | ||
|
||
|
||
def test_user_creation(): | ||
user = User(name="John Doe", description="Test user") | ||
assert user.name == "John Doe" | ||
assert user.description == "Test user" | ||
|
||
|
||
def test_user_without_name(): | ||
with pytest.raises(ValidationError): | ||
user = User(description="Test user") | ||
|
||
|
||
def test_user_without_description(): | ||
with pytest.raises(ValidationError): | ||
user = User(name="John Doe") | ||
|
||
|
||
def test_user_with_roles(): | ||
roles = [Role(name="admin", description="Admin role"), Role(name="user", description="User role")] | ||
user = User(name="John Doe", description="Test user", roles=roles) | ||
assert user.roles == roles | ||
|
||
|
||
def test_has_role(): | ||
role = Role(name="admin", description="Admin role") | ||
user = User(name="John Doe", description="Test user", roles=[role]) | ||
assert user.has_role(role) == True | ||
assert user.has_role(Role(name="user", description="User role")) == False |