Repository: box/box-python-sdk
Pull request #356 (2018-10-26 04:09:07)

Fix device pins for enterprise parameter

boxcla: Verified that @mattwiller has signed the CLA. Thanks for the pull request!
coveralls: ## Pull Request Test Coverage Report for [Build 1220](https://coveralls.io/builds/19733980)

* **2** of **2**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.002%**) to **95.257%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/19733980/badge)](https://coveralls.io/builds/19733980) |
| :-- | --: |
| Change from base [Build 1203](https://coveralls.io/builds/19707399): |  0.002% |
| Covered Lines: | 2149 |
| Relevant Lines: | 2256 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/boxsdk/client/client.py b/boxsdk/client/client.py
index 2a6cd57..9fa5daa 100644
--- a/boxsdk/client/client.py
+++ b/boxsdk/client/client.py
@@ -1440,14 +1440,14 @@ def device_pinner(self, device_pin_id):
         """
         return self.translator.get('device_pinner')(session=self._session, object_id=device_pin_id)
 
-    def device_pinners(self, enterprise_id, direction=None, limit=None, marker=None, fields=None):
+    def device_pinners(self, enterprise=None, direction=None, limit=None, marker=None, fields=None):
         """
         Returns all of the device pins for the given enterprise.
 
-        :param enterprise_id:
-            The id of the enterprise to retrieve device pinners for.
-        :type enterprise_id:
-            `unicode`
+        :param enterprise:
+            The enterprise to retrieve device pinners for, defaulting to the current enterprise.
+        :type enterprise:
+            :class`Enterprise` or None
         :param direction:
             The sorting direction. Set to `ASC` or `DESC`
         :type direction:
@@ -1469,6 +1469,7 @@ def device_pinners(self, enterprise_id, direction=None, limit=None, marker=None,
         :rtype:
             :class:`BoxObjectCollection`
         """
+        enterprise_id = enterprise.object_id if enterprise is not None else self.get_current_enterprise().id
         additional_params = {}
         if direction is not None:
             additional_params['direction'] = direction
diff --git a/docs/device_pin.md b/docs/device_pin.md
index 4d2c692..594bc3f 100644
--- a/docs/device_pin.md
+++ b/docs/device_pin.md
@@ -17,11 +17,10 @@ corporate-managed Box account to a particular mobile device or Box Sync client.
 List Enterprise Device Pins
 ---------------------------
 
-To retrieve all device pins for the enterprise, use `client.device_pinners(enterprise_id, limit=None, marker=None, direction=None, fields=None)`.
+To retrieve all device pins for the enterprise, use `client.device_pinners(enterprise=None, limit=None, marker=None, direction=None, fields=None)`.
 
 ```python
-enterprise_id = '1234'
-device_pins = client.device_pinners(enterprise_id)
+device_pins = client.device_pinners()
 for device_in in device_pins:
     # Do something
 ```


Test patch:
diff --git a/test/unit/client/test_client.py b/test/unit/client/test_client.py
index 89452b2..1312885 100644
--- a/test/unit/client/test_client.py
+++ b/test/unit/client/test_client.py
@@ -1080,14 +1080,16 @@ def test_downscope_token_sends_downscope_request_with_additional_data(
 
 def test_device_pins_for_enterprise(mock_client, mock_box_session, device_pins_response, device_pin_id_1, device_pin_id_2):
     # pylint:disable=redefined-outer-name
-    enterprise_id = '33333'
-    mock_box_session.get.return_value = device_pins_response
+    enterprise_id = '11111'
     expected_url = '{0}/enterprises/{1}/device_pinners'.format(API.BASE_API_URL, enterprise_id)
-    pins = mock_client.device_pinners(enterprise_id, direction='asc')
+    mock_box_session.get.return_value = device_pins_response
+    enterprise = mock_client.enterprise(enterprise_id)
+    pins = mock_client.device_pinners(enterprise, direction='ASC')
     for pin, expected_id in zip(pins, [device_pin_id_1, device_pin_id_2]):
         assert pin.object_id == expected_id
-        assert pin._session == mock_box_session  # pylint:disable=protected-access
-    mock_box_session.get.assert_called_once_with(expected_url, params={'direction': 'asc'})
+        # pylint:disable=protected-access
+        assert pin._session == mock_box_session
+    mock_box_session.get.assert_called_once_with(expected_url, params={'direction': 'ASC'})
 
 
 def test_get_current_enterprise(mock_client, mock_box_session):