|
17 | 17 | import os |
18 | 18 | import os.path |
19 | 19 | import copy |
| 20 | +import urllib |
20 | 21 |
|
21 | 22 | try: |
22 | 23 | import simplejson as json |
|
277 | 278 | } |
278 | 279 |
|
279 | 280 |
|
| 281 | +ACTION_WITH_UNICODE_NAME = { |
| 282 | + "name": "st2.dummy.action_unicode_我爱狗", |
| 283 | + "description": "test description", |
| 284 | + "enabled": True, |
| 285 | + "pack": "dummy_pack_1", |
| 286 | + "entry_point": "/tmp/test/action1.sh", |
| 287 | + "runner_type": "local-shell-script", |
| 288 | + "parameters": { |
| 289 | + "a": {"type": "string", "default": "A1"}, |
| 290 | + "b": {"type": "string", "default": "B1"}, |
| 291 | + "sudo": {"default": True, "immutable": True}, |
| 292 | + }, |
| 293 | + "notify": {"on-complete": {"message": "Woohoo! I completed!!!"}}, |
| 294 | +} |
| 295 | + |
| 296 | + |
280 | 297 | class ActionsControllerTestCase( |
281 | 298 | FunctionalTest, APIControllerWithIncludeAndExcludeFilterTestCase, CleanFilesTestCase |
282 | 299 | ): |
@@ -640,6 +657,48 @@ def test_action_with_notify_update(self): |
640 | 657 | self.assertEqual(get_resp.json["notify"], {}) |
641 | 658 | self.__do_delete(action_id) |
642 | 659 |
|
| 660 | + @mock.patch.object( |
| 661 | + action_validator, "validate_action", mock.MagicMock(return_value=True) |
| 662 | + ) |
| 663 | + def test_action_with_unicode_name_create(self): |
| 664 | + post_resp = self.__do_post(ACTION_WITH_UNICODE_NAME) |
| 665 | + action_id = self.__get_action_id(post_resp) |
| 666 | + get_resp = self.__do_get_one(action_id) |
| 667 | + self.assertEqual(get_resp.status_int, 200) |
| 668 | + self.assertEqual(self.__get_action_id(get_resp), action_id) |
| 669 | + self.assertEqual(get_resp.json["name"], "st2.dummy.action_unicode_我爱狗") |
| 670 | + self.assertEqual( |
| 671 | + get_resp.json["ref"], "dummy_pack_1.st2.dummy.action_unicode_我爱狗" |
| 672 | + ) |
| 673 | + self.assertEqual( |
| 674 | + get_resp.json["uid"], "action:dummy_pack_1:st2.dummy.action_unicode_我爱狗" |
| 675 | + ) |
| 676 | + |
| 677 | + get_resp = self.__do_get_one("dummy_pack_1.st2.dummy.action_unicode_我爱狗") |
| 678 | + self.assertEqual(get_resp.json["name"], "st2.dummy.action_unicode_我爱狗") |
| 679 | + self.assertEqual( |
| 680 | + get_resp.json["ref"], "dummy_pack_1.st2.dummy.action_unicode_我爱狗" |
| 681 | + ) |
| 682 | + self.assertEqual( |
| 683 | + get_resp.json["uid"], "action:dummy_pack_1:st2.dummy.action_unicode_我爱狗" |
| 684 | + ) |
| 685 | + |
| 686 | + # Now retrieve the action using the ref and ensure it works correctly |
| 687 | + # NOTE: We need to use urlquoted value when retrieving the item since that's how all the |
| 688 | + # http clients work - non ascii characters get escaped / quoted. Passing in unquoted |
| 689 | + # value will result in exception (as expected). |
| 690 | + ref_quoted = urllib.parse.quote("dummy_pack_1.st2.dummy.action_unicode_我爱狗") |
| 691 | + get_resp = self.__do_get_one(ref_quoted) |
| 692 | + self.assertEqual(get_resp.json["name"], "st2.dummy.action_unicode_我爱狗") |
| 693 | + self.assertEqual( |
| 694 | + get_resp.json["ref"], "dummy_pack_1.st2.dummy.action_unicode_我爱狗" |
| 695 | + ) |
| 696 | + self.assertEqual( |
| 697 | + get_resp.json["uid"], "action:dummy_pack_1:st2.dummy.action_unicode_我爱狗" |
| 698 | + ) |
| 699 | + |
| 700 | + self.__do_delete(action_id) |
| 701 | + |
643 | 702 | @mock.patch.object( |
644 | 703 | action_validator, "validate_action", mock.MagicMock(return_value=True) |
645 | 704 | ) |
|
0 commit comments