Repository: incubator-airflow Updated Branches: refs/heads/master bc6feea03 -> 1fa71f5a5
[AIRFLOW-3212][AIRFLOW-2314] Remove only leading slash in GCS path Closes #3212 from wileeam/fix-gcs-hook-helper- function Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/1fa71f5a Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/1fa71f5a Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/1fa71f5a Branch: refs/heads/master Commit: 1fa71f5a5c8925c670d07198c43af65097e9d00d Parents: bc6feea Author: Guillermo Rodriguez Cano <[email protected]> Authored: Thu Apr 12 09:18:36 2018 +0200 Committer: Fokko Driesprong <[email protected]> Committed: Thu Apr 12 09:18:36 2018 +0200 ---------------------------------------------------------------------- airflow/contrib/hooks/gcs_hook.py | 3 ++- tests/contrib/hooks/test_gcs_hook.py | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/1fa71f5a/airflow/contrib/hooks/gcs_hook.py ---------------------------------------------------------------------- diff --git a/airflow/contrib/hooks/gcs_hook.py b/airflow/contrib/hooks/gcs_hook.py index 6a53b1d..09c42e3 100644 --- a/airflow/contrib/hooks/gcs_hook.py +++ b/airflow/contrib/hooks/gcs_hook.py @@ -457,5 +457,6 @@ def _parse_gcs_url(gsurl): raise AirflowException('Please provide a bucket name') else: bucket = parsed_url.netloc - blob = parsed_url.path.strip('/') + # Remove leading '/' but NOT trailing one + blob = parsed_url.path.lstrip('/') return bucket, blob http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/1fa71f5a/tests/contrib/hooks/test_gcs_hook.py ---------------------------------------------------------------------- diff --git a/tests/contrib/hooks/test_gcs_hook.py b/tests/contrib/hooks/test_gcs_hook.py index cc87fb7..f4fac9c 100644 --- a/tests/contrib/hooks/test_gcs_hook.py +++ b/tests/contrib/hooks/test_gcs_hook.py @@ -14,12 +14,11 @@ import unittest -from airflow.exceptions import AirflowException import airflow.contrib.hooks.gcs_hook as gcs_hook +from airflow.exceptions import AirflowException class TestGCSHookHelperFunctions(unittest.TestCase): - def test_parse_gcs_url(self): """ Test GCS url parsing @@ -30,17 +29,14 @@ class TestGCSHookHelperFunctions(unittest.TestCase): ('bucket', 'path/to/blob')) # invalid URI - self.assertRaises( - AirflowException, - gcs_hook._parse_gcs_url, - 'gs:/bucket/path/to/blob') + self.assertRaises(AirflowException, gcs_hook._parse_gcs_url, + 'gs:/bucket/path/to/blob') # trailing slash self.assertEqual( gcs_hook._parse_gcs_url('gs://bucket/path/to/blob/'), - ('bucket', 'path/to/blob')) + ('bucket', 'path/to/blob/')) # bucket only self.assertEqual( - gcs_hook._parse_gcs_url('gs://bucket/'), - ('bucket', '')) + gcs_hook._parse_gcs_url('gs://bucket/'), ('bucket', ''))
