Add model attribute for profile completeness
This commit is contained in:
parent
891dcc5b31
commit
f8c4386d84
@ -38,6 +38,15 @@ class User(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
||||
"date_latest_training",
|
||||
]
|
||||
|
||||
@property
|
||||
def profile_complete(self):
|
||||
return all(
|
||||
[
|
||||
getattr(self, field_name) is not None
|
||||
for field_name in self.REQUIRED_FIELDS
|
||||
]
|
||||
)
|
||||
|
||||
@property
|
||||
def atat_permissions(self):
|
||||
return self.atat_role.permissions
|
||||
|
17
tests/models/test_user.py
Normal file
17
tests/models/test_user.py
Normal file
@ -0,0 +1,17 @@
|
||||
import pytest
|
||||
|
||||
from atst.models.user import User
|
||||
|
||||
from tests.factories import UserFactory
|
||||
|
||||
|
||||
def test_profile_complete_with_all_info():
|
||||
user = UserFactory.create()
|
||||
assert user.profile_complete
|
||||
|
||||
|
||||
@pytest.mark.parametrize("missing_field", User.REQUIRED_FIELDS)
|
||||
def test_profile_complete_with_missing_info(missing_field):
|
||||
user = UserFactory.create()
|
||||
setattr(user, missing_field, None)
|
||||
assert not user.profile_complete
|
Loading…
x
Reference in New Issue
Block a user