Skip to content

Commit

Permalink
update test_tickets.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 24, 2023
1 parent 3e15e85 commit ab1a1a2
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
29 changes: 29 additions & 0 deletions tests/test_tickets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
from typing import Generator, Tuple

import pytest

from .test_tags import assert_existing_tags
from zammadoo.tickets import Ticket


Expand Down Expand Up @@ -56,6 +58,11 @@ def test_ticket_state_attribute(client):
assert ticket.state == client.ticket_states(456)


def test_ticket_weburl_attripute(client):
ticket = client.tickets(123, info={"id": 123})
assert ticket.weburl == f"{client.weburl}/#ticket/zoom/123"


def test_tickets_create_body_only(rclient, temporary_resources):
with temporary_resources("tickets") as infos:
ticket = rclient.tickets.create(
Expand Down Expand Up @@ -180,3 +187,25 @@ def test_ticket_history(ticket_pair):

assert history[0].items() > {"object": "Ticket", "type": "created"}.items()
assert history[1].items() > {"object": "Ticket::Article", "type": "created"}.items()


def test_ticket_search(rclient, ticket_pair, record_log):
if record_log[1]:
time.sleep(3.0)
tickets = list(rclient.tickets.search(f"title:__pytest__"))
assert len(tickets) >= 2


def test_ticket_iter(rclient, ticket_pair):
tickets = list(rclient.tickets.iter(page=1000))
assert len(tickets) == 0


def test_ticket_tags(ticket_pair, assert_existing_tags):
ticket_a, ticket_b = ticket_pair
with assert_existing_tags("__pytest__", "__tag__"):
assert ticket_a.tags() == []
ticket_a.add_tags("__pytest__", "__tag__")
assert ticket_a.tags() == ["__pytest__", "__tag__"]
ticket_a.remove_tags("__tag__")
assert ticket_a.tags() == ["__pytest__"]
10 changes: 10 additions & 0 deletions tests/test_tickets/test_ticket_iter.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"method": "POST", "url": "https://localhost/api/v1/tickets#fixture", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "905"}, "encoding": "utf-8", "content_size": 905}
{"id":118,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67108","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T20:00:55.324Z","updated_at":"2023-10-24T20:00:55.592Z","article_ids":[171],"ticket_time_accounting_ids":[]}
{"method": "POST", "url": "https://localhost/api/v1/tickets#fixture", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "905"}, "encoding": "utf-8", "content_size": 905}
{"id":119,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67109","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T20:00:55.707Z","updated_at":"2023-10-24T20:00:55.970Z","article_ids":[172],"ticket_time_accounting_ids":[]}
{"method": "GET", "url": "https://localhost/api/v1/tickets?page=1000&per_page=10&expand=false", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "encoding": "utf-8", "content_size": 2}
[]
{"method": "DELETE", "url": "https://localhost/api/v1/tickets/118#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "text/html", "Content-Length": "0"}, "encoding": "ISO-8859-1", "content_size": 0}

{"method": "DELETE", "url": "https://localhost/api/v1/tickets/119#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "text/html", "Content-Length": "0"}, "encoding": "ISO-8859-1", "content_size": 0}

10 changes: 10 additions & 0 deletions tests/test_tickets/test_ticket_search.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"method": "POST", "url": "https://localhost/api/v1/tickets#fixture", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "905"}, "encoding": "utf-8", "content_size": 905}
{"id":116,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67106","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T19:58:06.136Z","updated_at":"2023-10-24T19:58:06.405Z","article_ids":[169],"ticket_time_accounting_ids":[]}
{"method": "POST", "url": "https://localhost/api/v1/tickets#fixture", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "905"}, "encoding": "utf-8", "content_size": 905}
{"id":117,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67107","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T19:58:06.523Z","updated_at":"2023-10-24T19:58:06.786Z","article_ids":[170],"ticket_time_accounting_ids":[]}
{"method": "GET", "url": "https://localhost/api/v1/tickets/search?query=title%3A__pytest__&page=1&per_page=10&expand=false", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "6675"}, "encoding": "utf-8", "content_size": 6675}
{"tickets":[117,116],"tickets_count":2,"assets":{"Ticket":{"117":{"id":117,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67107","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T19:58:06.523Z","updated_at":"2023-10-24T19:58:06.786Z","article_ids":[170],"ticket_time_accounting_ids":[]},"116":{"id":116,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67106","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T19:58:06.136Z","updated_at":"2023-10-24T19:58:06.405Z","article_ids":[169],"ticket_time_accounting_ids":[]}},"Group":{"1":{"id":1,"signature_id":1,"email_address_id":null,"name":"Users","assignment_timeout":null,"follow_up_possible":"yes","reopen_time_in_days":null,"follow_up_assignment":true,"active":true,"shared_drafts":true,"note":"Standard Group/Pool for Tickets.","updated_by_id":3,"created_by_id":1,"created_at":"2023-09-22T20:15:53.823Z","updated_at":"2023-10-19T04:18:40.446Z","user_ids":[3]}},"User":{"1":{"id":1,"organization_id":null,"login":"-","firstname":"-","lastname":"","email":"","image":null,"image_source":null,"web":"","phone":"","fax":"","mobile":"","department":"","street":"","zip":"","city":"","country":"","address":"","vip":false,"verified":false,"active":false,"note":"","last_login":null,"source":null,"login_failed":0,"out_of_office":false,"out_of_office_start_at":null,"out_of_office_end_at":null,"out_of_office_replacement_id":null,"preferences":{"tickets_closed":0,"tickets_open":0},"updated_by_id":3,"created_by_id":1,"created_at":"2023-09-22T20:15:52.579Z","updated_at":"2023-10-23T17:41:54.206Z","role_ids":[3],"two_factor_preference_ids":[],"organization_ids":[],"authorization_ids":[],"overview_sorting_ids":[],"group_ids":{}},"3":{"id":3,"organization_id":3,"login":"zammadoo@hephaestus.local","firstname":"zammadoo","lastname":"admin","email":"zammadoo@hephaestus.local","image":null,"image_source":null,"web":"","phone":"","fax":"","mobile":"","department":"","street":"","zip":"","city":"","country":"","address":"","vip":false,"verified":false,"active":true,"note":"","last_login":"2023-10-19T04:17:31.698Z","source":null,"login_failed":0,"out_of_office":false,"out_of_office_start_at":null,"out_of_office_end_at":null,"out_of_office_replacement_id":null,"preferences":{"notification_config":{"matrix":{"create":{"criteria":{"owned_by_me":true,"owned_by_nobody":true,"subscribed":true,"no":false},"channel":{"email":true,"online":true}},"update":{"criteria":{"owned_by_me":true,"owned_by_nobody":true,"subscribed":true,"no":false},"channel":{"email":true,"online":true}},"reminder_reached":{"criteria":{"owned_by_me":true,"owned_by_nobody":false,"subscribed":false,"no":false},"channel":{"email":true,"online":true}},"escalation":{"criteria":{"owned_by_me":true,"owned_by_nobody":false,"subscribed":false,"no":false},"channel":{"email":true,"online":true}}}},"locale":"de-de","intro":true,"tickets_closed":0,"tickets_open":2,"theme":"dark","notification_sound":{"file":"Xylo.mp3","enabled":false}},"updated_by_id":3,"created_by_id":1,"created_at":"2023-09-22T20:25:51.668Z","updated_at":"2023-10-22T19:33:20.883Z","role_ids":[1,2],"two_factor_preference_ids":[],"organization_ids":[],"authorization_ids":[],"overview_sorting_ids":[],"group_ids":{"1":["full"]}},"11":{"id":11,"organization_id":null,"login":"pytest@localhost.local","firstname":"","lastname":"","email":"pytest@localhost.local","image":null,"image_source":null,"web":"","phone":"","fax":"","mobile":"","department":null,"street":"","zip":"","city":"","country":"","address":null,"vip":false,"verified":false,"active":true,"note":"","last_login":null,"source":null,"login_failed":0,"out_of_office":false,"out_of_office_start_at":null,"out_of_office_end_at":null,"out_of_office_replacement_id":null,"preferences":{"locale":"de-de","tickets_closed":0,"tickets_open":2},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T19:42:40.673Z","updated_at":"2023-10-24T19:58:06.907Z","role_ids":[3],"two_factor_preference_ids":[],"organization_ids":[],"authorization_ids":[],"overview_sorting_ids":[],"group_ids":{}}},"Role":{"3":{"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":{}},"1":{"id":1,"name":"Admin","preferences":{},"default_at_signup":false,"active":true,"note":"To configure your system.","updated_by_id":3,"created_by_id":1,"created_at":"2023-09-22T20:15:52.702Z","updated_at":"2023-10-19T02:03:18.114Z","permission_ids":[1,43,55,65],"knowledge_base_permission_ids":[],"group_ids":{}},"2":{"id":2,"name":"Agent","preferences":{},"default_at_signup":false,"active":true,"note":"To work on Tickets.","updated_by_id":3,"created_by_id":1,"created_at":"2023-09-22T20:15:52.728Z","updated_at":"2023-10-19T02:03:18.117Z","permission_ids":[43,57,60,62,66],"knowledge_base_permission_ids":[],"group_ids":{}}},"Organization":{"3":{"id":3,"name":"zammadoo","shared":true,"domain":"","domain_assignment":false,"active":true,"vip":false,"note":"","updated_by_id":3,"created_by_id":3,"created_at":"2023-10-19T01:57:58.784Z","updated_at":"2023-10-19T04:18:40.412Z","member_ids":[3],"secondary_member_ids":[]}}}}
{"method": "DELETE", "url": "https://localhost/api/v1/tickets/116#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "text/html", "Content-Length": "0"}, "encoding": "ISO-8859-1", "content_size": 0}

{"method": "DELETE", "url": "https://localhost/api/v1/tickets/117#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "text/html", "Content-Length": "0"}, "encoding": "ISO-8859-1", "content_size": 0}

32 changes: 32 additions & 0 deletions tests/test_tickets/test_ticket_tags.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{"method": "POST", "url": "https://localhost/api/v1/tickets#fixture", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "905"}, "encoding": "utf-8", "content_size": 905}
{"id":122,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67112","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T20:05:48.586Z","updated_at":"2023-10-24T20:05:48.865Z","article_ids":[175],"ticket_time_accounting_ids":[]}
{"method": "POST", "url": "https://localhost/api/v1/tickets#fixture", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "905"}, "encoding": "utf-8", "content_size": 905}
{"id":123,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67113","title":"__pytest__","owner_id":1,"customer_id":11,"note":null,"first_response_at":null,"first_response_escalation_at":null,"first_response_in_min":null,"first_response_diff_in_min":null,"close_at":null,"close_escalation_at":null,"close_in_min":null,"close_diff_in_min":null,"update_escalation_at":null,"update_in_min":null,"update_diff_in_min":null,"last_close_at":null,"last_contact_at":null,"last_contact_agent_at":null,"last_contact_customer_at":null,"last_owner_update_at":null,"create_article_type_id":10,"create_article_sender_id":1,"article_count":1,"escalation_at":null,"pending_time":null,"type":null,"time_unit":null,"preferences":{},"updated_by_id":3,"created_by_id":3,"created_at":"2023-10-24T20:05:48.996Z","updated_at":"2023-10-24T20:05:49.257Z","article_ids":[176],"ticket_time_accounting_ids":[]}
{"method": "POST", "url": "https://localhost/api/v1/tag_list?name=__pytest__#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "encoding": "utf-8", "content_size": 2}
{}
{"method": "POST", "url": "https://localhost/api/v1/tag_list?name=__tag__#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "encoding": "utf-8", "content_size": 2}
{}
{"method": "GET", "url": "https://localhost/api/v1/tags?object=Ticket&o_id=122", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "11"}, "encoding": "utf-8", "content_size": 11}
{"tags":[]}
{"method": "POST", "url": "https://localhost/api/v1/tags/add", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "4"}, "encoding": "utf-8", "content_size": 4}
true
{"method": "POST", "url": "https://localhost/api/v1/tags/add", "status_code": 201, "reason": "Created", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "4"}, "encoding": "utf-8", "content_size": 4}
true
{"method": "GET", "url": "https://localhost/api/v1/tags?object=Ticket&o_id=122", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "33"}, "encoding": "utf-8", "content_size": 33}
{"tags":["__pytest__","__tag__"]}
{"method": "DELETE", "url": "https://localhost/api/v1/tags/remove", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "4"}, "encoding": "utf-8", "content_size": 4}
true
{"method": "GET", "url": "https://localhost/api/v1/tags?object=Ticket&o_id=122", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "23"}, "encoding": "utf-8", "content_size": 23}
{"tags":["__pytest__"]}
{"method": "GET", "url": "https://localhost/api/v1/tag_search?term=__tag__#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "30"}, "encoding": "utf-8", "content_size": 30}
[{"id":160,"value":"__tag__"}]
{"method": "DELETE", "url": "https://localhost/api/v1/tag_list/160#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "encoding": "utf-8", "content_size": 2}
{}
{"method": "GET", "url": "https://localhost/api/v1/tag_search?term=__pytest__#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "33"}, "encoding": "utf-8", "content_size": 33}
[{"id":159,"value":"__pytest__"}]
{"method": "DELETE", "url": "https://localhost/api/v1/tag_list/159#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "2"}, "encoding": "utf-8", "content_size": 2}
{}
{"method": "DELETE", "url": "https://localhost/api/v1/tickets/122#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "text/html", "Content-Length": "0"}, "encoding": "ISO-8859-1", "content_size": 0}

{"method": "DELETE", "url": "https://localhost/api/v1/tickets/123#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "text/html", "Content-Length": "0"}, "encoding": "ISO-8859-1", "content_size": 0}

Loading

0 comments on commit ab1a1a2

Please sign in to comment.