From 43f82ba42b5cdc382bf59b39ec0100703cb071fe Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sun, 24 Nov 2013 23:09:46 +0100 Subject: [PATCH] Python 3 compatibility. --- .travis.yml | 3 ++- dpaste/tests/test_api.py | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index f100ea0..35f329c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: python python: - "2.7" + - "3.3" install: - "pip install -r requirements.txt" - "pip install -e ." -script: manage.py test dpaste --settings=dpaste.settings \ No newline at end of file +script: manage.py test dpaste --settings=dpaste.settings diff --git a/dpaste/tests/test_api.py b/dpaste/tests/test_api.py index 77b3a34..26c35aa 100644 --- a/dpaste/tests/test_api.py +++ b/dpaste/tests/test_api.py @@ -51,17 +51,18 @@ class SnippetAPITestCase(TestCase): data = {'content': u"Hello Wörld.\n\tGood Bye"} response = self.client.post(self.api_url, data) + content = response.content.decode('utf-8') + self.assertEqual(response.status_code, 200) self.assertEqual(Snippet.objects.count(), 1) # The response is a URL with quotes - self.assertTrue(response.content.startswith('"')) - self.assertTrue(response.content.endswith('"')) + self.assertTrue(content.startswith('"')) + self.assertTrue(content.endswith('"')) # The URL returned is the absolute url to the snippet. # If we call that url our snippet should be in the page content. - snippet_url = response.content[1:-1] - response = self.client.get(snippet_url) + response = self.client.get(content[1:-1]) self.assertEqual(response.status_code, 200) self.assertContains(response, data['content']) @@ -73,12 +74,14 @@ class SnippetAPITestCase(TestCase): data = {'content': u"Hello Wörld.\n\tGood Bye", 'format': 'url'} response = self.client.post(self.api_url, data) + content = response.content.decode('utf-8') + self.assertEqual(response.status_code, 200) self.assertEqual(Snippet.objects.count(), 1) # Response is just the link starting with http(s) and ends with a linebreak - self.assertTrue(response.content.startswith('http')) - self.assertTrue(response.content.endswith('\n')) + self.assertTrue(content.startswith('http')) + self.assertTrue(content.endswith('\n')) def test_json_format(self): @@ -92,11 +95,13 @@ class SnippetAPITestCase(TestCase): } response = self.client.post(self.api_url, data) + content = response.content.decode('utf-8') + self.assertEqual(response.status_code, 200) self.assertEqual(Snippet.objects.count(), 1) from json import loads - json_data = loads(response.content) + json_data = loads(content) # Response is valid json, containing, content, lexer and url self.assertEqual(json_data['content'], data['content'])