def test_get_existing_tickets(self, mock_show_ticket): ticket = z_api.ZTicket(id=10, channel="web", created_at="2017-07-15T06:08:25Z", subject="I need some homes.", description="Buying a home.", status="open", requester=z_api.ZUser(id=1022, name="James Fish", email="*****@*****.**"), submitter=z_api.ZUser(id=1022, name="James Fish", email="*****@*****.**"), assignee=z_api.ZUser( id=114273319939, name="Apoorv Kansal", email="*****@*****.**")) mock_show_ticket.return_value = ticket response = client.get(reverse('show-ticket', kwargs={'id': 10})) # Check status code of response to be 200 self.assertEquals(response.status_code, 200) # Check json data returned is the expected json data. expected_json_output = { 'id': 10, 'channel': 'web', 'created_at': '2017-07-15T06:08:25Z', 'subject': 'I need some homes.', 'description': 'Buying a home.', 'status': 'open', 'requester': { 'id': 1022, 'name': 'James Fish', 'email': '*****@*****.**' }, 'submitter': { 'id': 1022, 'name': 'James Fish', 'email': '*****@*****.**' }, 'assignee': { 'id': 114273319939, 'name': 'Apoorv Kansal', 'email': '*****@*****.**' } } self.assertEquals(expected_json_output, response.data)
def test_get_existing_tickets(self, mock_list_tickets): first_page_tickets = [ z_api.ZTicket(id=10, channel="web", created_at="2017-07-15T06:08:25Z", subject="I need some homes.", description="Buying a home.", status="open", requester=z_api.ZUser(id=1022, name="James Fish", email="*****@*****.**"), submitter=z_api.ZUser(id=1022, name="James Fish", email="*****@*****.**"), assignee=z_api.ZUser( id=114273319939, name="Apoorv Kansal", email="*****@*****.**")), z_api.ZTicket(id=11, channel="api", created_at="2017-07-14T06:08:25Z", subject="Help home burning.", description="My home is destroyed :(", status="pending", requester=z_api.ZUser(id=1032, name="Sally Fish", email="*****@*****.**"), submitter=z_api.ZUser(id=1022, name="Sally Fish", email="*****@*****.**"), assignee=z_api.ZUser( id=114273319939, name="Apoorv Kansal", email="*****@*****.**")), z_api.ZTicket( id=12, channel="web", created_at="2017-07-13T06:08:25Z", subject="Selling homes.", description= "It's time to move on so I shall sell my homes today.", status="open", requester=z_api.ZUser(id=10672, name="Grass Hopper", email="*****@*****.**"), submitter=z_api.ZUser(id=1022, name="Grass Hopper", email="*****@*****.**"), assignee=z_api.ZUser(id=114273319939, name="Apoorv Kansal", email="*****@*****.**")) ] total_tickets = 100 mock_list_tickets.return_value = [first_page_tickets, total_tickets] response = client.get('{}?{}'.format( reverse('list-tickets'), urllib.parse.urlencode({'page': 1}))) # Check status code of response to be 200 self.assertEquals(response.status_code, 200) # Check json data returned is the expected json data. expected_json_output = { 'tickets': [{ 'id': 10, 'channel': 'web', 'created_at': '2017-07-15T06:08:25Z', 'subject': 'I need some homes.', 'description': 'Buying a home.', 'status': 'open', 'requester': { 'id': 1022, 'name': 'James Fish', 'email': '*****@*****.**' }, 'submitter': { 'id': 1022, 'name': 'James Fish', 'email': '*****@*****.**' }, 'assignee': { 'id': 114273319939, 'name': 'Apoorv Kansal', 'email': '*****@*****.**' } }, { 'id': 11, 'channel': 'api', 'created_at': '2017-07-14T06:08:25Z', 'subject': 'Help home burning.', 'description': 'My home is destroyed :(', 'status': 'pending', 'requester': { 'id': 1032, 'name': 'Sally Fish', 'email': '*****@*****.**' }, 'submitter': { 'id': 1022, 'name': 'Sally Fish', 'email': '*****@*****.**' }, 'assignee': { 'id': 114273319939, 'name': 'Apoorv Kansal', 'email': '*****@*****.**' } }, { 'id': 12, 'channel': 'web', 'created_at': '2017-07-13T06:08:25Z', 'subject': 'Selling homes.', 'description': "It's time to move on so I shall sell my homes today.", 'status': 'open', 'requester': { 'id': 10672, 'name': 'Grass Hopper', 'email': '*****@*****.**' }, 'submitter': { 'id': 1022, 'name': 'Grass Hopper', 'email': '*****@*****.**' }, 'assignee': { 'id': 114273319939, 'name': 'Apoorv Kansal', 'email': '*****@*****.**' } }], 'count': 100 } self.assertEquals(expected_json_output, response.data)
def test_get_existing_comments(self, mock_list_comments): first_page_comments = [ z_api.ZComment(id=10, type="Comment", body="A really BIG home.", channel="web", created_at="2017-07-15T06:19:41Z", author=z_api.ZUser(id=114273319939, name="Apoorv Kansal")), z_api.ZComment(id=102, type="Comment", body="Okay yes what are you after?", channel="web", created_at="2017-07-15T06:06:41Z", author=z_api.ZUser(id=114273311932, name="Vimal Kansal")), z_api.ZComment( id=14, type="Comment", body="I need help in home making.", channel="api", created_at="2017-07-14T06:06:41Z", author=z_api.ZUser(id=114273379932, name="Rita Kansal"), attachments=[ z_api.ZAttachment( id=982, content_url= "https://homesrus-aus.zendesk.com/attachments/token/07rnDsQPHFvf1npZcElWc6GWu/?name=photo.jpg" ) ]) ] total_comments = 10 mock_list_comments.return_value = [first_page_comments, total_comments] response = client.get('{}?{}'.format( reverse('list-comments', kwargs={'ticket_id': 1}), urllib.parse.urlencode({'page': 1}))) # Check status code of response to be 200 self.assertEquals(response.status_code, 200) # Check json data returned is the expected json data. expected_json_output = { 'comments': [{ 'id': 10, 'type': 'Comment', 'body': 'A really BIG home.', 'channel': 'web', 'created_at': '2017-07-15T06:19:41Z', 'author': { 'id': 114273319939, 'name': 'Apoorv Kansal' } }, { 'id': 102, 'type': 'Comment', 'body': 'Okay yes what are you after?', 'channel': 'web', 'created_at': '2017-07-15T06:06:41Z', 'author': { 'id': 114273311932, 'name': 'Vimal Kansal' } }, { 'id': 14, 'type': 'Comment', 'body': 'I need help in home making.', 'channel': 'api', 'created_at': '2017-07-14T06:06:41Z', 'author': { 'id': 114273379932, 'name': 'Rita Kansal' }, 'attachments': [{ 'id': 982, 'content_url': 'https://homesrus-aus.zendesk.com/attachments/token/07rnDsQPHFvf1npZcElWc6GWu/?name=photo.jpg' }] }], 'count': 10 } self.assertEquals(expected_json_output, response.data)