Skip to content

Commit

Permalink
feat(lock, unlock): return success object
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Lock and unlock now return an object on a successful request and throws an error on an unsuccessful request. Previously, lock and unlock did not return an object on a successful request.
  • Loading branch information
zespinosa97 authored and Karthik Bhaskara committed Apr 9, 2019
1 parent 877ba34 commit 63381b2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,25 @@ wish to make requests to it

Unlock the vehicle.

#### Return
| Type | Description |
|:------------------ |:--------------------|
| Dictionary.`status`| Set to success on successful request. |
#### Raises
<code>SmartcarException</code> on unsuccessful request

### `lock(self)`

Lock the vehicle.

#### Return
| Type | Description |
|:------------------ |:--------------------|
| Dictionary.`status`| Set to success on successful request. |
#### Raises
<code>SmartcarException</code> on unsuccessful request


## Static Methods

### `smartcar.is_expired(expiration)`
Expand Down
2 changes: 1 addition & 1 deletion smartcar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '2.0.1'
__version__ = '3.0.0'

from .smartcar import (AuthClient, is_expired, get_user_id, get_vehicle_ids)
from .vehicle import Vehicle
Expand Down
21 changes: 19 additions & 2 deletions smartcar/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,28 @@ def location(self):
def unlock(self):
""" POST Vehicle.unlock
Returns:
dict: status
Raises:
SmartcarException
"""
self.api.action('security', 'UNLOCK')
response = self.api.action('security', 'UNLOCK')
return {
'status': response.json()['status']
}

def lock(self):
""" POST Vehicle.lock
Returns:
dict: status
Raises:
SmartcarException
"""
self.api.action('security', 'LOCK')
response = self.api.action('security', 'LOCK')
return {
'status': response.json()['status']
}
20 changes: 16 additions & 4 deletions tests/test_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,22 @@ def test_disconnect(self):

@responses.activate
def test_lock(self):
self.queue('POST', 'security')
self.check(self.vehicle.lock(), action='LOCK')
data = {
'status': 'success'
}
self.queue('POST', 'security', body=data)

response = self.vehicle.lock()
self.check(response, action='LOCK')
self.assertEqual(response['status'], data['status'])

@responses.activate
def test_unlock(self):
self.queue('POST', 'security')
self.check(self.vehicle.unlock(), action='UNLOCK')
data = {
'status': 'success'
}
self.queue('POST', 'security', body=data)

response = self.vehicle.unlock()
self.check(response, action='UNLOCK')
self.assertEqual(response['status'], data['status'])
4 changes: 2 additions & 2 deletions tests/tests_e2e/test_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def test_vin(self):

def test_lock(self):
lock = self.vehicle.lock()
self.assertIsNone(lock)
self.assertEqual(lock["status"], "success")

def test_unlock(self):
unlock = self.vehicle.unlock()
self.assertIsNone(unlock)
self.assertEqual(unlock["status"], "success")

def test_disconnect(self):
disconnected = self.vehicle.disconnect()
Expand Down

0 comments on commit 63381b2

Please sign in to comment.