Skip to content

Commit

Permalink
add test_roles.py
Browse files Browse the repository at this point in the history
Signed-off-by: flashdagger <flashdagger@googlemail.com>
  • Loading branch information
flashdagger committed Oct 27, 2023
1 parent ab1a1a2 commit 9da13ab
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ History

* resource items are now cached when using iteration
* fromisoformat conversion in Python <3.10 supporting Zulu offset format
* :class:`roles.Roles` wrongly supported `search`

0.1.0 (2023-10-08)
------------------
Expand Down
24 changes: 24 additions & 0 deletions tests/test_roles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-


import pytest


def test_roles_create_but_cannot_delete(rclient):
role = rclient.roles(3)
assert role.name == "Customer"

properties = dict(role.view())
properties["name"] = "Clone: Customer"
new_role = rclient.roles.create(**properties)

with pytest.raises(NotImplementedError, match="roles cannot be deletet"):
new_role.delete()


def test_role_update(rclient):
role = rclient.roles(7)
assert role.name == "Clone: Customer"
updated_role = role.update(active=False)
assert updated_role.active is False
4 changes: 4 additions & 0 deletions tests/test_roles/test_role_update.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"method": "GET", "url": "https://localhost/api/v1/roles/7", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "341"}, "encoding": "utf-8", "content_size": 341}
{"id":7,"name":"Clone: Customer","preferences":{},"default_at_signup":true,"active":true,"note":"People who create Tickets ask for help.","updated_by_id":3,"created_by_id":3,"created_at":"2023-10-27T04:10:36.048Z","updated_at":"2023-10-27T04:10:36.044Z","permission_ids":[44,47,48,50,54,58],"knowledge_base_permission_ids":[],"group_ids":{}}
{"method": "PUT", "url": "https://localhost/api/v1/roles/7", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "342"}, "encoding": "utf-8", "content_size": 342}
{"active":false,"updated_by_id":3,"id":7,"name":"Clone: Customer","preferences":{},"default_at_signup":true,"note":"People who create Tickets ask for help.","created_by_id":3,"created_at":"2023-10-27T04:10:36.048Z","updated_at":"2023-10-27T04:14:25.749Z","permission_ids":[44,47,48,50,54,58],"knowledge_base_permission_ids":[],"group_ids":{}}
4 changes: 4 additions & 0 deletions tests/test_roles/test_roles_create_but_cannot_delete.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"method": "GET", "url": "https://localhost/api/v1/roles/3", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "334"}, "encoding": "utf-8", "content_size": 334}
{"id":3,"name":"Customer","preferences":{},"default_at_signup":true,"active":true,"note":"People who create Tickets ask for help.","updated_by_id":3,"created_by_id":1,"created_at":"2023-09-22T20:15:52.744Z","updated_at":"2023-09-23T03:23:14.777Z","permission_ids":[44,47,48,50,54,58],"knowledge_base_permission_ids":[],"group_ids":{}}
{"method": "POST", "url": "https://localhost/api/v1/roles", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "341"}, "encoding": "utf-8", "content_size": 341}
{"id":7,"name":"Clone: Customer","preferences":{},"default_at_signup":true,"active":true,"note":"People who create Tickets ask for help.","updated_by_id":3,"created_by_id":3,"created_at":"2023-10-27T04:10:36.048Z","updated_at":"2023-10-27T04:10:36.044Z","permission_ids":[44,47,48,50,54,58],"knowledge_base_permission_ids":[],"group_ids":{}}
6 changes: 4 additions & 2 deletions zammadoo/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, List

from .resource import NamedResource
from .resources import CreatableT, SearchableT
from .resources import CreatableT, IterableT

if TYPE_CHECKING:
from .client import Client
Expand All @@ -14,6 +14,8 @@
class Role(NamedResource):
"""Role(...)"""

default_at_signup: bool #:

@property
def groups(self) -> List["Group"]:
groups = self.parent.client.groups
Expand All @@ -28,7 +30,7 @@ def delete(self):
raise NotImplementedError("roles cannot be deletet via REST API")


class Roles(SearchableT[Role], CreatableT[Role]):
class Roles(IterableT[Role], CreatableT[Role]):
"""Roles(...)"""

_RESOURCE_TYPE = Role
Expand Down

0 comments on commit 9da13ab

Please sign in to comment.