From 8fc31b42e34f1c552775d793f5a1f8ef0f6d8d24 Mon Sep 17 00:00:00 2001 From: asadiqbal Date: Thu, 11 May 2017 15:05:23 +0500 Subject: [PATCH] ENT-374 Support ticket is created without enterprise tags for Anonymous users. --- .../util/tests/test_submit_feedback.py | 42 +++++++++++++++++++ openedx/features/enterprise_support/api.py | 3 ++ 2 files changed, 45 insertions(+) diff --git a/common/djangoapps/util/tests/test_submit_feedback.py b/common/djangoapps/util/tests/test_submit_feedback.py index 761046342f..e43dc04684 100644 --- a/common/djangoapps/util/tests/test_submit_feedback.py +++ b/common/djangoapps/util/tests/test_submit_feedback.py @@ -520,6 +520,48 @@ class SubmitFeedbackTest(EnterpriseServiceMockMixin, TestCase): self._assert_zendesk_called(zendesk_mock_instance, ticket_id, ticket, ticket_update) self._assert_datadog_called(datadog_mock, datadog_tags) + @httpretty.activate + @override_settings(ZENDESK_CUSTOM_FIELDS=TEST_ZENDESK_CUSTOM_FIELD_CONFIG, ENABLE_ENTERPRISE_INTEGRATION=True) + def test_request_with_anonymous_user_without_enterprise_info(self, zendesk_mock_class, datadog_mock): + """ + Test tags related to enterprise should not be there in case an unauthenticated user. + """ + ticket_id = 42 + self.mock_enterprise_learner_api() + user = self._anon_user + + zendesk_mock_instance = zendesk_mock_class.return_value + zendesk_mock_instance.create_ticket.return_value = ticket_id + datadog_valid_tags = ["issue_type:{}".format(self._anon_fields["issue_type"])] + datadog_invalid_tags = ['learner_type:enterprise_learner'] + + resp = self._build_and_run_request(user, self._anon_fields) + self.assertEqual(resp.status_code, 200) + + expected_datadog_calls = [mock.call.increment(views.DATADOG_FEEDBACK_METRIC, tags=datadog_valid_tags)] + self.assertEqual(datadog_mock.mock_calls, expected_datadog_calls) + + not_expected_datadog_calls = [mock.call.increment(views.DATADOG_FEEDBACK_METRIC, tags=datadog_invalid_tags)] + self.assertNotEqual(datadog_mock.mock_calls, not_expected_datadog_calls) + + @httpretty.activate + @override_settings(ZENDESK_CUSTOM_FIELDS=TEST_ZENDESK_CUSTOM_FIELD_CONFIG, ENABLE_ENTERPRISE_INTEGRATION=True) + def test_tags_in_request_with_auth_user_with_enterprise_info(self, zendesk_mock_class, datadog_mock): + """ + Test tags related to enterprise should be there in case the request is generated by an authenticated user. + """ + ticket_id = 42 + self.mock_enterprise_learner_api() + user = self._auth_user + + zendesk_mock_instance = zendesk_mock_class.return_value + zendesk_mock_instance.create_ticket.return_value = ticket_id + datadog_valid_tags = ['learner_type:enterprise_learner'] + + resp = self._build_and_run_request(user, self._auth_fields) + self.assertEqual(resp.status_code, 200) + self._assert_datadog_called(datadog_mock, datadog_valid_tags) + def test_get_request(self, zendesk_mock_class, datadog_mock): """Test that a GET results in a 405 even with all required fields""" req = self._request_factory.get("/submit_feedback", data=self._anon_fields) diff --git a/openedx/features/enterprise_support/api.py b/openedx/features/enterprise_support/api.py index b8e876fb22..f0ddc54721 100644 --- a/openedx/features/enterprise_support/api.py +++ b/openedx/features/enterprise_support/api.py @@ -162,6 +162,9 @@ class EnterpriseApiClient(object): a response. This exception is raised for both connection timeout and read timeout. """ + if not user.is_authenticated(): + return None + api_resource_name = 'enterprise-learner' cache_key = get_cache_key(