This repository was archived by the owner on Aug 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import vcr | ||
|
||
yauta_vcr = vcr.VCR( | ||
serializer='yaml', | ||
cassette_library_dir='tests/fixtures/cassettes', | ||
record_mode='once', | ||
match_on=['uri', 'method'], | ||
filter_headers=[('Authorization', 'TESLA_ACCESS_TOKEN')], | ||
filter_post_data_parameters=[ | ||
('client_id', 'TESLA_CLIENT_ID'), | ||
('client_secret', 'TESLA_CLIENT_SECRET'), | ||
('email', 'TESLA_EMAIL'), | ||
('password', 'TESLA_PASSWORD'), | ||
('pin', 'TESLA_PIN') | ||
] | ||
) | ||
|
||
|
||
__all__ = [yauta_vcr] |
36 changes: 36 additions & 0 deletions
36
tests/fixtures/cassettes/test_tesla_get_auth_with_email.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interactions: | ||
- request: | ||
body: grant_type=password&client_id=TESLA_CLIENT_ID&client_secret=TESLA_CLIENT_SECRET&email=TESLA_EMAIL&password=TESLA_PASSWORD | ||
headers: | ||
Accept: ['*/*'] | ||
Accept-Encoding: ['gzip, deflate'] | ||
Connection: [keep-alive] | ||
Content-Length: ['220'] | ||
Content-Type: [application/x-www-form-urlencoded] | ||
User-Agent: [python-requests/2.21.0] | ||
method: POST | ||
uri: https://owner-api.teslamotors.com/oauth/token?grant_type=password | ||
response: | ||
body: | ||
string: !!binary | | ||
H4sIAAAAAAAAAzzNMW4EIQxA0btQb2FjDPZeZmSMUVaRkhUzRaJV7h6UIu0v/nslc4/zPK7P9/hI | ||
98QVVXSG+8DW0QOaj+g8zQSYabiq0ayM5EQUOtVzhkoximH2dEt/q+P6fsb+9bAVa9f4ej5WnMdj | ||
KyQiAHBLK+Zub/96qWUK1G4aglIkaBqH5FnVTFsxwTYMoio3V2nOzOqubXToAH07vsKuGIdd6Y5c | ||
BLForj+/AAAA//8DAFIqhPzpAAAA | ||
headers: | ||
Cache-Control: [no-store] | ||
Connection: [keep-alive] | ||
Content-Encoding: [gzip] | ||
Content-Type: [application/json; charset=utf-8] | ||
Date: ['Mon, 21 Jan 2019 23:55:26 GMT'] | ||
ETag: [W/"0182cdce05699ddc0027d3b5f763fb57"] | ||
Pragma: [no-cache] | ||
Server: [nginx] | ||
Transfer-Encoding: [chunked] | ||
X-Content-Type-Options: [nosniff] | ||
X-Frame-Options: [SAMEORIGIN, SAMEORIGIN] | ||
X-Request-Id: [37c7d5bb-e5be-4fc7-b537-a3340c74d6f4] | ||
X-Runtime: ['0.398629'] | ||
X-XSS-Protection: [1; mode=block] | ||
status: {code: 200, message: OK} | ||
version: 1 |
65 changes: 65 additions & 0 deletions
65
tests/fixtures/cassettes/test_tesla_get_vehicle_details_by_id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: ['*/*'] | ||
Accept-Encoding: ['gzip, deflate'] | ||
Authorization: [TESLA_ACCESS_TOKEN] | ||
Connection: [keep-alive] | ||
User-Agent: [python-requests/2.21.0] | ||
method: GET | ||
uri: https://owner-api.teslamotors.com/api/1/vehicles/xxxxxxxx/vehicle_data | ||
response: | ||
body: | ||
string: !!binary | | ||
H4sIAAAAAAAAAwIAAAD//3xXXXOrOBL9K1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fkQie4PNA9mbmZEwf2QY8EqDCfc9MCjjDmH6+EXgjYNw | ||
Nopno3A8Cn/JJvP5fEsfcJZOu3LoahfEm4GL6M9OE46Nc7UX+Gp5YSUy94zqsTehS5kW/XmiQmYa | ||
0xONY4LYFcaj59pHYq/0hRJg1exFJvmRFF07OekjtBkRxYAjt9JyWD0kMatMZbDVdIp4NpuMgkk0 | ||
JWKEJTWB9WzUKut3Zf12Npixp8f8cPH0YtpIjUttm1dOPGK+sYgYxE9UNciGZS04xlCvSDFeTOn7 | ||
oxstPEKLYU2GkQYfL7bc3r1PY2T3NeU2Vfg2mJm2TS2+kP8DAAD//wLrBAmC+img+h1JHahTUwAU | ||
AnXPQYUuolqCZw5gzgWlDGh3BJqfYDkHmoaVgIVWXn45KBHizhLAVnwqzA/QEhwiBHJAHtCXiOiH | ||
laQoYwm1tbUAAAAA//8DAFOQ9M3LEAAA | ||
headers: | ||
Cache-Control: ['max-age=0, private, must-revalidate'] | ||
Connection: [keep-alive] | ||
Content-Encoding: [gzip] | ||
Content-Type: [application/json; charset=utf-8] | ||
Date: ['Tue, 22 Jan 2019 00:36:15 GMT'] | ||
ETag: [W/"6ba7c530630a75a5656e3c7b64f47abc"] | ||
Server: [nginx] | ||
Transfer-Encoding: [chunked] | ||
X-Content-Type-Options: [nosniff] | ||
X-Frame-Options: [SAMEORIGIN, SAMEORIGIN] | ||
X-Request-Id: [fdca1f74-5600-4def-a89b-770d1cb46678] | ||
X-Runtime: ['0.804233'] | ||
X-TXID: [71491ff51dea744f913e1ead4e372072] | ||
X-XSS-Protection: [1; mode=block] | ||
status: {code: 200, message: OK} | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: ['*/*'] | ||
Accept-Encoding: ['gzip, deflate'] | ||
Authorization: [TESLA_ACCESS_TOKEN] | ||
Connection: [keep-alive] | ||
User-Agent: [python-requests/2.21.0] | ||
method: GET | ||
uri: https://owner-api.teslamotors.com/api/1/vehicles | ||
response: | ||
body: {string: '{"response":[{"id":1234,"vehicle_id":1234,"vin":"1234","display_name":"Ghost","option_codes":"AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,MI00,CDM0","color":null,"tokens":["b74979f90e209a12","1c9886ecbbf0836e"],"state":"online","in_service":false,"id_s":"1234","calendar_enabled":true,"api_version":6,"backseat_token":null,"backseat_token_updated_at":null}],"count":1}'} | ||
headers: | ||
Cache-Control: ['max-age=0, private, must-revalidate'] | ||
Connection: [keep-alive] | ||
Content-Length: ['563'] | ||
Content-Type: [application/json; charset=utf-8] | ||
Date: ['Tue, 22 Jan 2019 00:11:05 GMT'] | ||
ETag: [W/"80301a5d122271a36d6e18a95d133d22"] | ||
Server: [nginx] | ||
X-Content-Type-Options: [nosniff] | ||
X-Frame-Options: [SAMEORIGIN, SAMEORIGIN] | ||
X-Request-Id: [fa8b6a3f-a1b6-4b92-b228-4a1133761998] | ||
X-Runtime: ['0.187736'] | ||
X-TXID: [239d6a8d0fff87b08a90c008b800abd5] | ||
X-XSS-Protection: [1; mode=block] | ||
status: {code: 200, message: OK} | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
import os | ||
|
||
from unittest import TestCase | ||
|
||
from yauta.tesla import TeslaAPI | ||
from yauta.vehicle import TeslaVehicle | ||
|
||
from .common import yauta_vcr | ||
|
||
|
||
class TeslaTest(TestCase): | ||
@yauta_vcr.use_cassette('test_tesla_get_auth_with_email.yml') | ||
def test_get_tesla_auth(self): | ||
email = os.environ.get('TESLA_EMAIL') | ||
password = os.environ.get('TESLA_PASSWORD') | ||
client_id = os.environ.get('TESLA_CLIENT_ID') | ||
client_secret = os.environ.get('TESLA_CLIENT_SECRET') | ||
t = TeslaAPI( | ||
email=email, | ||
password=password, | ||
client_id=client_id, | ||
client_secret=client_secret | ||
) | ||
|
||
t.initialize() | ||
self.assertTrue(t.headers['Authorization']) | ||
|
||
def test_initialize_tesla_with_access_token(self): | ||
t = TeslaAPI( | ||
email='xxxxxxx', | ||
password='xxxxxxx', | ||
client_id='xxxxxxxx', | ||
client_secret='xxxxxxxx' | ||
) | ||
t.initialize('XXXXXXXXXXX') | ||
self.assertTrue(t.access_token) | ||
self.assertEqual(t.access_token, 'XXXXXXXXXXX') | ||
self.assertTrue(t.headers['Authorization']) | ||
self.assertEqual(t.headers['Authorization'], 'Bearer XXXXXXXXXXX') | ||
|
||
@yauta_vcr.use_cassette('test_tesla_get_vehicles.yml') | ||
def test_get_tesla_vehicles(self): | ||
access_token = os.environ.get('TESLA_ACCESS_TOKEN', 'xxxxxxxx') | ||
t = TeslaAPI( | ||
email='xxxxxxx', | ||
password='xxxxxxx', | ||
client_id='xxxxxxxx', | ||
client_secret='xxxxxxxx' | ||
) | ||
t.initialize(access_token=access_token) | ||
vehicles = t.get_vehicles() | ||
self.assertEqual(len(vehicles), 1) | ||
|
||
self.assertTrue(isinstance(vehicles[0], TeslaVehicle)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
import os | ||
from unittest import TestCase | ||
|
||
from yauta.tesla import TeslaAPI | ||
from yauta.vehicle import TeslaVehicle | ||
|
||
from .common import yauta_vcr | ||
|
||
|
||
class TeslaVehicleTest(TestCase): | ||
@yauta_vcr.use_cassette('test_tesla_get_vehicle_details_by_id') | ||
def test_get_tesla_vehicle_details_by_id(self): | ||
vehicle_id = os.environ.get('TESLA_VEHICLE_ID', 'xxxxxxxx') | ||
access_token = os.environ.get('TESLA_ACCESS_TOKEN', 'xxxxxxxx') | ||
t = TeslaAPI( | ||
email='xxxxxxxx', | ||
password='xxxxxxxx', | ||
client_id='xxxxxxxx', | ||
client_secret='xxxxxxxx' | ||
) | ||
t.initialize(access_token=access_token) | ||
vehicle = TeslaVehicle(vehicle_id, t) | ||
data = vehicle.get_vehicle_data() | ||
self.assertTrue(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters