Skip to content

Commit

Permalink
rewrite test_ticket_create_article_sender_attribute
Browse files Browse the repository at this point in the history
Signed-off-by: flashdagger <flashdagger@googlemail.com>
  • Loading branch information
flashdagger committed Oct 30, 2023
1 parent 774e164 commit 18e53d8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
20 changes: 6 additions & 14 deletions tests/test_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@
from . import assert_existing_tags, ticket_pair


def test_ticket_create_article_sender_attribute(client):
ticket = client.tickets(123, info={"id": 123, "create_article_sender_id": 1})
assert ticket.create_article_sender == "Agent"

ticket = client.tickets(123, info={"id": 123, "create_article_sender_id": 2})
assert ticket.create_article_sender == "Customer"

ticket = client.tickets(123, info={"id": 123, "create_article_sender_id": 3})
assert ticket.create_article_sender == "System"

ticket = client.tickets(123, info={"id": 123, "create_article_sender_id": 4})
assert ticket.create_article_sender == "Unknown"


def test_ticket_customer_attribute(client):
ticket = client.tickets(123, info={"id": 123, "customer_id": 456})
assert ticket.customer == client.users(456)
Expand Down Expand Up @@ -182,3 +168,9 @@ def test_ticket_tags(ticket_pair, assert_existing_tags):
assert ticket_a.tags() == ["__pytest__", "__tag__"]
ticket_a.remove_tags("__tag__")
assert ticket_a.tags() == ["__pytest__"]


def test_ticket_create_article_sender_and_type_attribute(ticket_pair):
ticket_a, ticket_b = ticket_pair
assert ticket_a.create_article_sender == "Agent"
assert ticket_b.create_article_type == "note"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{"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":196,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67186","title":"__pytest__","owner_id":1,"customer_id":14,"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-30T19:19:07.318Z","updated_at":"2023-10-30T19:19:07.579Z","article_ids":[301],"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":197,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67187","title":"__pytest__","owner_id":1,"customer_id":14,"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-30T19:19:07.704Z","updated_at":"2023-10-30T19:19:07.932Z","article_ids":[302],"ticket_time_accounting_ids":[]}
{"method": "GET", "url": "https://localhost/api/v1/tickets/196?expand=true", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "1176"}, "encoding": "utf-8", "content_size": 1176}
{"id":196,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67186","title":"__pytest__","owner_id":1,"customer_id":14,"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-30T19:19:07.318Z","updated_at":"2023-10-30T19:19:07.579Z","article_ids":[301],"ticket_time_accounting_ids":[],"group":"Users","ticket_time_accounting":[],"state":"new","priority":"2 normal","owner":"-","customer":"pytest@localhost.local","created_by":"zammadoo@hephaestus.local","updated_by":"zammadoo@hephaestus.local","create_article_type":"note","create_article_sender":"Agent"}
{"method": "GET", "url": "https://localhost/api/v1/tickets/197?expand=true", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "application/json; charset=utf-8", "Content-Length": "1176"}, "encoding": "utf-8", "content_size": 1176}
{"id":197,"group_id":1,"priority_id":2,"state_id":1,"organization_id":null,"number":"67187","title":"__pytest__","owner_id":1,"customer_id":14,"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-30T19:19:07.704Z","updated_at":"2023-10-30T19:19:07.932Z","article_ids":[302],"ticket_time_accounting_ids":[],"group":"Users","ticket_time_accounting":[],"state":"new","priority":"2 normal","owner":"-","customer":"pytest@localhost.local","created_by":"zammadoo@hephaestus.local","updated_by":"zammadoo@hephaestus.local","create_article_type":"note","create_article_sender":"Agent"}
{"method": "DELETE", "url": "https://localhost/api/v1/tickets/196#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/197#fixture", "status_code": 200, "reason": "OK", "headers": {"Content-Type": "text/html", "Content-Length": "0"}, "encoding": "ISO-8859-1", "content_size": 0}

6 changes: 0 additions & 6 deletions zammadoo/articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ def iter_bytes(self, chunk_size=8192) -> Iterator[bytes]:
class Article(Resource):
"""Article(...)"""

SENDER_MAP = {
1: "Agent",
2: "Customer",
3: "System",
}

body: str #:
cc: Optional[str] #:
content_type: str #:
Expand Down
13 changes: 10 additions & 3 deletions zammadoo/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .articles import Article
from .resource import MutableResource, NamedResource
from .resources import CreatableT, IterableT, SearchableT, _T_co
from .utils import LINK_TYPES, LinkType
from .utils import LINK_TYPES, LinkType, info_cast

if TYPE_CHECKING:
from .articles import OptionalFiles
Expand Down Expand Up @@ -95,8 +95,15 @@ class Ticket(MutableResource):

@property
def create_article_sender(self) -> str:
casid = self["create_article_sender_id"]
return Article.SENDER_MAP.get(casid, "Unknown")
if "create_article_sender" not in self._info:
self.reload(expand=True)
return info_cast(self._info)["create_article_sender"]

@property
def create_article_type(self) -> str:
if "create_article_type" not in self._info:
self.reload(expand=True)
return info_cast(self._info)["create_article_type"]

@property
def customer(self) -> "User":
Expand Down
2 changes: 2 additions & 0 deletions zammadoo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class TypedTag(TypedDict):


class TypedInfo(TypedDict, total=False):
create_article_sender: str
create_article_type: str
id: int
name: str
login: str
Expand Down

0 comments on commit 18e53d8

Please sign in to comment.