Repository: planetlabs/planet-client-python
Pull request #63 (2015-08-18 12:58:41)

Small fixes


Patch:
diff --git a/docs/Makefile b/docs/Makefile
index 11bbf4a..5565537 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -48,6 +48,9 @@ help:
 	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
 	@echo "  coverage   to run coverage check of the documentation (if enabled)"
 
+livehtml:
+	sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+
 clean:
 	rm -rf $(BUILDDIR)/*
 
diff --git a/planet/api/client.py b/planet/api/client.py
index 8b93736..eaf88d6 100644
--- a/planet/api/client.py
+++ b/planet/api/client.py
@@ -90,7 +90,7 @@ class Client(object):
             'intersects': intersects
         }
         params.update(**filters)
-        return self._get('scenes/%s' % scene_type,
+        return self._get('scenes/%s/' % scene_type,
                          models.Scenes, params=params).get_body()
 
     def get_scene_metadata(self, scene_id, scene_type='ortho'):
@@ -99,14 +99,14 @@ class Client(object):
 
         .. todo:: Generalize to accept multiple scene ids.
         """
-        return self._get('scenes/%s/%s' % (scene_type, scene_id)).get_body()
+        return self._get('scenes/%s/%s/' % (scene_type, scene_id)).get_body()
 
     def fetch_scene_geotiffs(self, scene_ids, scene_type='ortho',
                              product='visual', callback=None):
         params = {
             'product': product
         }
-        paths = ['scenes/%s/%s/full' % (scene_type, sid) for sid in scene_ids]
+        paths = ['scenes/%s/%s/full/' % (scene_type, id) for id in scene_ids]
         return self._download_many(paths, params, callback)
 
     def fetch_scene_thumbnails(self, scene_ids, scene_type='ortho', size='md',
@@ -115,7 +115,7 @@ class Client(object):
             'size': size,
             'format': fmt
         }
-        paths = ['scenes/%s/%s/thumb' % (scene_type, sid) for sid in scene_ids]
+        paths = ['scenes/%s/%s/thumb/' % (scene_type, id) for id in scene_ids]
         return self._download_many(paths, params, callback)
 
     def list_mosaics(self):
@@ -124,7 +124,7 @@ class Client(object):
 
         .. todo:: Pagination
         """
-        return self._get('mosaics', models.Mosaics).get_body()
+        return self._get('mosaics/', models.Mosaics).get_body()
 
     def get_mosaic(self, name):
         """
@@ -133,7 +133,7 @@ class Client(object):
         :param name:
             Mosaic name as returned by `list_mosaics`.
         """
-        return self._get('mosaics/%s' % name).get_body()
+        return self._get('mosaics/%s/' % name).get_body()
 
     def get_mosaic_quads(self, name, intersects=None, count=50):
         """
@@ -156,15 +156,15 @@ class Client(object):
         return self._get(path, models.Quads, params).get_body()
 
     def fetch_mosaic_quad_geotiffs(self, mosaic_name, quad_ids, callback=None):
-        pt = 'mosaics/%s/quads/%s/full'
+        pt = 'mosaics/%s/quads/%s/full/'
         paths = [pt % (mosaic_name, qid) for qid in quad_ids]
         return self._download_many(paths, {}, callback)
 
     def get_workspaces(self):
-        return self._get('workspaces').get_body()
+        return self._get('workspaces/').get_body()
 
     def get_workspace(self, id):
-        return self._get('workspaces/%s' % id).get_body()
+        return self._get('workspaces/%s/' % id).get_body()
 
     def set_workspace(self, workspace, id=None):
         if id:
diff --git a/planet/api/dispatch.py b/planet/api/dispatch.py
index 7187c5b..1046bf7 100644
--- a/planet/api/dispatch.py
+++ b/planet/api/dispatch.py
@@ -41,13 +41,13 @@ class RedirectSession(FuturesSession):
             redir = prepared_request.url
             if not _is_subdomain_of_tld(orig, redir):
                 prepared_request.headers.pop('Authorization')
-            key = re.match('api-key (\S+)', existing_auth)
-            if key:
-                prepared_request.prepare_url(
-                    prepared_request.url, {
-                        'api_key': key.group(1)
-                    }
-                )
+                key = re.match('api-key (\S+)', existing_auth)
+                if key:
+                    prepared_request.prepare_url(
+                        prepared_request.url, {
+                            'api_key': key.group(1)
+                        }
+                    )
 
 
 class RequestsDispatcher(object):
diff --git a/planet/api/models.py b/planet/api/models.py
index 6a7988a..7a08449 100644
--- a/planet/api/models.py
+++ b/planet/api/models.py
@@ -58,7 +58,7 @@ class Response(object):
     def await(self):
         if self._future:
             self._future.result()
-            return self._body
+        return self._body
 
 
 class Request(object):
diff --git a/planet/scripts/__init__.py b/planet/scripts/__init__.py
index 020b0c8..d391c87 100644
--- a/planet/scripts/__init__.py
+++ b/planet/scripts/__init__.py
@@ -39,7 +39,8 @@ pretty = click.option('-pp/-r', '--pretty/--no-pretty', default=None,
                       is_flag=True)
 scene_type = click.option('-s', '--scene-type', default='ortho')
 dest_dir = click.option('-d', '--dest', help='Destination directory',
-                        type=click.Path(file_okay=False, resolve_path=True))
+                        type=click.Path(file_okay=False, resolve_path=True,
+                                        exists=True))
 workspace = click.option('--workspace')
 
 
@@ -204,6 +205,7 @@ def help(context, command):
     if command:
         cmd = cli.commands.get(command, None)
         if cmd:
+            context.info_name = command
             click.echo(cmd.get_help(context))
         else:
             raise click.ClickException('no command: %s' % command)
@@ -273,7 +275,7 @@ def metadata(scene_id, scene_type, pretty):
 @click.option('--product',
               type=click.Choice(
                   ["band_%d" % i for i in range(1, 12)] +
-                  ['visual', 'analytic', 'qa']
+                  ['visual', 'analytic', 'unrectified', 'qa']
               ), default='visual')
 @cli.command('download')
 def fetch_scene_geotiff(scene_ids, scene_type, product, dest):
@@ -459,5 +461,7 @@ def set_workspace(id, aoi, name, create, workspace):
     if name:
         workspace['name'] = name
 
+    if not workspace:
+        raise click.ClickException('nothing to do')
     echo_json_response(call_and_wrap(client().set_workspace,
                        workspace, id), pretty)


Test patch:
diff --git a/tests/test_mod.py b/tests/test_mod.py
index b82dd45..e442469 100644
--- a/tests/test_mod.py
+++ b/tests/test_mod.py
@@ -88,7 +88,7 @@ def test_status_code_other(client):
 def test_fetch_scene_info_scene_id(client):
     '''Verify get_scene_metadata path handling'''
     with requests_mock.Mocker() as m:
-        uri = os.path.join(client.base_url, 'scenes/ortho/x22')
+        uri = os.path.join(client.base_url, 'scenes/ortho/x22/')
         m.get(uri, text='bananas', status_code=200)
         assert client.get_scene_metadata('x22').get_raw() == 'bananas'
 
@@ -135,7 +135,7 @@ def test_login_errors(client):
 
 def test_get_scenes_list(client):
     with requests_mock.Mocker() as m:
-        uri = os.path.join(client.base_url, 'scenes/ortho')
+        uri = os.path.join(client.base_url, 'scenes/ortho/')
 
         def fake_response(i):
             return json.dumps({'links': {
diff --git a/tests/test_mosaics.py b/tests/test_mosaics.py
index 7c04b61..04882a4 100644
--- a/tests/test_mosaics.py
+++ b/tests/test_mosaics.py
@@ -26,7 +26,7 @@ def test_list_mosaics():
     with Mocker() as m:
 
         text = read_fixture('list-mosaics.json')
-        uri = os.path.join(client.base_url, 'mosaics')
+        uri = os.path.join(client.base_url, 'mosaics/')
         m.get(uri, text=text, status_code=200)
 
         r = client.list_mosaics()
@@ -43,7 +43,7 @@ def test_get_mosaic():
 
         text = read_fixture('get-mosaic.json')
         uri = os.path.join(client.base_url,
-                           'mosaics/%s' % mosaic_name)
+                           'mosaics/%s/' % mosaic_name)
         m.get(uri, text=text, status_code=200)
 
         r = client.get_mosaic(mosaic_name)