From 9333ad100ede13e1510ed6cf82c653a9641fda7e Mon Sep 17 00:00:00 2001 From: Pete Date: Tue, 9 Apr 2013 17:43:00 +0100 Subject: [PATCH 1/6] Fixed helpful test error message --- tests/test_base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index ad425b1..c184746 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -7,12 +7,11 @@ try: except ImportError: print ("********************************************************************\n" "You need to create a 'tokens.py' file containing the following:\n\n" - " host = \"\"\n" + " host = \"\"\n" " consumer_key = \"\"\n" " consumer_secret = \"\"\n" " token = \"\"\n" " token_secret = \"\"\n" - " host = \"\"\n\n" "WARNING: Don't use a production OpenPhoto instance for this!\n" "********************************************************************\n") raise From e6095ec3db11c3db04e6bb00167527a1e0372a61 Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Mon, 15 Apr 2013 21:30:06 +0100 Subject: [PATCH 2/6] Update README to stop nosetests from capturing the logging, since it gets pretty large. Logs are saved to tests.log. --- tests/README.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/README.markdown b/tests/README.markdown index 92e250f..89838c9 100644 --- a/tests/README.markdown +++ b/tests/README.markdown @@ -9,7 +9,7 @@ A computer, Python 2.7 and an empty OpenPhoto instance. --------------------------------------- -### Setting up +### Setting up Create a tests/tokens.py file containing the following: @@ -34,7 +34,9 @@ The "-c" lets you stop the tests gracefully with \[CTRL\]-c. The easiest way to run a subset of the tests is with nose: cd /path/to/openphoto-python - nosetests -v -s tests/test_albums.py:TestAlbums.test_view + nosetests -v -s --nologcapture tests/test_albums.py:TestAlbums.test_view + +All HTTP requests and responses are recorded in the file "tests.log". --------------------------------------- From a477dc796c5d7b5a2443142f8f1b1aaba584ccb5 Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Sat, 20 Apr 2013 11:20:22 +0100 Subject: [PATCH 3/6] Remove unneeded LOG_FILENAME variable --- tests/test_base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_base.py b/tests/test_base.py index c184746..34a99f4 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -26,7 +26,6 @@ class TestBase(unittest.TestCase): unittest.TestCase.__init__(self, *args, **kwds) self.photos = [] - LOG_FILENAME = "tests.log" logging.basicConfig(filename="tests.log", filemode="w", format="%(message)s", From 35a271c25bcae8aeb23bcfe48953382ac53d43fc Mon Sep 17 00:00:00 2001 From: Pete Date: Sat, 20 Apr 2013 20:36:29 +0100 Subject: [PATCH 4/6] Improve POST logging - don't log file contents. --- openphoto/openphoto_http.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/openphoto/openphoto_http.py b/openphoto/openphoto_http.py index 59431f6..a60e84c 100644 --- a/openphoto/openphoto_http.py +++ b/openphoto/openphoto_http.py @@ -88,19 +88,20 @@ class OpenPhotoHttp: if files: # Parameters must be signed and encoded into the multipart body - params = self._sign_params(client, url, params) - headers, body = encode_multipart_formdata(params, files) + signed_params = self._sign_params(client, url, params) + headers, body = encode_multipart_formdata(signed_params, files) request = urllib2.Request(url, body, headers) content = urllib2.urlopen(request).read() else: body = urllib.urlencode(params) _, content = client.request(url, "POST", body) - # TODO: Don't log file data in multipart forms self._logger.info("============================") self._logger.info("POST %s" % url) - if body: - self._logger.info(body) + if params: + self._logger.info("params: %s" % repr(params)) + if files: + self._logger.info("files: %s" % repr(files)) self._logger.info("---") self._logger.info(content) From 735daab58edc61260948d8f052f47be22c755bf3 Mon Sep 17 00:00:00 2001 From: Pete Date: Sun, 21 Apr 2013 16:23:25 +0100 Subject: [PATCH 5/6] Revert 35a271c25bcae8aeb23bcfe48953382ac53d43fc, since this has been applied on the http_improvements branch --- openphoto/openphoto_http.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/openphoto/openphoto_http.py b/openphoto/openphoto_http.py index a60e84c..5bb280b 100644 --- a/openphoto/openphoto_http.py +++ b/openphoto/openphoto_http.py @@ -88,20 +88,19 @@ class OpenPhotoHttp: if files: # Parameters must be signed and encoded into the multipart body - signed_params = self._sign_params(client, url, params) - headers, body = encode_multipart_formdata(signed_params, files) + params = self._sign_params(client, url, params) + headers, body = encode_multipart_formdata(params, files) request = urllib2.Request(url, body, headers) content = urllib2.urlopen(request).read() else: body = urllib.urlencode(params) _, content = client.request(url, "POST", body) + # TODO: Don't log file data in multipart forms self._logger.info("============================") self._logger.info("POST %s" % url) - if params: - self._logger.info("params: %s" % repr(params)) - if files: - self._logger.info("files: %s" % repr(files)) + if body: + self._logger.info(body) self._logger.info("---") self._logger.info(content) From 2ddcc6978ecbe5980d4addd894b1ac538862fc7c Mon Sep 17 00:00:00 2001 From: Pete Date: Sun, 21 Apr 2013 16:25:01 +0100 Subject: [PATCH 6/6] Comment whitespace --- openphoto/openphoto_http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openphoto/openphoto_http.py b/openphoto/openphoto_http.py index 5bb280b..59431f6 100644 --- a/openphoto/openphoto_http.py +++ b/openphoto/openphoto_http.py @@ -96,7 +96,7 @@ class OpenPhotoHttp: body = urllib.urlencode(params) _, content = client.request(url, "POST", body) - # TODO: Don't log file data in multipart forms + # TODO: Don't log file data in multipart forms self._logger.info("============================") self._logger.info("POST %s" % url) if body: