Python 3.6 compatibility: bytes vs strings stuff

These changes mostly revolve around the change in ObjectId constructor
when running on Python 3.6. Where on 2.7 the constructor would accept
12- and 24-byte strings, now only 12-byte bytes and 24-character strings
are accepted. Good thing, but required some changes in our code.

Other changes include hashing of strings, which isn't supported, so they
are converted to bytes first, and sometimes converted back afterwards.
This commit is contained in:
2017-03-03 14:14:36 +01:00
parent c2206e6b27
commit 2e41c074b5
12 changed files with 62 additions and 46 deletions

View File

@@ -15,7 +15,7 @@ class Str2idTest(AbstractPillarTest):
self.assertEqual(ObjectId(str_id), str2id(str_id))
happy(24 * 'a')
happy(12 * 'a')
happy(12 * b'a')
happy('577e23ad98377323f74c368c')
def test_unhappy(self):
@@ -25,10 +25,11 @@ class Str2idTest(AbstractPillarTest):
self.assertRaises(BadRequest, str2id, str_id)
unhappy(13 * 'a')
unhappy(13 * b'a')
unhappy('577e23ad 8377323f74c368c')
unhappy('김치') # Kimchi
unhappy('')
unhappy('')
unhappy(b'')
unhappy(None)