-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
155 lines (117 loc) · 4.75 KB
/
tests.py
File metadata and controls
155 lines (117 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Name: Kat Kime
# Date: 8/1/2021
# Description: Tests the ticket viewer program.
import unittest
import ticket_viewer
import ticket_database
import Constants
"""
Specifications:
-- Connects to the Zendesk API
-- Requests all the tickets for your account
-- Displays tickets in a list
-- Displays individual ticket details
-- Pages through tickets when more than 25 are returned
- Displays a friendly error message if the API is unavailable or the response is
invalid.
-- Tells the user something is wrong if there is a program error.
-- The Ticket Viewer should handle the API being unavailable
"""
class TestCase(unittest.TestCase):
def test_1_API(self):
"""
Tests that get_tickets connects to the Zendesk API.
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
expected = dict
self.assertEqual(expected, type(ticket_viewer.get_tickets(authorization, domain)))
def test_2_list(self):
"""
Tests that display_table prints a table of Zendesk tickets.
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
tickets.display_tickets()
def test_3_details(self):
"""
Tests that the ticket viewer creates and returns a string object with user details when prompted.
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
ticket_id = 1
expected = str
print(tickets.get_ticket_details(ticket_id))
self.assertEqual(expected, type(tickets.get_ticket_details(ticket_id)))
def test_4_next(self):
"""
Tests that the ticket viewer displays the next page of tickets when prompted.
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
# test that final displayed ticket is greater than original ticket
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
start = tickets.display_tickets()
end = tickets.view_next_page(start)
expected = True
self.assertEqual(expected, end - start > 0)
def test_6_execute_details(self):
"""
Tests that execute_command() returns -1 when view details is selected
"""
command = 'view'
ticket_id = 5
expected = -1
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
self.assertEqual(expected, tickets.execute_command(command, ticket_id))
def test_7_excute_next(self):
"""
Tests that execute_command() returns a number greater than -1 when view details is selected
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
command = 'next'
ticket_id = 5
expected = True
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
self.assertEqual(expected, tickets.execute_command(command, ticket_id) > ticket_id)
def test_5_bad_API(self):
"""
Tests that the ticket viewer displays an error and exits when the API cannot be reached.
"""
authorization = "bad key"
domain = Constants.DOMAIN
tickets = ticket_viewer.get_tickets(authorization, domain)
expected = None
self.assertEqual(expected, tickets)
def test_9_good_data(self):
"""
Tests that program runs successfully when good data is given.
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
def test_10_bad_ticket_number(self):
"""
Tests that program responds accordingly when user feeds a number that's larger than database
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
n = 1000
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
tickets.get_ticket_details(n)
def test_11_bad_data_input(self):
"""
Tests that exception is caught when user enters invalid ticket id.
"""
authorization = Constants.AUTHORIZATION_KEY
domain = Constants.DOMAIN
command = 'view'
tid = 5
n = 'stuff'
tickets = ticket_database.Tickets(ticket_viewer.get_tickets(authorization, domain))
tickets.execute_command(command, tid)