Пример #1
0
async def test_get_vehicle_status_ev_bad_location(http_redirect,
                                                  ssl_certificate):
    async with CaseControlledTestServer(
            ssl=ssl_certificate.server_context()) as server:
        controller = await setup_multi_session(server, http_redirect)

        task = asyncio.create_task(controller.get_data(TEST_VIN_2_EV.lower()))
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(
            server,
            SELECT_VEHICLE_2,
            path=sc.API_SELECT_VEHICLE,
            query={
                "vin": TEST_VIN_2_EV,
                "_": str(int(time.time()))
            },
        )
        await server_js_response(server,
                                 VEHICLE_STATUS_EV,
                                 path=sc.API_VEHICLE_STATUS)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server, CONDITION_EV, path=sc.API_CONDITION)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server, LOCATE_G2, path=sc.API_LOCATE)
        status = (await task)["status"]
        assert status[sc.LOCATION_VALID]
        assert_vehicle_status(status, VEHICLE_STATUS_G2)

        # Emulates a fetch after a Crosstrek PHEV is turned off, it will return bad coordinates
        task = asyncio.create_task(
            controller.fetch(TEST_VIN_2_EV.lower(), force=True))
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server,
                                 VEHICLE_STATUS_EV,
                                 path=sc.API_VEHICLE_STATUS)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server, CONDITION_EV, path=sc.API_CONDITION)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server,
                                 LOCATE_G2_BAD_LOCATION,
                                 path=sc.API_LOCATE)
        await task
        task = asyncio.create_task(controller.get_data(TEST_VIN_2_EV.lower()))
        status = (await task)["status"]
        # We should be informed that the current location is invalid/old
        assert not status[sc.LOCATION_VALID]
        # But still preserve the previous valid location
        assert_vehicle_status(status, VEHICLE_STATUS_G2)
Пример #2
0
async def test_get_vehicle_status_ev_security_plus(http_redirect,
                                                   ssl_certificate):
    async with CaseControlledTestServer(
            ssl=ssl_certificate.server_context()) as server:
        controller = await setup_multi_session(server, http_redirect)

        task = asyncio.create_task(controller.get_data(TEST_VIN_2_EV.lower()))
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(
            server,
            SELECT_VEHICLE_2,
            path=sc.API_SELECT_VEHICLE,
            query={
                "vin": TEST_VIN_2_EV,
                "_": str(int(time.time()))
            },
        )
        await server_js_response(server,
                                 VEHICLE_STATUS_EV,
                                 path=sc.API_VEHICLE_STATUS)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server, CONDITION_EV, path=sc.API_CONDITION)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server, LOCATE_G2, path=sc.API_LOCATE)
        status = (await task)["status"]
        assert status[sc.LOCATION_VALID]
        assert_vehicle_status(status, VEHICLE_STATUS_G2)
Пример #3
0
async def test_get_vehicle_status_no_tire_pressure(http_redirect,
                                                   ssl_certificate):
    async with CaseControlledTestServer(
            ssl=ssl_certificate.server_context()) as server:
        controller = await setup_multi_session(server, http_redirect)

        task = asyncio.create_task(controller.get_data(TEST_VIN_4_SAFETY_PLUS))
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(
            server,
            SELECT_VEHICLE_4,
            path=sc.API_SELECT_VEHICLE,
            query={
                "vin": TEST_VIN_4_SAFETY_PLUS,
                "_": str(int(time.time()))
            },
        )
        await server_js_response(server,
                                 VEHICLE_STATUS_G2_NO_TIRE_PRESSURE,
                                 path=sc.API_VEHICLE_STATUS)
        status = (await task)["status"]
        with pytest.raises(AssertionError):
            assert_vehicle_status(status, VEHICLE_STATUS_G2)
        assert not status[sc.TIRE_PRESSURE_FL]
        assert not status[sc.TIRE_PRESSURE_FR]
        assert not status[sc.TIRE_PRESSURE_RL]
        assert not status[sc.TIRE_PRESSURE_RR]
Пример #4
0
async def test_get_vehicle_status_g2_security_plus(http_redirect,
                                                   ssl_certificate):
    async with CaseControlledTestServer(
            ssl=ssl_certificate.server_context()) as server:
        VALID_EXTERNAL_TEMP = "22.0"
        controller = await setup_multi_session(server, http_redirect)
        task = asyncio.create_task(controller.get_data(TEST_VIN_3_G2))
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(
            server,
            SELECT_VEHICLE_3,
            path=sc.API_SELECT_VEHICLE,
            query={
                "vin": TEST_VIN_3_G2,
                "_": str(int(time.time()))
            },
        )
        await server_js_response(server,
                                 VEHICLE_STATUS_G2,
                                 path=sc.API_VEHICLE_STATUS)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        # Manually set EXTERNAL_TEMP to good value
        controller._vehicles[TEST_VIN_3_G2]["status"][
            sc.EXTERNAL_TEMP] = VALID_EXTERNAL_TEMP
        # This condition below includes a known erroneous EXTERNAL_TEMP, which should be discarded
        await server_js_response(server, CONDITION_G2, path=sc.API_CONDITION)
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(server, LOCATE_G2, path=sc.API_LOCATE)
        status = (await task)["status"]
        assert status[sc.LOCATION_VALID]
        # Verify erroneous EXTERNAL TEMP was discarded
        assert status[sc.EXTERNAL_TEMP] == VALID_EXTERNAL_TEMP
        assert_vehicle_status(status, VEHICLE_STATUS_G2)
Пример #5
0
async def test_get_vehicle_status_safety_plus(http_redirect, ssl_certificate):
    async with CaseControlledTestServer(
            ssl=ssl_certificate.server_context()) as server:
        controller = await setup_multi_session(server, http_redirect)

        task = asyncio.create_task(controller.get_data(TEST_VIN_4_SAFETY_PLUS))
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(
            server,
            SELECT_VEHICLE_4,
            path=sc.API_SELECT_VEHICLE,
            query={
                "vin": TEST_VIN_4_SAFETY_PLUS,
                "_": str(int(time.time()))
            },
        )
        await server_js_response(server,
                                 VEHICLE_STATUS_G2,
                                 path=sc.API_VEHICLE_STATUS)
        status = (await task)["status"]
        assert_vehicle_status(status, VEHICLE_STATUS_G2)
Пример #6
0
async def test_get_vehicle_status_no_tire_pressure(http_redirect,
                                                   ssl_certificate):
    async with CaseControlledTestServer(
            ssl=ssl_certificate.server_context()) as server:
        controller = await setup_multi_session(server, http_redirect)

        task = asyncio.create_task(controller.get_data(TEST_VIN_4_SAFETY_PLUS))
        await server_js_response(server,
                                 VALIDATE_SESSION_SUCCESS,
                                 path=sc.API_VALIDATE_SESSION)
        await server_js_response(
            server,
            SELECT_VEHICLE_4,
            path=sc.API_SELECT_VEHICLE,
            query={
                "vin": TEST_VIN_4_SAFETY_PLUS,
                "_": str(int(time.time()))
            },
        )
        # Manually set Tire Pressures to good value
        good_data = VEHICLE_STATUS_G2["data"]
        controller._vehicles[TEST_VIN_4_SAFETY_PLUS]["status"][
            sc.TIRE_PRESSURE_FL] = good_data[sc.VS_TIRE_PRESSURE_FL]
        controller._vehicles[TEST_VIN_4_SAFETY_PLUS]["status"][
            sc.TIRE_PRESSURE_FR] = good_data[sc.VS_TIRE_PRESSURE_FR]
        controller._vehicles[TEST_VIN_4_SAFETY_PLUS]["status"][
            sc.TIRE_PRESSURE_RL] = good_data[sc.VS_TIRE_PRESSURE_RL]
        controller._vehicles[TEST_VIN_4_SAFETY_PLUS]["status"][
            sc.TIRE_PRESSURE_RR] = good_data[sc.VS_TIRE_PRESSURE_RR]

        # Provide no tire pressures, controller should ignore and keep previous
        await server_js_response(server,
                                 VEHICLE_STATUS_G2_NO_TIRE_PRESSURE,
                                 path=sc.API_VEHICLE_STATUS)
        status = (await task)["status"]
        assert_vehicle_status(status, VEHICLE_STATUS_G2)