-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and complete test_priorities.py
Signed-off-by: flashdagger <flashdagger@googlemail.com>
- Loading branch information
1 parent
0aa0bf7
commit 246abcb
Showing
6 changed files
with
62 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,45 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: UTF-8 -*- | ||
|
||
from contextlib import contextmanager | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def assert_existing_priorities(zammad_api): | ||
def _cleanup(names): | ||
priority_map = {} | ||
priority_map.update( | ||
(info["name"], info["id"]) | ||
for info in zammad_api("GET", "ticket_priorities").json() | ||
) | ||
for name in names: | ||
priority_id = priority_map.get(name) | ||
if not priority_id: | ||
continue | ||
zammad_api("DELETE", f"ticket_priorities/{priority_id}") | ||
|
||
@contextmanager | ||
def _create_temporary(*names, delete=()): | ||
temporary_priorities = set(delete) | ||
_cleanup(temporary_priorities) | ||
|
||
for priority_name in names: | ||
if priority_name not in temporary_priorities: | ||
zammad_api( | ||
"POST", | ||
"ticket_priorities", | ||
{"name": priority_name, "note": "pytest"}, | ||
) | ||
temporary_priorities.add(priority_name) | ||
|
||
yield | ||
|
||
_cleanup(temporary_priorities) | ||
|
||
return _create_temporary | ||
|
||
|
||
def test_create_and_update_priority(rclient, assert_existing_priorities): | ||
with assert_existing_priorities(delete={"pytest_prio"}): | ||
new_priority = rclient.ticket_priorities.create("pytest_prio") | ||
def test_create_priority(rclient, temporary_resources): | ||
with temporary_resources("ticket_priorities") as priorities: | ||
new_priority = rclient.ticket_priorities.create("pytest_priority") | ||
priorities.append(new_priority.view()) | ||
assert new_priority.active is True | ||
updated_priority = new_priority.update(active=False) | ||
assert new_priority.note is None | ||
assert new_priority.default_create is False | ||
assert new_priority.ui_icon is None | ||
assert new_priority.ui_color is None | ||
|
||
|
||
def test_update_priority(rclient, temporary_resources): | ||
with temporary_resources("ticket_priorities", {"name": "pytest_priority"}) as infos: | ||
info = infos[0] | ||
priority = rclient.ticket_priorities(info["id"], info=info) | ||
assert priority.active is True | ||
updated_priority = priority.update(active=False) | ||
assert updated_priority.active is False | ||
|
||
|
||
def test_update_priority_with_reload(rclient, temporary_resources): | ||
with temporary_resources("ticket_priorities", {"name": "pytest_priority"}) as infos: | ||
info = infos[0] | ||
priority = rclient.ticket_priorities(info["id"], info=info) | ||
assert priority.active is True | ||
priority.update(active=False) | ||
priority.reload() | ||
assert priority.active is False | ||
|
||
|
||
def test_delete_priority(rclient, temporary_resources): | ||
from zammadoo import APIException | ||
|
||
with temporary_resources("ticket_priorities", {"name": "pytest_priority"}) as infos: | ||
info = infos[0] | ||
priority = rclient.ticket_priorities(info["id"], info=info) | ||
priority.delete() | ||
with pytest.raises(APIException, match="Couldn't find Ticket::Priority"): | ||
priority.reload() | ||
infos.clear() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"method": "POST", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "230"}, "url": "https://localhost/api/v1/ticket_priorities", "status_code": 201, "encoding": "utf-8", "reason": "Created", "content_size": 230} | ||
{"id":14,"name":"pytest_priority","default_create":false,"ui_icon":null,"ui_color":null,"note":null,"active":true,"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-23T19:08:57.516Z","updated_at":"2023-10-23T19:08:57.516Z"} | ||
{"method": "DELETE", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "url": "https://localhost/api/v1/ticket_priorities/14#fixture", "status_code": 200, "encoding": "utf-8", "reason": "OK", "content_size": 2} | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"method": "POST", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "230"}, "url": "https://localhost/api/v1/ticket_priorities#fixture", "status_code": 201, "encoding": "utf-8", "reason": "Created", "content_size": 230} | ||
{"id":17,"name":"pytest_priority","default_create":false,"ui_icon":null,"ui_color":null,"note":null,"active":true,"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-23T19:08:58.814Z","updated_at":"2023-10-23T19:08:58.814Z"} | ||
{"method": "DELETE", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "url": "https://localhost/api/v1/ticket_priorities/17", "status_code": 200, "encoding": "utf-8", "reason": "OK", "content_size": 2} | ||
{} | ||
{"method": "GET", "headers": {"Content-Type": "application/json; charset=utf-8"}, "url": "https://localhost/api/v1/ticket_priorities/17", "status_code": 404, "encoding": "utf-8", "reason": "Not Found", "content_size": 115} | ||
{"error":"Couldn't find Ticket::Priority with 'id'=17","error_human":"Couldn't find Ticket::Priority with 'id'=17"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"method": "POST", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "230"}, "url": "https://localhost/api/v1/ticket_priorities#fixture", "status_code": 201, "encoding": "utf-8", "reason": "Created", "content_size": 230} | ||
{"id":15,"name":"pytest_priority","default_create":false,"ui_icon":null,"ui_color":null,"note":null,"active":true,"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-23T19:08:57.821Z","updated_at":"2023-10-23T19:08:57.821Z"} | ||
{"method": "PUT", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "231"}, "url": "https://localhost/api/v1/ticket_priorities/15", "status_code": 200, "encoding": "utf-8", "reason": "OK", "content_size": 231} | ||
{"active":false,"updated_by_id":3,"id":15,"name":"pytest_priority","default_create":false,"ui_icon":null,"ui_color":null,"note":null,"created_by_id":3,"created_at":"2023-10-23T19:08:57.821Z","updated_at":"2023-10-23T19:08:57.952Z"} | ||
{"method": "DELETE", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "url": "https://localhost/api/v1/ticket_priorities/15#fixture", "status_code": 200, "encoding": "utf-8", "reason": "OK", "content_size": 2} | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{"method": "POST", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "230"}, "url": "https://localhost/api/v1/ticket_priorities#fixture", "status_code": 201, "encoding": "utf-8", "reason": "Created", "content_size": 230} | ||
{"id":16,"name":"pytest_priority","default_create":false,"ui_icon":null,"ui_color":null,"note":null,"active":true,"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-23T19:08:58.220Z","updated_at":"2023-10-23T19:08:58.220Z"} | ||
{"method": "PUT", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "231"}, "url": "https://localhost/api/v1/ticket_priorities/16", "status_code": 200, "encoding": "utf-8", "reason": "OK", "content_size": 231} | ||
{"active":false,"updated_by_id":3,"id":16,"name":"pytest_priority","default_create":false,"ui_icon":null,"ui_color":null,"note":null,"created_by_id":3,"created_at":"2023-10-23T19:08:58.220Z","updated_at":"2023-10-23T19:08:58.439Z"} | ||
{"method": "GET", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "231"}, "url": "https://localhost/api/v1/ticket_priorities/16", "status_code": 200, "encoding": "utf-8", "reason": "OK", "content_size": 231} | ||
{"active":false,"updated_by_id":3,"id":16,"name":"pytest_priority","default_create":false,"ui_icon":null,"ui_color":null,"note":null,"created_by_id":3,"created_at":"2023-10-23T19:08:58.220Z","updated_at":"2023-10-23T19:08:58.439Z"} | ||
{"method": "DELETE", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "url": "https://localhost/api/v1/ticket_priorities/16#fixture", "status_code": 200, "encoding": "utf-8", "reason": "OK", "content_size": 2} | ||
{} |