Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
zopyx committed May 19, 2024
1 parent 0b5c31f commit cab71bb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fastapi_auth/tests/test_users.py
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

0 comments on commit cab71bb

Please sign in to comment.