Commit 8fc31b42 by asadiqbal

ENT-374 Support ticket is created without enterprise tags for Anonymous users.

parent 6d1c23b7
...@@ -520,6 +520,48 @@ class SubmitFeedbackTest(EnterpriseServiceMockMixin, TestCase): ...@@ -520,6 +520,48 @@ class SubmitFeedbackTest(EnterpriseServiceMockMixin, TestCase):
self._assert_zendesk_called(zendesk_mock_instance, ticket_id, ticket, ticket_update) self._assert_zendesk_called(zendesk_mock_instance, ticket_id, ticket, ticket_update)
self._assert_datadog_called(datadog_mock, datadog_tags) 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): def test_get_request(self, zendesk_mock_class, datadog_mock):
"""Test that a GET results in a 405 even with all required fields""" """Test that a GET results in a 405 even with all required fields"""
req = self._request_factory.get("/submit_feedback", data=self._anon_fields) req = self._request_factory.get("/submit_feedback", data=self._anon_fields)
......
...@@ -162,6 +162,9 @@ class EnterpriseApiClient(object): ...@@ -162,6 +162,9 @@ class EnterpriseApiClient(object):
a response. This exception is raised for both connection timeout and read timeout. 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' api_resource_name = 'enterprise-learner'
cache_key = get_cache_key( cache_key = get_cache_key(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment