From 58a7292fed40cfad3cb386f016505d2e0ec43ad2 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 14:37:36 -0500 Subject: [PATCH] Fix test_legacy_api.py 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mediagoblin/tests/test_legacy_api.py b/mediagoblin/tests/test_legacy_api.py index 4e0cbd8f..f12d9ce5 100644 --- a/mediagoblin/tests/test_legacy_api.py +++ b/mediagoblin/tests/test_legacy_api.py @@ -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)