You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bo...@apache.org on 2017/12/19 16:08:23 UTC

incubator-airflow git commit: [AIRFLOW-XXX] Fix failing PubSub tests on Python3

Repository: incubator-airflow
Updated Branches:
  refs/heads/master cec04ad34 -> 81558f3d0


[AIRFLOW-XXX] Fix failing PubSub tests on Python3

Correct failing tests due to not explicitly using
b'' string when b64encoding.

Closes #2893 from prodonjs/master


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/81558f3d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/81558f3d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/81558f3d

Branch: refs/heads/master
Commit: 81558f3d094edd6bc8aac4ab0528f561c65e2b3e
Parents: cec04ad
Author: Jason Prodonovich <pr...@google.com>
Authored: Tue Dec 19 17:08:04 2017 +0100
Committer: Bolke de Bruin <bo...@xs4all.nl>
Committed: Tue Dec 19 17:08:04 2017 +0100

----------------------------------------------------------------------
 tests/contrib/hooks/test_gcp_pubsub_hook.py     | 26 +++++++++++---------
 tests/contrib/operators/test_pubsub_operator.py |  5 ++--
 2 files changed, 17 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/81558f3d/tests/contrib/hooks/test_gcp_pubsub_hook.py
----------------------------------------------------------------------
diff --git a/tests/contrib/hooks/test_gcp_pubsub_hook.py b/tests/contrib/hooks/test_gcp_pubsub_hook.py
index 8cc6c8f..7226618 100644
--- a/tests/contrib/hooks/test_gcp_pubsub_hook.py
+++ b/tests/contrib/hooks/test_gcp_pubsub_hook.py
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+from __future__ import unicode_literals
 
 from base64 import b64encode as b64e
 import unittest
@@ -31,16 +32,17 @@ except ImportError:
 BASE_STRING = 'airflow.contrib.hooks.gcp_api_base_hook.{}'
 PUBSUB_STRING = 'airflow.contrib.hooks.gcp_pubsub_hook.{}'
 
+EMPTY_CONTENT = ''.encode('utf8')
 TEST_PROJECT = 'test-project'
 TEST_TOPIC = 'test-topic'
 TEST_SUBSCRIPTION = 'test-subscription'
 TEST_UUID = 'abc123-xzy789'
 TEST_MESSAGES = [
     {
-        'data': b64e('Hello, World!'),
+        'data': b64e(b'Hello, World!'),
         'attributes': {'type': 'greeting'}
     },
-    {'data': b64e('Knock, knock')},
+    {'data': b64e(b'Knock, knock')},
     {'attributes': {'foo': ''}}]
 
 EXPANDED_TOPIC = 'projects/%s/topics/%s' % (TEST_PROJECT, TEST_TOPIC)
@@ -80,30 +82,30 @@ class PubSubHookTest(unittest.TestCase):
     def test_delete_nonexisting_topic_failifnotexists(self, mock_service):
         (mock_service.return_value.projects.return_value.topics
          .return_value.delete.return_value.execute.side_effect) = HttpError(
-            resp={'status': '404'}, content='')
+            resp={'status': '404'}, content=EMPTY_CONTENT)
 
         with self.assertRaises(PubSubException) as e:
             self.pubsub_hook.delete_topic(TEST_PROJECT, TEST_TOPIC, True)
 
-        self.assertEquals(e.exception.message,
+        self.assertEquals(str(e.exception),
                           'Topic does not exist: %s' % EXPANDED_TOPIC)
 
     @mock.patch(PUBSUB_STRING.format('PubSubHook.get_conn'))
     def test_create_preexisting_topic_failifexists(self, mock_service):
         (mock_service.return_value.projects.return_value.topics.return_value
          .create.return_value.execute.side_effect) = HttpError(
-            resp={'status': '409'}, content='')
+            resp={'status': '409'}, content=EMPTY_CONTENT)
 
         with self.assertRaises(PubSubException) as e:
             self.pubsub_hook.create_topic(TEST_PROJECT, TEST_TOPIC, True)
-        self.assertEquals(e.exception.message,
+        self.assertEquals(str(e.exception),
                           'Topic already exists: %s' % EXPANDED_TOPIC)
 
     @mock.patch(PUBSUB_STRING.format('PubSubHook.get_conn'))
     def test_create_preexisting_topic_nofailifexists(self, mock_service):
         (mock_service.return_value.projects.return_value.topics.return_value
          .get.return_value.execute.side_effect) = HttpError(
-            resp={'status': '409'}, content='')
+            resp={'status': '409'}, content=EMPTY_CONTENT)
 
         self.pubsub_hook.create_topic(TEST_PROJECT, TEST_TOPIC)
 
@@ -158,13 +160,13 @@ class PubSubHookTest(unittest.TestCase):
                                                              mock_service):
         (mock_service.return_value.projects.return_value.subscriptions.
          return_value.delete.return_value.execute.side_effect) = HttpError(
-            resp={'status': '404'}, content='')
+            resp={'status': '404'}, content=EMPTY_CONTENT)
 
         with self.assertRaises(PubSubException) as e:
             self.pubsub_hook.delete_subscription(
                 TEST_PROJECT, TEST_SUBSCRIPTION, fail_if_not_exists=True)
 
-        self.assertEquals(e.exception.message,
+        self.assertEquals(str(e.exception),
                           'Subscription does not exist: %s' %
                           EXPANDED_SUBSCRIPTION)
 
@@ -210,14 +212,14 @@ class PubSubHookTest(unittest.TestCase):
         (mock_service.return_value.projects.return_value.
          subscriptions.return_value.create.return_value
          .execute.side_effect) = HttpError(resp={'status': '409'},
-                                           content='')
+                                           content=EMPTY_CONTENT)
 
         with self.assertRaises(PubSubException) as e:
             self.pubsub_hook.create_subscription(
                 TEST_PROJECT, TEST_TOPIC, TEST_SUBSCRIPTION,
                 fail_if_exists=True)
 
-        self.assertEquals(e.exception.message,
+        self.assertEquals(str(e.exception),
                           'Subscription already exists: %s' %
                           EXPANDED_SUBSCRIPTION)
 
@@ -225,7 +227,7 @@ class PubSubHookTest(unittest.TestCase):
     def test_create_subscription_nofailifexists(self, mock_service):
         (mock_service.return_value.projects.return_value.topics.return_value
          .get.return_value.execute.side_effect) = HttpError(
-            resp={'status': '409'}, content='')
+            resp={'status': '409'}, content=EMPTY_CONTENT)
 
         response = self.pubsub_hook.create_subscription(
             TEST_PROJECT, TEST_TOPIC, TEST_SUBSCRIPTION

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/81558f3d/tests/contrib/operators/test_pubsub_operator.py
----------------------------------------------------------------------
diff --git a/tests/contrib/operators/test_pubsub_operator.py b/tests/contrib/operators/test_pubsub_operator.py
index d288378..560fe54 100644
--- a/tests/contrib/operators/test_pubsub_operator.py
+++ b/tests/contrib/operators/test_pubsub_operator.py
@@ -11,6 +11,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+from __future__ import unicode_literals
 
 from base64 import b64encode as b64e
 import unittest
@@ -35,10 +36,10 @@ TEST_TOPIC = 'test-topic'
 TEST_SUBSCRIPTION = 'test-subscription'
 TEST_MESSAGES = [
     {
-        'data': b64e('Hello, World!'),
+        'data': b64e(b'Hello, World!'),
         'attributes': {'type': 'greeting'}
     },
-    {'data': b64e('Knock, knock')},
+    {'data': b64e(b'Knock, knock')},
     {'attributes': {'foo': ''}}]