Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issue with serializing default permissions #10

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions neon_data_models/models/user/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class PermissionsConfig(BaseModel):

class Config:
use_enum_values = True
validate_default = True

@classmethod
def from_roles(cls, roles: List[str]):
Expand Down
14 changes: 13 additions & 1 deletion tests/models/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_neon_user_config(self):
self.assertIsInstance(config.user.dob, date)

def test_user(self):
from neon_data_models.enum import AccessRoles
user_kwargs = dict(username="test",
password_hash="test",
tokens=[{"token_name": "test_token",
Expand All @@ -98,6 +99,11 @@ def test_user(self):
"last_refresh_timestamp": round(time())}])
default_user = User(**user_kwargs)
self.assertIsInstance(default_user.tokens[0], HanaToken)

dumped = default_user.model_dump()
for perm in dumped['permissions']:
self.assertEqual(int, type(dumped['permissions'][perm]), perm)
self.assertIsInstance(AccessRoles(dumped['permissions'][perm]), AccessRoles, perm)
with self.assertRaises(ValidationError):
User()

Expand All @@ -124,8 +130,14 @@ def test_permissions_config(self):
node=AccessRoles.NODE,
hub=AccessRoles.NODE,
llm=AccessRoles.NONE)

# Test dumped enums
dumped = test_config.model_dump()
for key, value in dumped.items():
self.assertEqual(type(value), int, key)

# Test dump/load
self.assertEqual(PermissionsConfig(**test_config.model_dump()),
self.assertEqual(PermissionsConfig(**dumped),
test_config)

# Test to/from roles
Expand Down
Loading