Repository: mapbox/mapbox-sdk-py

Issue:
Uploads API parameters should be username, not account
For consistency with the HTTP api documentation. I'd like to keep the `account` kwarg as a deprecated alias until 1.0.

Discussion:

Patch:
diff --git a/CHANGES b/CHANGES
index fe6cdbb..571cacb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,12 @@
 - Add support for sequences of geometries and coordinate pairs to read_points
   (#212).
 
+Deprecations:
+
+- 'account' keyword argument of `Uploader` class's `list()`, `delete()`,
+  and `status()` methods will be removed at 1.0. It is replaced by the
+  'username' keyword argument.
+
 0.14.0 (2017-07-10)
 -------------------
 - Permit images of size 1 and 1280 (#196)
diff --git a/mapbox/services/uploads.py b/mapbox/services/uploads.py
index fb6726c..2b7353e 100644
--- a/mapbox/services/uploads.py
+++ b/mapbox/services/uploads.py
@@ -1,7 +1,8 @@
+"""Mapbox Uploads API
 """
-Mapbox Uploads API
-"""
+
 import re
+import warnings
 
 from boto3.session import Session as boto3_session
 from uritemplate import URITemplate
@@ -64,6 +65,15 @@ class Uploader(Service):
 
         return tileset
 
+    # TODO: remove this method at 1.0.
+    def _resolve_username(self, account, username):
+        """Resolve username and handle deprecation of account kwarg"""
+        if account is not None:
+            warnings.warn(
+                "Use keyword argument 'username' instead of 'account'",
+                DeprecationWarning)
+        return username or account or self.username
+
     def stage(self, fileobj, creds=None, callback=None):
         """Stages data in a Mapbox-owned S3 bucket
 
@@ -140,7 +150,7 @@ class Uploader(Service):
         requests.Response
         """
         tileset = self._validate_tileset(tileset)
-        account, _name = tileset.split(".")
+        username, _name = tileset.split(".")
 
         msg = {'tileset': tileset,
                'url': stage_url}
@@ -150,15 +160,15 @@ class Uploader(Service):
 
         msg['name'] = name if name else _name
 
-        uri = URITemplate(self.baseuri + '/{account}').expand(
-            account=account)
+        uri = URITemplate(self.baseuri + '/{username}').expand(
+            username=username)
 
         resp = self.session.post(uri, json=msg)
         self.handle_http_error(resp)
 
         return resp
 
-    def list(self, account=None):
+    def list(self, account=None, username=None):
         """List of all uploads
 
         Returns a Response object, the json() method of which returns
@@ -166,81 +176,74 @@ class Uploader(Service):
 
         Parameters
         ----------
-        account: str
-            Account name, defaults to the service's username.
+        username : str
+            Account username, defaults to the service's username.
+        account : str, **deprecated**
+            Alias for username. Will be removed in version 1.0.
 
         Returns
         -------
         requests.Response
         """
-
-        if account is None:
-            account = self.username
-        uri = URITemplate(self.baseuri + '/{account}').expand(
-            account=account)
+        username = self._resolve_username(account, username)
+        uri = URITemplate(self.baseuri + '/{username}').expand(
+            username=username)
         resp = self.session.get(uri)
         self.handle_http_error(resp)
-
         return resp
 
-    def delete(self, upload, account=None):
+    def delete(self, upload, account=None, username=None):
         """Delete the specified upload
 
         Parameters
         ----------
         upload: str
             The id of the upload or a dict with key 'id'.
-        account: str
-            Account name, defaults to the service's username.
+        username : str
+            Account username, defaults to the service's username.
+        account : str, **deprecated**
+            Alias for username. Will be removed in version 1.0.
 
         Returns
         -------
         requests.Response
         """
-
-        if account is None:
-            account = self.username
-
+        username = self._resolve_username(account, username)
         if isinstance(upload, dict):
             upload_id = upload['id']
         else:
             upload_id = upload
-
-        uri = URITemplate(self.baseuri + '/{account}/{upload_id}').expand(
-            account=account, upload_id=upload_id)
+        uri = URITemplate(self.baseuri + '/{username}/{upload_id}').expand(
+            username=username, upload_id=upload_id)
         resp = self.session.delete(uri)
         self.handle_http_error(resp)
-
         return resp
 
-    def status(self, upload, account=None):
+    def status(self, upload, account=None, username=None):
         """Check status of upload
 
         Parameters
         ----------
         upload: str
             The id of the upload or a dict with key 'id'.
-        account: str
-            Account name, defaults to the service's username.
+        username : str
+            Account username, defaults to the service's username.
+        account : str, **deprecated**
+            Alias for username. Will be removed in version 1.0.
 
         Returns
         -------
         requests.Response
         """
-
-        if account is None:
-            account = self.username
-
+        username = self._resolve_username(account, username)
         if isinstance(upload, dict):
             upload_id = upload['id']
         else:
             upload_id = upload
-
-        uri = URITemplate(self.baseuri + '/{account}/{upload_id}').expand(
-            account=account, upload_id=upload_id)
+        uri = URITemplate(self.baseuri + '/{username}/{upload_id}').expand(
+            username=username, upload_id=upload_id)
         resp = self.session.get(uri)
         self.handle_http_error(resp)
-
         return resp
 
     def upload(self, fileobj, tileset, name=None, patch=False, callback=None):


Test patch:
diff --git a/tests/test_upload.py b/tests/test_upload.py
index 4bb31d9..b802c38 100644
--- a/tests/test_upload.py
+++ b/tests/test_upload.py
@@ -32,6 +32,14 @@ def test_class_attrs():
     assert serv.api_version == 'v1'
 
 
+# TODO: remove at 1.0.
+def test_resolve_username():
+    """Username is resolved and deprecation warning raised"""
+    serv = mapbox.Uploader()
+    with pytest.warns(DeprecationWarning):
+        assert serv._resolve_username('foo', 'bar') == 'bar'
+
+
 @responses.activate
 def test_get_credentials():
     query_body = """