Small fixes => tests pass after 2to3

This commit is contained in:
Vincent Jacques
2012-11-21 20:30:35 +01:00
parent 9a03610f7b
commit d8e50c7937
3 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ class Requester:
def __init__(self, login_or_token, password, base_url, timeout, client_id, client_secret, user_agent):
if password is not None:
login = login_or_token
self.__authorizationHeader = "Basic " + base64.b64encode(login + ":" + password).replace('\n', '')
self.__authorizationHeader = "Basic " + str(base64.b64encode(bytearray(login + ":" + password, "utf-8"))).replace('\n', '')
elif login_or_token is not None:
token = login_or_token
self.__authorizationHeader = "token " + token
+1 -1
View File
@@ -32,5 +32,5 @@ class ContentFile(Framework.TestCase):
self.assertEqual(self.file.size, 7531)
self.assertEqual(self.file.name, "ReadMe.md")
self.assertEqual(self.file.path, "ReadMe.md")
self.assertEqual(len(base64.b64decode(self.file.content)), 7531)
self.assertEqual(len(base64.b64decode(bytearray(self.file.content, "utf-8"))), 7531)
self.assertEqual(self.file.sha, "5628799a7d517a4aaa0c1a7004d07569cd154df0")
+5 -4
View File
@@ -19,6 +19,7 @@ import sys
import Framework
atLeastPython26 = sys.hexversion >= 0x02060000
atMostPython2 = sys.hexversion < 0x03000000
class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we do not use self.assertRaises with only one argument
@@ -43,7 +44,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we
"message": "Validation Failed"
}
)
if atLeastPython26:
if atLeastPython26 and atMostPython2:
self.assertEqual(str(exception), "422 {u\'message\': u\'Validation Failed\', u\'errors\': [{u\'field\': u\'key\', u\'message\': u\"key is invalid. It must begin with \'ssh-rsa\' or \'ssh-dss\'. Check that you\'re copying the public half of the key\", u\'code\': u\'custom\', u\'resource\': u\'PublicKey\'}]}")
else:
self.assertEqual(str(exception), "422 {\'message\': \'Validation Failed\', \'errors\': [{\'field\': \'key\', \'message\': \"key is invalid. It must begin with \'ssh-rsa\' or \'ssh-dss\'. Check that you\'re copying the public half of the key\", \'code\': \'custom\', \'resource\': \'PublicKey\'}]}") # pragma no cover
@@ -57,7 +58,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we
raised = True
self.assertEqual(exception.status, 404)
self.assertEqual(exception.data, {"message": "Not Found"})
if atLeastPython26:
if atLeastPython26 and atMostPython2:
self.assertEqual(str(exception), "404 {u'message': u'Not Found'}")
else:
self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover
@@ -71,7 +72,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we
raised = True
self.assertEqual(exception.status, 404)
self.assertEqual(exception.data, {"message": "Not Found"})
if atLeastPython26:
if atLeastPython26 and atMostPython2:
self.assertEqual(str(exception), "404 {u'message': u'Not Found'}")
else:
self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover
@@ -85,7 +86,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we
raised = True
self.assertEqual(exception.status, 401)
self.assertEqual(exception.data, {"message": "Bad credentials"})
if atLeastPython26:
if atLeastPython26 and atMostPython2:
self.assertEqual(str(exception), "401 {u'message': u'Bad credentials'}")
else:
self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}") # pragma no cover