G-Two / subarulink

A python package for interacting with Subaru STARLINK remote vehicle services.
Apache License 2.0
86 stars 13 forks source link

Write tests #12

Closed G-Two closed 3 years ago

G-Two commented 4 years ago

I anticipate more code changes as more users try different vehicles and issues are raised. Tests are needed to cover the code for this module.

mconlow commented 4 years ago

Let me know how I can be helpful on this. I'm a bit of a hacker at this, but we owe you for getting this so far so want to be helpful if I can.

G-Two commented 4 years ago

Tests are written and working. To setup the dev/test environment from the git repo, use pipenv install --dev and make sure subarulink is not pip installed in the environment.

% pipenv run pytest -v                                                                                                       (master)subarulink
===================================================================== test session starts ======================================================================
platform darwin -- Python 3.7.6, pytest-6.0.0rc1, py-1.9.0, pluggy-0.13.1 -- /Users/gg/.local/share/virtualenvs/subarulink-M1xevF0w/bin/python
cachedir: .pytest_cache
rootdir: /Volumes/data/proj/subarulink
plugins: cov-2.10.0, aiohttp-0.3.0, asyncio-0.14.0
collected 20 items

tests/subarulink_test.py::test_connect_incomplete_credentials PASSED                                                                                     [  5%]
tests/subarulink_test.py::test_connect_fail_authenticate PASSED                                                                                          [ 10%]
tests/subarulink_test.py::test_connect_device_registration PASSED                                                                                        [ 15%]
tests/subarulink_test.py::test_connect_single_car PASSED                                                                                                 [ 20%]
tests/subarulink_test.py::test_connect_multi_car PASSED                                                                                                  [ 25%]
tests/subarulink_test.py::test_get_data_security_plus PASSED                                                                                             [ 30%]
tests/subarulink_test.py::test_get_vehicle_status_ev_security_plus PASSED                                                                                [ 35%]
tests/subarulink_test.py::test_get_vehicle_status_ev_remote PASSED                                                                                       [ 40%]
tests/subarulink_test.py::test_get_vehicle_status_safety_plus PASSED                                                                                     [ 45%]
tests/subarulink_test.py::test_get_vehicle_status_no_tire_pressure PASSED                                                                                [ 50%]
tests/subarulink_test.py::test_get_vehicle_status_unsupported PASSED                                                                                     [ 55%]
tests/subarulink_test.py::test_lights_success PASSED                                                                                                     [ 60%]
tests/subarulink_test.py::test_lights_failure PASSED                                                                                                     [ 65%]
tests/subarulink_test.py::test_lights_timeout PASSED                                                                                                     [ 70%]
tests/subarulink_test.py::test_get_climate_settings PASSED                                                                                               [ 75%]
tests/subarulink_test.py::test_remote_start_no_args PASSED                                                                                               [ 80%]
tests/subarulink_test.py::test_remote_start_bad_args PASSED                                                                                              [ 85%]
tests/subarulink_test.py::test_remote_cmd_unsupported PASSED                                                                                             [ 90%]
tests/subarulink_test.py::test_switch_vehicle PASSED                                                                                                     [ 95%]
tests/subarulink_test.py::test_expired_session PASSED                                                                                                    [100%]

====================================================================== 20 passed in 0.94s ======================================================================

More are needed to cover controller.py as well as some lower level aiohttp errors. This will be a continuous work in progress.

In tests/responses.py there are some mock API responses for 4 different cars (a Gen 1 telematics with no subscription, a Gen 2 PHEV with full subscription, a Gen 2 Gas with full subscription, and a Gen 2 Gas with Safety Plus only). I made a guess as to what the data should be for non-EV vehicles. Please compare with your debug logs and let me know if you see anything missing or anything that shouldn't be there.