def test_user_save(session): # pylint: disable=unused-argument """Assert User record is saved.""" user = User(username='******', keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04') user.save() assert user.id is not None
def sign_up(self, request, *args, **kwargs): """Post method <api>/auth/sign_up/ Returns: User model with auth_token field or 400 if password too weak. Raises: Validation if not all fields are present in request data. """ serializer = UserAuthSignUpSerializer(data=request.data) serializer.is_valid(raise_exception=True) user = User( username=serializer.validated_data["email"], email=serializer.validated_data["email"], first_name=serializer.validated_data["first_name"], last_name=serializer.validated_data["last_name"], ) try: validate_password(serializer.validated_data["password"], user=user) except ValidationError as e: return Response(data=e, status=status.HTTP_400_BAD_REQUEST) user.set_password(serializer.validated_data["password"]) user.save() return Response( self.serializer_class(user, context={ "request": request }).data)
def test_user_delete(session): """Assert the User record is deleted.""" user = User(username='******', roles='{edit, uma_authorization, staff}') user.save() user.delete() assert user.id is not None
def factory_user_model(username, roles, keycloak_guid): """Return a valid user object stamped with the supplied designation.""" from auth_api.models import User as UserModel user = UserModel(username=username, roles=roles, keycloak_guid=keycloak_guid) user.save() return user
def test_user_delete(session): # pylint: disable=unused-argument """Assert the User record is deleted.""" user = User(username='******', roles='{edit, uma_authorization, staff}', keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04') user.save() user.delete() assert user.id is not None
def factory_user_model(username, firstname=None, lastname=None, roles=None, keycloak_guid=None): """Return a valid user object stamped with the supplied designation.""" user = UserModel(username=username, firstname=firstname, lastname=lastname, roles=roles, keycloak_guid=keycloak_guid) user.save() return user