Port test_v2 unit test to Python 3

* test_v2.py: don't encode token identifier to ASCII on Python 3, it
  must be a text string on Python 3.
* Token: don't encode token_id nor user_id to UTF-8 on Python 3, they
  must be text strings on Python 3.
* ProjectScopedPayload.disassemble(): decode project identifier from
  UTF-8 on Python 3 to get a text string.
* Replace json.loads() with oslo_serialization.jsonutils.loads() to
  accept utf8-encoded byte string.
* tests-py3-blacklist.txt: remove test_v2 to run the test.

Change-Id: I59b80c655c9834ec4fd0af625eb514c3dec262ab
bp: python3
This commit is contained in:
Victor Stinner 2016-05-03 10:45:08 +02:00 committed by Steve Martinelli
parent 996b0c7e10
commit 97eec19126
3 changed files with 12 additions and 6 deletions

View File

@ -12,12 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import time
import uuid
from keystoneclient.common import cms
from oslo_config import cfg
from oslo_serialization import jsonutils
import six
from six.moves import http_client
from testtools import matchers
@ -1257,7 +1257,7 @@ class V2TestCase(RestfulTestCase, CoreApiTests, LegacyV2UsernameTests):
data_json = cms.cms_verify(signed_text, CONF.signing.certfile,
CONF.signing.ca_certs)
data = json.loads(data_json)
data = jsonutils.loads(data_json)
return (data, token2)
@ -1523,6 +1523,9 @@ class TestFernetTokenProviderV2(RestfulTestCase):
self.assignment_api.add_role_to_user_and_project(self.user_foo['id'],
project_ref['id'],
self.role_admin['id'])
token_id = unscoped_token
if six.PY2:
token_id = token_id.encode('ascii')
r = self.public_request(
method='POST',
path='/v2.0/tokens',
@ -1530,7 +1533,7 @@ class TestFernetTokenProviderV2(RestfulTestCase):
'auth': {
'tenantName': project_ref['name'],
'token': {
'id': unscoped_token.encode('ascii')
'id': token_id,
}
}
},

View File

@ -67,10 +67,14 @@ class Token(token.persistence.TokenDriverV8):
"'memcache' or 'sql' instead."))
def _prefix_token_id(self, token_id):
return 'token-%s' % token_id.encode('utf-8')
if six.PY2:
token_id = token_id.encode('utf-8')
return 'token-%s' % token_id
def _prefix_user_id(self, user_id):
return 'usertokens-%s' % user_id.encode('utf-8')
if six.PY2:
user_id = user_id.encode('utf-8')
return 'usertokens-%s' % user_id
def _get_key_or_default(self, key, default=None):
try:

View File

@ -2,7 +2,6 @@ keystone.tests.unit.common.test_ldap
keystone.tests.unit.identity.backends.test_ldap
keystone.tests.unit.test_backend_ldap
keystone.tests.unit.test_backend_ldap_pool
keystone.tests.unit.test_v2
keystone.tests.unit.test_v3_auth
keystone.tests.unit.test_v3_credential
keystone.tests.unit.test_v3_oauth1