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

[Fixes #51] Bug: creating user via json_content expects username, also fixes bug when using delete user #62

Merged
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
19 changes: 17 additions & 2 deletions geonoderest/users.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import sys
import logging
from typing import Dict, Optional

from geonoderest.resources import GeonodeResourceHandler
Expand Down Expand Up @@ -157,7 +159,7 @@ def patch(

def cmd_create(
self,
username: str,
username: Optional[str] = None,
email: str = "",
first_name: str = "",
last_name: str = "",
Expand Down Expand Up @@ -208,7 +210,7 @@ def cmd_create(

def create(
self,
username: str,
username: Optional[str] = None,
email: str = "",
first_name: str = "",
last_name: str = "",
Expand All @@ -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,
Expand All @@ -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}")
Loading