]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
brag: Make usage of bytes vs unicode compatible with Python 3
authorOleh Prypin <oleh@pryp.in>
Wed, 29 Jun 2016 23:55:22 +0000 (02:55 +0300)
committerOleh Prypin <oleh@pryp.in>
Thu, 30 Jun 2016 13:30:05 +0000 (16:30 +0300)
Signed-off-by: Oleh Prypin <oleh@pryp.in>
src/brag/client/ceph-brag
src/brag/server/ceph_brag/controllers/root.py
src/brag/server/ceph_brag/tests/test_functional.py

index df48e18379afde3ec9123f5ba57d27912ac7a710..32a52c41fe61cac492951ea6a6a1a98c69f27cef 100755 (executable)
@@ -212,6 +212,8 @@ def run_command(cmd):
   child = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)
   (o, e) = child.communicate()
+  o = o.decode('utf-8', 'ignore')
+  e = e.decode('utf-8', 'ignore')
   return (child.returncode, o, e)
 
 
index 6ca46c8c081a1bac808ba0780d09321c11db2b7a..56ce1449752c255ec509c4815151ee1a73a658c1 100644 (file)
@@ -43,7 +43,7 @@ class RootController(RestController):
     @expose(content_type='application/json')
     def put(self, *args, **kwargs):
         try:
-            db.put_new_version(request.body)
+            db.put_new_version(request.body.decode('utf-8'))
         except ValueError as ve:
             return self.fail(status_code=422, msg="Improper payload : " + str(ve))
         except KeyError as ke:
index 292338c2766746f0cb1e034b35ec2c00adc8b8f6..03436cbdef063abf90ddf2a927e2240e2f5c4cbc 100644 (file)
@@ -10,27 +10,27 @@ class TestRootController(FunctionalTest):
         assert response.status_int == 400
 
     def test_2_put(self):
-        with open ("sample.json", "r") as myfile:
-            data=myfile.read().replace('\n', '')
+        with open("sample.json", "rb") as myfile:
+            data = myfile.read().replace(b'\n', b'')
         response = self.app.request('/', method='PUT', body=data)
         assert response.status_int == 201
 
     def test_3_put_invalid_json(self):
-        response = self.app.request('/', method='PUT', body='{asdfg', expect_errors=True)
+        response = self.app.request('/', method='PUT', body=b'{asdfg', expect_errors=True)
         assert response.status_int == 422
 
     def test_4_put_invalid_entries_1(self):
-        response = self.app.request('/', method='PUT', body='{}', expect_errors=True)
+        response = self.app.request('/', method='PUT', body=b'{}', expect_errors=True)
         assert response.status_int == 422
 
     def test_5_put_incomplete_json(self):
-        response = self.app.request('/', method='PUT', body='{\"uuid\":\"adfs-12312ad\"}',
+        response = self.app.request('/', method='PUT', body=b'{"uuid":"adfs-12312ad"}',
                                     expect_errors=True)
         assert response.status_int == 422
 
     def test_6_get(self):
         response = self.app.get('/')
-        js = json.loads(response.body)
+        js = json.loads(response.body.decode('utf-8'))
         for entry in js:
             ci = entry
             break
@@ -44,7 +44,7 @@ class TestRootController(FunctionalTest):
 
     def test_8_get_invalid_version(self):
         response = self.app.get('/')
-        js = json.loads(response.body)
+        js = json.loads(response.body.decode('utf-8'))
         for entry in js:
             ci = entry
             break
@@ -62,7 +62,7 @@ class TestRootController(FunctionalTest):
 
     def test_92_delete(self):
         response = self.app.get('/')
-        js = json.loads(response.body)
+        js = json.loads(response.body.decode('utf-8'))
         for entry in js:
             response = self.app.delete('/?uuid='+entry['uuid'])
             assert response.status_int == 200