From 7281fed719729a2fd407a997679d70e2eaf61bee Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 18 Sep 2019 14:24:37 -0400 Subject: [PATCH] Test JSON data without relying on arbitrary ordering. BOM-735 --- .../zendesk_proxy/tests/test_v1_views.py | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py b/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py index d66db7acd3..d7f5525a45 100644 --- a/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py +++ b/openedx/core/djangoapps/zendesk_proxy/tests/test_v1_views.py @@ -1,16 +1,19 @@ """Tests for zendesk_proxy views.""" + from __future__ import absolute_import -import json + from copy import deepcopy +import json import ddt from django.urls import reverse from django.test.utils import override_settings from mock import MagicMock, patch +import six +from six.moves import range from openedx.core.djangoapps.zendesk_proxy.v1.views import ZendeskProxyThrottle from openedx.core.lib.api.test_utils import ApiTestCase -from six.moves import range @ddt.ddt @@ -53,14 +56,30 @@ class ZendeskProxyTestCase(ApiTestCase): self.assertHttpCreated(response) (mock_args, mock_kwargs) = mock_post.call_args self.assertEqual(mock_args, ('https://www.superrealurlsthataredefinitelynotfake.com/api/v2/tickets.json',)) + six.assertCountEqual(self, mock_kwargs.keys(), ['headers', 'data']) self.assertEqual( - mock_kwargs, + mock_kwargs['headers'], { - 'headers': { - 'content-type': 'application/json', - 'Authorization': 'Bearer abcdefghijklmnopqrstuvwxyz1234567890' + 'content-type': 'application/json', + 'Authorization': 'Bearer abcdefghijklmnopqrstuvwxyz1234567890' + } + ) + self.assertEqual( + json.loads(mock_kwargs['data']), + { + 'ticket': { + 'comment': { + 'body': "Help! I'm trapped in a unit test factory and I can't get out!", + 'uploads': None, + }, + 'custom_fields': [{'id': '001', 'value': 'demo-course'}], + 'requester': { + 'email': 'JohnQStudent@example.com', + 'name': 'John Q. Student', + }, + 'subject': 'Python Unit Test Help Request', + 'tags': ['python_unit_test'], }, - 'data': '{"ticket": {"comment": {"body": "Help! I\'m trapped in a unit test factory and I can\'t get out!", "uploads": null}, "tags": ["python_unit_test"], "subject": "Python Unit Test Help Request", "custom_fields": [{"id": "001", "value": "demo-course"}], "requester": {"name": "John Q. Student", "email": "JohnQStudent@example.com"}}}' # pylint: disable=line-too-long } )