Skip to content

Commit 2c92b1f

Browse files
[Fixes #38]: "Feature: implement /api/v2/groups/ "
1 parent 0f71f01 commit 2c92b1f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/geonoderest/groups.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
class GeonodeGroupsHandler(GeonodeObjectHandler):
1515
ENDPOINT_NAME = "groups"
16-
JSON_OBJECT_NAME = "groups"
17-
SINGULAR_RESOURCE_NAME = "group"
16+
JSON_OBJECT_NAME = "group_profiles"
17+
SINGULAR_RESOURCE_NAME = "group_profile"
1818

1919
LIST_CMDOUT_HEADER: List[GeonodeCmdOutListKey] = [
2020
GeonodeCmdOutListKey(key="pk"),
2121
GeonodeCmdOutListKey(key="title"),
22-
GeonodeCmdOutListKey(key="name"),
22+
GeonodeCmdOutListKey(key="slug"),
2323
GeonodeCmdOutListKey(key="description"),
2424
]
2525

@@ -102,10 +102,9 @@ def create(
102102
sys.exit(1)
103103
json_content = {
104104
"title": title,
105+
"slug": name if name is not None else title.lower().replace(" ", "-"),
105106
"description": description,
106107
}
107-
if name is not None:
108-
json_content["name"] = name
109108

110109
return self.http_post(
111110
endpoint=self.ENDPOINT_NAME,

tests/test_groups.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class TestGeonodeGroupsHandler(unittest.TestCase):
1010
def test_list(self, mock_http_get):
1111
"""Ensure list calls the groups endpoint and returns groups list."""
1212
mock_http_get.return_value = {
13-
"groups": [
14-
{"pk": 1, "title": "Group A", "name": "group-a", "description": ""},
15-
{"pk": 2, "title": "Group B", "name": "group-b", "description": ""},
13+
"group_profiles": [
14+
{"pk": 1, "title": "Group A", "slug": "group-a", "description": ""},
15+
{"pk": 2, "title": "Group B", "slug": "group-b", "description": ""},
1616
]
1717
}
1818
handler = GeonodeGroupsHandler(env={})
@@ -23,9 +23,14 @@ def test_list(self, mock_http_get):
2323

2424
@patch.object(GeonodeGroupsHandler, "http_get")
2525
def test_get(self, mock_http_get):
26-
"""Ensure get returns the 'group' dict from the API response."""
26+
"""Ensure get returns the 'group_profile' dict from the API response."""
2727
mock_http_get.return_value = {
28-
"group": {"pk": 1, "title": "Group A", "name": "group-a", "description": ""}
28+
"group_profile": {
29+
"pk": 1,
30+
"title": "Group A",
31+
"slug": "group-a",
32+
"description": "",
33+
}
2934
}
3035
handler = GeonodeGroupsHandler(env={})
3136
result = handler.get(1)
@@ -62,7 +67,7 @@ def test_create_with_title(self, mock_http_post):
6267
)
6368
mock_http_post.assert_called_once_with(
6469
endpoint="groups",
65-
json={"title": "New Group", "description": "A desc", "name": "new-group"},
70+
json={"title": "New Group", "slug": "new-group", "description": "A desc"},
6671
)
6772
self.assertEqual(result["pk"], 5)
6873

0 commit comments

Comments
 (0)