diff --git a/geonoderest/users.py b/geonoderest/users.py index 6c54ef8..fb2b1f3 100644 --- a/geonoderest/users.py +++ b/geonoderest/users.py @@ -1,4 +1,6 @@ import json +import sys +import logging from typing import Dict, Optional from geonoderest.resources import GeonodeResourceHandler @@ -157,7 +159,7 @@ def patch( def cmd_create( self, - username: str, + username: Optional[str] = None, email: str = "", first_name: str = "", last_name: str = "", @@ -208,7 +210,7 @@ def cmd_create( def create( self, - username: str, + username: Optional[str] = None, email: str = "", first_name: str = "", last_name: str = "", @@ -231,6 +233,10 @@ def create( json_content (dict) dict object with addition metadata / fields """ if json_content is None: + if username is None: + logging.error("missing username for user creation ...") + sys.exit(1) + json_content = { "username": username, "email": email, @@ -243,3 +249,12 @@ def create( endpoint=self.ENDPOINT_NAME, params=json_content, ) + + def cmd_delete(self, pk: int, **kwargs): + self.delete(pk=pk, **kwargs) + print(f"{self.JSON_OBJECT_NAME}: {pk} deleted ...") + + def delete(self, pk: int, **kwargs): + """delete geonode resource object""" + self.http_get(endpoint=f"{self.ENDPOINT_NAME}/{pk}") + self.http_delete(endpoint=f"users/{pk}")