|
2 | 2 |
|
3 | 3 | from django.contrib.auth.models import AnonymousUser |
4 | 4 |
|
5 | | -from kitsune.customercare.forms import ZendeskForm |
| 5 | +from kitsune.customercare.forms import ( |
| 6 | + POLICY_DISTRIBUTION_TAGS, |
| 7 | + UPDATE_CHANNEL_TAGS, |
| 8 | + ZendeskForm, |
| 9 | +) |
6 | 10 | from kitsune.customercare.models import SupportTicket |
7 | 11 | from kitsune.products.tests import ( |
8 | 12 | ProductFactory, |
@@ -512,3 +516,72 @@ def test_send_stores_deployment_fields(self, mock_task): |
512 | 516 | self.assertEqual(submission.update_channel, "esr") |
513 | 517 | self.assertEqual(submission.policy_distribution, "group_policy_admx") |
514 | 518 | mock_task.assert_called_once_with(submission.id) |
| 519 | + |
| 520 | + @patch("kitsune.customercare.tasks.zendesk_submission_classifier.delay") |
| 521 | + def test_send_appends_update_channel_segmentation_tag(self, mock_task): |
| 522 | + """Test that update_channel value is mapped to its segmentation tag.""" |
| 523 | + self.vpn_zendesk.enable_deployment_fields = True |
| 524 | + self.vpn_zendesk.save() |
| 525 | + |
| 526 | + for channel, expected_tag in UPDATE_CHANNEL_TAGS.items(): |
| 527 | + with self.subTest(channel=channel): |
| 528 | + form = ZendeskForm( |
| 529 | + data={ |
| 530 | + "email": "test@example.com", |
| 531 | + "category": "vpn-connection-issues", |
| 532 | + "subject": "Test subject", |
| 533 | + "description": "Test description", |
| 534 | + "update_channel": channel, |
| 535 | + "policy_distribution": "group_policy_admx", |
| 536 | + }, |
| 537 | + product=self.vpn_product, |
| 538 | + user=self.user, |
| 539 | + ) |
| 540 | + self.assertTrue(form.is_valid()) |
| 541 | + submission = form.send(self.user, self.vpn_product) |
| 542 | + self.assertIn(expected_tag, submission.zendesk_tags) |
| 543 | + |
| 544 | + @patch("kitsune.customercare.tasks.zendesk_submission_classifier.delay") |
| 545 | + def test_send_appends_policy_distribution_segmentation_tag(self, mock_task): |
| 546 | + """Test that policy_distribution value is mapped to its segmentation tag.""" |
| 547 | + self.vpn_zendesk.enable_deployment_fields = True |
| 548 | + self.vpn_zendesk.save() |
| 549 | + |
| 550 | + for distribution, expected_tag in POLICY_DISTRIBUTION_TAGS.items(): |
| 551 | + with self.subTest(distribution=distribution): |
| 552 | + form = ZendeskForm( |
| 553 | + data={ |
| 554 | + "email": "test@example.com", |
| 555 | + "category": "vpn-connection-issues", |
| 556 | + "subject": "Test subject", |
| 557 | + "description": "Test description", |
| 558 | + "update_channel": "esr", |
| 559 | + "policy_distribution": distribution, |
| 560 | + }, |
| 561 | + product=self.vpn_product, |
| 562 | + user=self.user, |
| 563 | + ) |
| 564 | + self.assertTrue(form.is_valid()) |
| 565 | + submission = form.send(self.user, self.vpn_product) |
| 566 | + self.assertIn(expected_tag, submission.zendesk_tags) |
| 567 | + |
| 568 | + @patch("kitsune.customercare.tasks.zendesk_submission_classifier.delay") |
| 569 | + def test_send_no_deployment_tags_when_fields_empty(self, mock_task): |
| 570 | + """Test that no deployment segmentation tags are added when fields are empty.""" |
| 571 | + form = ZendeskForm( |
| 572 | + data={ |
| 573 | + "email": "test@example.com", |
| 574 | + "category": "vpn-connection-issues", |
| 575 | + "subject": "Test subject", |
| 576 | + "description": "Test description", |
| 577 | + }, |
| 578 | + product=self.vpn_product, |
| 579 | + user=self.user, |
| 580 | + ) |
| 581 | + self.assertTrue(form.is_valid()) |
| 582 | + submission = form.send(self.user, self.vpn_product) |
| 583 | + |
| 584 | + for tag in UPDATE_CHANNEL_TAGS.values(): |
| 585 | + self.assertNotIn(tag, submission.zendesk_tags) |
| 586 | + for tag in POLICY_DISTRIBUTION_TAGS.values(): |
| 587 | + self.assertNotIn(tag, submission.zendesk_tags) |
0 commit comments