-
Notifications
You must be signed in to change notification settings - Fork 72
feat: add support contact tag pipeline step #2688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
| Your project description goes here. | ||
| """ | ||
|
|
||
| __version__ = "8.9.4" | ||
| __version__ = "8.10.0" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """ | ||
| Pipeline steps for the support views filters. | ||
| """ | ||
| from crum import get_current_request | ||
| from openedx_filters.filters import PipelineStep | ||
|
|
||
| # This import will be replaced with an internal path in ENT-11576 when | ||
| # enterprise_support is migrated into edx-enterprise. | ||
| try: | ||
| from openedx.features.enterprise_support.api import enterprise_customer_for_request | ||
| except ImportError: | ||
| enterprise_customer_for_request = None | ||
|
|
||
|
|
||
| class SupportContactEnterpriseTagStep(PipelineStep): | ||
| """ | ||
| Append a support-ticket tag for linked customer-account requests. | ||
|
|
||
| This step is intended to be registered as a pipeline step for the | ||
| ``org.openedx.learning.support.contact.context.requested.v1`` filter. | ||
| """ | ||
|
|
||
| def run_filter(self, tags, user): # pylint: disable=arguments-differ | ||
| """ | ||
| Append 'enterprise_learner' to tags if the requester is linked to a customer account. | ||
| """ | ||
| request = get_current_request() | ||
| customer = enterprise_customer_for_request(request) | ||
| if customer and 'enterprise_learner' not in tags: | ||
| tags = [*tags, 'enterprise_learner'] | ||
|
|
||
| return {'tags': tags, 'user': user} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """ | ||
| Tests for enterprise.filters.support pipeline steps. | ||
| """ | ||
| from unittest.mock import patch | ||
|
|
||
| from django.test import RequestFactory, TestCase | ||
|
|
||
| from enterprise.filters.support import SupportContactEnterpriseTagStep | ||
| from test_utils.factories import UserFactory | ||
|
|
||
| CONTACT_FILTER_TYPE = "org.openedx.learning.support.contact.context.requested.v1" | ||
|
|
||
|
|
||
| class TestSupportContactEnterpriseTagStep(TestCase): | ||
| """ | ||
| Tests for SupportContactEnterpriseTagStep pipeline step. | ||
| """ | ||
|
|
||
| def _make_step(self): | ||
| return SupportContactEnterpriseTagStep(CONTACT_FILTER_TYPE, []) | ||
|
|
||
| def _make_request(self): | ||
| return RequestFactory().get('/') | ||
|
|
||
| @patch('enterprise.filters.support.enterprise_customer_for_request') | ||
| @patch('enterprise.filters.support.get_current_request') | ||
| def test_appends_tag_for_linked_customer_request(self, mock_get_current_request, mock_customer_for_request): | ||
| """ | ||
| When the request is associated with a linked customer account, 'enterprise_learner' | ||
| is appended to the tags list. | ||
| """ | ||
| mock_customer_for_request.return_value = {'uuid': 'some-uuid', 'name': 'Test Customer'} | ||
| request = self._make_request() | ||
| mock_get_current_request.return_value = request | ||
| user = UserFactory() | ||
| tags = ['some_tag'] | ||
|
|
||
| step = self._make_step() | ||
| result = step.run_filter(tags=tags, user=user) | ||
|
|
||
| assert result['tags'] == ['some_tag', 'enterprise_learner'] | ||
| assert result['user'] is user | ||
| mock_customer_for_request.assert_called_once_with(request) | ||
|
|
||
| @patch('enterprise.filters.support.enterprise_customer_for_request') | ||
| @patch('enterprise.filters.support.get_current_request') | ||
| def test_does_not_duplicate_tag(self, mock_get_current_request, mock_customer_for_request): | ||
| """ | ||
| When 'enterprise_learner' is already in the tags list, it is not duplicated. | ||
| """ | ||
| mock_customer_for_request.return_value = {'uuid': 'some-uuid', 'name': 'Test Customer'} | ||
| mock_get_current_request.return_value = self._make_request() | ||
| user = UserFactory() | ||
| tags = ['enterprise_learner'] | ||
|
|
||
| step = self._make_step() | ||
| result = step.run_filter(tags=tags, user=user) | ||
|
|
||
| assert result['tags'].count('enterprise_learner') == 1 | ||
|
|
||
| @patch('enterprise.filters.support.enterprise_customer_for_request') | ||
| @patch('enterprise.filters.support.get_current_request') | ||
| def test_does_not_append_tag_for_unlinked_request(self, mock_get_current_request, mock_customer_for_request): | ||
| """ | ||
| When the request is not associated with a linked customer account, tags are unchanged. | ||
| """ | ||
| mock_customer_for_request.return_value = None | ||
| mock_get_current_request.return_value = self._make_request() | ||
| user = UserFactory() | ||
| tags = ['some_tag'] | ||
|
|
||
| step = self._make_step() | ||
| result = step.run_filter(tags=tags, user=user) | ||
|
|
||
| assert result['tags'] == ['some_tag'] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.