You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kp...@apache.org on 2020/08/12 14:53:39 UTC

[qpid-proton] 01/02: PROTON-2237: Added unit tests to check illegal key types are detected and handled, also subclasses of string type keys are converted to type string

This is an automated email from the ASF dual-hosted git repository.

kpvdr pushed a commit to branch python-check-property-keys
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 4e19c7ce9c18304d793719d493ce602a6755e271
Author: Kim van der Riet <kp...@apache.org>
AuthorDate: Tue Aug 11 17:11:15 2020 -0400

    PROTON-2237: Added unit tests to check illegal key types are detected and handled, also subclasses of string type keys are converted to type string
---
 python/tests/proton_tests/message.py | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/python/tests/proton_tests/message.py b/python/tests/proton_tests/message.py
index 04413ee..d819096 100644
--- a/python/tests/proton_tests/message.py
+++ b/python/tests/proton_tests/message.py
@@ -107,6 +107,11 @@ class AccessorsTest(Test):
   def testReplyToGroupId(self):
     self._test_str("reply_to_group_id")
 
+try:
+    unicode()
+except NameError:
+    unicode = str
+
 class CodecTest(Test):
 
   def testProperties(self):
@@ -119,6 +124,43 @@ class CodecTest(Test):
 
     assert msg2.properties['key'] == 'value', msg2.properties['key']
 
+  class MyStringSubclass(unicode):
+    def __repr__(self):
+      return 'MyStringSubclass(%s)' % unicode.__repr__(self)
+
+  def testStringSubclassPropertyKey(self):
+    self.msg.properties = {CodecTest.MyStringSubclass('abc'): 123}
+    data = self.msg.encode()
+
+    msg2 = Message()
+    msg2.decode(data)
+
+    assert msg2.properties == self.msg.properties
+
+  def testNonStringPropertyKey(self):
+    self.msg.properties = {123: 'abc'}
+    try:
+       self.msg.encode()
+    except MessageException:
+      return
+    assert True, '%s: non-string key' % self.msg
+
+  def testSymbolPropertyKey(self):
+    self.msg.properties = {symbol('abc'): 'def'}
+    try:
+       self.msg.encode()
+    except MessageException:
+      return
+    assert True, '%s: symbol key' % self.msg
+
+  def testCharPropertyKey(self):
+    self.msg.properties = {char('a'): 'bcd'}
+    try:
+       self.msg.encode()
+    except MessageException:
+      return
+    assert True, '%s: char key' % self.msg
+
   def testAnnotationsSymbolicAndUlongKey(self, a={symbol('one'): 1, 'two': 2, ulong(3): 'three'}):
     self.msg.annotations = a
     data = self.msg.encode()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org