def test_serialize(self): user_model = User( first_name="Foo", last_name="Bar", username="******", password="******", email=TEST_EMAIL, roles=[self.role], created_on=timezone.parse(DEFAULT_TIME), changed_on=timezone.parse(DEFAULT_TIME), ) self.session.add(user_model) self.session.commit() user = self.session.query(User).filter( User.email == TEST_EMAIL).first() deserialized_user = user_collection_item_schema.dump(user) # No user_id and password in dump assert deserialized_user == { 'created_on': DEFAULT_TIME, 'email': '*****@*****.**', 'changed_on': DEFAULT_TIME, 'active': None, 'last_login': None, 'last_name': 'Bar', 'fail_login_count': None, 'first_name': 'Foo', 'username': '******', 'login_count': None, 'roles': [{ 'name': 'TestRole' }], }
def get_user(*, username: str) -> APIResponse: """Get a user""" ab_security_manager = current_app.appbuilder.sm user = ab_security_manager.find_user(username=username) if not user: raise NotFound(title="User not found", detail=f"The User with username `{username}` was not found") return user_collection_item_schema.dump(user)