Fix test_legacy_api.py
authorChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 16 Sep 2014 19:37:36 +0000 (14:37 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 16 Sep 2014 19:37:36 +0000 (14:37 -0500)
Or rather, reimplement one of Berker's fixes and add one of mine:
 - add back the http_auth_headers fix Berker wrote
 - decode to json when testing the response.body, since we have no
   idea what the order will be here

mediagoblin/tests/test_legacy_api.py

index 4e0cbd8fbdcbf33f693a6667c31d75937a2ff1ca..f12d9ce5f2eaaa06da59dddb843f3dd45bc0f832 100644 (file)
@@ -17,6 +17,7 @@
 
 import logging
 import base64
+import json
 
 import pytest
 
@@ -48,10 +49,10 @@ class TestAPI(object):
         return template.TEMPLATE_TEST_CONTEXT[template_name]
 
     def http_auth_headers(self):
-        return {'Authorization': 'Basic {0}'.format(
-                base64.b64encode(':'.join([
+        return {'Authorization': ('Basic {0}'.format(
+                base64.b64encode((':'.join([
                     self.user.username,
-                    self.user_password])))}
+                    self.user_password])).encode('ascii')).decode()))}
 
     def do_post(self, data, test_app, **kwargs):
         url = kwargs.pop('url', '/api/submit')
@@ -77,8 +78,8 @@ class TestAPI(object):
             '/api/test',
             headers=self.http_auth_headers())
 
-        assert response.body == \
-                '{"username": "joapi", "email": "joapi@example.com"}'
+        assert json.loads(response.body) == {
+            "username": "joapi", "email": "joapi@example.com"}
 
     def test_2_test_submission(self, test_app):
         self.login(test_app)