def test_battery_status_1() -> None:
    """Test vehicle data for battery-status.1.json."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/battery-status.1.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {
        "timestamp": "2020-11-17T09:06:48+01:00",
        "batteryLevel": 50,
        "batteryAutonomy": 128,
        "batteryCapacity": 0,
        "batteryAvailableEnergy": 0,
        "plugStatus": 0,
        "chargingStatus": -1.0,
    }

    vehicle_data = cast(
        models.KamereonVehicleBatteryStatusData,
        response.get_attributes(
            schemas.KamereonVehicleBatteryStatusDataSchema),
    )

    assert vehicle_data.timestamp == "2020-11-17T09:06:48+01:00"
    assert vehicle_data.batteryLevel == 50
    assert vehicle_data.batteryTemperature is None
    assert vehicle_data.batteryAutonomy == 128
    assert vehicle_data.batteryCapacity == 0
    assert vehicle_data.batteryAvailableEnergy == 0
    assert vehicle_data.plugStatus == 0
    assert vehicle_data.chargingStatus == -1.0
    assert vehicle_data.chargingRemainingTime is None
    assert vehicle_data.chargingInstantaneousPower is None
    assert vehicle_data.get_plug_status() == enums.PlugState.UNPLUGGED
    assert vehicle_data.get_charging_status() == enums.ChargeState.CHARGE_ERROR
def test_get_jwt_response() -> None:
    """Test get_jwt response."""
    response: models.GigyaGetJWTResponse = get_response_content(
        f"{FIXTURE_PATH}/get_jwt.json", schemas.GigyaGetJWTResponseSchema
    )
    response.raise_for_error_code()
    assert response.get_jwt() == "sample-jwt-token"
def test_login_response() -> None:
    """Test login response."""
    response: models.GigyaLoginResponse = get_response_content(
        f"{FIXTURE_PATH}/login.json", schemas.GigyaLoginResponseSchema
    )
    response.raise_for_error_code()
    assert response.get_session_cookie() == "sample-cookie-value"
def test_vehicle_action_response(filename: str) -> None:
    """Test vehicle action response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        filename, schemas.KamereonVehicleDataResponseSchema)
    response.raise_for_error_code()
    # Ensure the guid is hidden
    assert response.data.id == "guid"
Exemple #5
0
def test_vehicle_error_response(filename: str) -> None:
    """Test vehicle error response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        filename, schemas.KamereonVehicleDataResponseSchema)
    with pytest.raises(exceptions.KamereonResponseException):
        response.raise_for_error_code()
    assert response.errors is not None
def test_vehicle_data_response(filename: str) -> None:
    """Test vehicle data response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        filename, schemas.KamereonVehicleDataResponseSchema)
    response.raise_for_error_code()
    # Ensure the VIN is hidden
    assert response.data.id.startswith("VF1AAAA")
Exemple #7
0
def test_login_403042_response() -> None:
    """Test login.403042 response."""
    response: models.GigyaLoginResponse = get_response_content(
        f"{FIXTURE_PATH}/login.403042.json", schemas.GigyaLoginResponseSchema)
    with pytest.raises(exceptions.InvalidCredentialsException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == 403042
    assert excinfo.value.error_details == "invalid loginID or password"
def test_get_account_info_response() -> None:
    """Test get_account_info response."""
    response: models.GigyaGetAccountInfoResponse = get_response_content(
        f"{FIXTURE_PATH}/get_account_info.json",
        schemas.GigyaGetAccountInfoResponseSchema,
    )
    response.raise_for_error_code()
    assert response.get_person_id() == "person-id-1"
Exemple #9
0
def test_get_jwt_403013_response() -> None:
    """Test get_jwt.403013 response."""
    response: models.GigyaGetJWTResponse = get_response_content(
        f"{FIXTURE_PATH}/get_jwt.403013.json",
        schemas.GigyaGetJWTResponseSchema)
    with pytest.raises(exceptions.GigyaResponseException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == 403013
    assert excinfo.value.error_details == "Unverified user"
Exemple #10
0
def test_vehicle_error_access_denied() -> None:
    """Test vehicle access_denied response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/access_denied.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    with pytest.raises(exceptions.AccessDeniedException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == "err.func.403"
    assert excinfo.value.error_details == "Access is denied for this resource"
Exemple #11
0
def test_vehicle_error_resource_not_found() -> None:
    """Test vehicle resource_not_found response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/resource_not_found.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    with pytest.raises(exceptions.ResourceNotFoundException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == "err.func.wired.notFound"
    assert excinfo.value.error_details == "Resource not found"
Exemple #12
0
def test_vehicle_error_quota_limit() -> None:
    """Test vehicle quota_limit response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/quota_limit.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    with pytest.raises(exceptions.QuotaLimitException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == "err.func.wired.overloaded"
    assert excinfo.value.error_details == "You have reached your quota limit"
Exemple #13
0
def test_vehicle_error_invalid_date() -> None:
    """Test vehicle invalid_date response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/invalid_date.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    with pytest.raises(exceptions.InvalidInputException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == "err.func.400"
    assert (excinfo.value.error_details ==
            "/data/attributes/startDateTime must be a future date")
Exemple #14
0
def test_vehicle_error_not_supported() -> None:
    """Test vehicle not_supported response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/not_supported.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    with pytest.raises(exceptions.NotSupportedException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == "err.tech.501"
    assert (excinfo.value.error_details ==
            "This feature is not technically supported by this gateway")
def test_vehicle_action_response_attributes() -> None:
    """Test vehicle action response attributes."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/hvac-start.start.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {
        "action": "start",
        "targetTemperature": 21.0,
    }
Exemple #16
0
def test_vehicle_error_invalid_upstream() -> None:
    """Test vehicle invalid_upstream response."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/invalid_upstream.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    with pytest.raises(exceptions.InvalidUpstreamException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == "err.tech.500"
    assert (
        excinfo.value.error_details ==
        "Invalid response from the upstream server (The request sent to the GDC"
        " is erroneous) ; 502 Bad Gateway")
Exemple #17
0
def test_zoe40_2() -> None:
    """Test vehicle details for zoe_40.2.json."""
    response: models.KamereonVehiclesResponse = get_response_content(
        f"{FIXTURE_PATH}/zoe_40.2.json",
        schemas.KamereonVehiclesResponseSchema)
    vehicle_details = response.vehicleLinks[0].vehicleDetails
    assert vehicle_details
    assert vehicle_details.get_brand_label() == "RENAULT"
    assert vehicle_details.get_energy_code() == "ELEC"
    assert vehicle_details.get_model_code() == "X101VE"
    assert vehicle_details.get_model_label() == "ZOE"
    assert vehicle_details.reports_charging_power_in_watts()
    assert vehicle_details.uses_electricity()
    assert not vehicle_details.uses_fuel()
Exemple #18
0
def test_capturii_1() -> None:
    """Test vehicle details for captur_ii.1.json."""
    response: models.KamereonVehiclesResponse = get_response_content(
        f"{FIXTURE_PATH}/captur_ii.1.json",
        schemas.KamereonVehiclesResponseSchema)
    vehicle_details = response.vehicleLinks[0].vehicleDetails
    assert vehicle_details
    assert vehicle_details.get_brand_label() == "RENAULT"
    assert vehicle_details.get_energy_code() == "ESS"
    assert vehicle_details.get_model_code() == "XJB1SU"
    assert vehicle_details.get_model_label() == "CAPTUR II"
    assert not vehicle_details.reports_charging_power_in_watts()
    assert not vehicle_details.uses_electricity()
    assert vehicle_details.uses_fuel()
def test_charge_mode() -> None:
    """Test vehicle data for charge-mode.json."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/charge-mode.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {"chargeMode": "always"}

    vehicle_data = cast(
        models.KamereonVehicleChargeModeData,
        response.get_attributes(schemas.KamereonVehicleChargeModeDataSchema),
    )

    assert vehicle_data.chargeMode == "always"
    assert vehicle_data.get_charge_mode() == enums.ChargeMode.ALWAYS
Exemple #20
0
def test_person_response() -> None:
    """Test person details response."""
    response: models.KamereonPersonResponse = get_response_content(
        f"{FIXTURE_PATH}/person.json", schemas.KamereonPersonResponseSchema)
    response.raise_for_error_code()
    assert response.accounts[0].accountId == "account-id-1"
    assert response.accounts[0].accountType == "MYRENAULT"
    assert response.accounts[0].accountStatus == "ACTIVE"

    assert response.accounts[1].accountId == "account-id-2"
    assert response.accounts[1].accountType == "SFDC"
    assert response.accounts[1].accountStatus == "ACTIVE"

    for account in response.accounts:
        assert account.accountId
        assert account.accountId.startswith("account-id")
def test_cockpit_zoe() -> None:
    """Test vehicle data for cockpit.zoe.json."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/cockpit.zoe.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {"totalMileage": 49114.27}

    vehicle_data = cast(
        models.KamereonVehicleCockpitData,
        response.get_attributes(schemas.KamereonVehicleCockpitDataSchema),
    )

    assert vehicle_data.totalMileage == 49114.27
    assert vehicle_data.fuelAutonomy is None
    assert vehicle_data.fuelQuantity is None
def test_location() -> None:
    """Test vehicle data for location.json."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/location.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {
        "gpsLatitude": 48.1234567,
        "gpsLongitude": 11.1234567,
        "lastUpdateTime": "2020-02-18T16:58:38Z",
    }

    vehicle_data = cast(
        models.KamereonVehicleLocationData,
        response.get_attributes(schemas.KamereonVehicleLocationDataSchema),
    )

    assert vehicle_data.gpsLatitude == 48.1234567
    assert vehicle_data.gpsLongitude == 11.1234567
    assert vehicle_data.lastUpdateTime == "2020-02-18T16:58:38Z"
def test_cockpit_captur_ii() -> None:
    """Test vehicle data for cockpit.captur_ii.json."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/cockpit.captur_ii.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {
        "fuelAutonomy": 35.0,
        "fuelQuantity": 3.0,
        "totalMileage": 5566.78,
    }

    vehicle_data = cast(
        models.KamereonVehicleCockpitData,
        response.get_attributes(schemas.KamereonVehicleCockpitDataSchema),
    )

    assert vehicle_data.totalMileage == 5566.78
    assert vehicle_data.fuelAutonomy == 35.0
    assert vehicle_data.fuelQuantity == 3.0
def test_battery_status_2() -> None:
    """Test vehicle data for battery-status.2.json."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/battery-status.2.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {
        "timestamp": "2020-01-12T21:40:16Z",
        "batteryLevel": 60,
        "batteryTemperature": 20,
        "batteryAutonomy": 141,
        "batteryCapacity": 0,
        "batteryAvailableEnergy": 31,
        "plugStatus": 1,
        "chargingStatus": 1.0,
        "chargingRemainingTime": 145,
        "chargingInstantaneousPower": 27.0,
    }

    vehicle_data = cast(
        models.KamereonVehicleBatteryStatusData,
        response.get_attributes(
            schemas.KamereonVehicleBatteryStatusDataSchema),
    )

    assert vehicle_data.timestamp == "2020-01-12T21:40:16Z"
    assert vehicle_data.batteryLevel == 60
    assert vehicle_data.batteryTemperature == 20
    assert vehicle_data.batteryAutonomy == 141
    assert vehicle_data.batteryCapacity == 0
    assert vehicle_data.batteryAvailableEnergy == 31
    assert vehicle_data.plugStatus == 1
    assert vehicle_data.chargingStatus == 1.0
    assert vehicle_data.chargingRemainingTime == 145
    assert vehicle_data.chargingInstantaneousPower == 27.0
    assert vehicle_data.get_plug_status() == enums.PlugState.PLUGGED
    assert vehicle_data.get_charging_status(
    ) == enums.ChargeState.CHARGE_IN_PROGRESS
Exemple #25
0
def test_vehicles_response(filename: str) -> None:
    """Test vehicles list response."""
    response: models.KamereonVehiclesResponse = get_response_content(
        filename, schemas.KamereonVehiclesResponseSchema)
    response.raise_for_error_code()
    # Ensure the account id is hidden
    assert response.accountId.startswith("account-id")
    for vehicle_link in response.vehicleLinks:
        # Ensure the VIN and RegistrationNumber are hidden
        assert vehicle_link.vin
        assert vehicle_link.vin.startswith("VF1AAAA")

        vehicle_details = vehicle_link.vehicleDetails
        assert vehicle_details
        assert vehicle_details.vin
        assert vehicle_details.vin.startswith("VF1AAAA")
        assert vehicle_details.registrationNumber
        assert vehicle_details.registrationNumber.startswith("REG-")

        # Ensure the methods work
        assert vehicle_details.get_brand_label()
        assert vehicle_details.get_energy_code()
        assert vehicle_details.get_model_code()
        assert vehicle_details.get_model_label()
def test_for_json() -> None:
    """Test for updating charge settings."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/charging-settings.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    vehicle_data = cast(
        models.KamereonVehicleChargingSettingsData,
        response.get_attributes(
            schemas.KamereonVehicleChargingSettingsDataSchema),
    )

    # Check that for_json returns the same as the original data
    for_json = {
        "schedules":
        list(schedule.for_json() for schedule in vehicle_data.schedules)
    }
    assert for_json == {
        "schedules": [{
            "id": 1,
            "activated": True,
            "monday": {
                "startTime": "T12:00Z",
                "duration": 15
            },
            "tuesday": {
                "startTime": "T04:30Z",
                "duration": 420
            },
            "wednesday": {
                "startTime": "T22:30Z",
                "duration": 420
            },
            "thursday": {
                "startTime": "T22:00Z",
                "duration": 420
            },
            "friday": {
                "startTime": "T12:15Z",
                "duration": 15
            },
            "saturday": {
                "startTime": "T12:30Z",
                "duration": 30
            },
            "sunday": {
                "startTime": "T12:45Z",
                "duration": 45
            },
        }]
    }

    # Check that for_json returns the same as the original data
    for_json = {
        "schedules":
        list(schedule.for_json() for schedule in vehicle_data.schedules)
    }
    assert for_json == {
        "schedules": [{
            "id": 1,
            "activated": True,
            "monday": {
                "startTime": "T12:00Z",
                "duration": 15
            },
            "tuesday": {
                "startTime": "T04:30Z",
                "duration": 420
            },
            "wednesday": {
                "startTime": "T22:30Z",
                "duration": 420
            },
            "thursday": {
                "startTime": "T22:00Z",
                "duration": 420
            },
            "friday": {
                "startTime": "T12:15Z",
                "duration": 15
            },
            "saturday": {
                "startTime": "T12:30Z",
                "duration": 30
            },
            "sunday": {
                "startTime": "T12:45Z",
                "duration": 45
            },
        }]
    }

    vehicle_data.update(TEST_UPDATE)
    assert vehicle_data.schedules[0].tuesday.startTime == "T12:00Z"
    assert vehicle_data.schedules[0].tuesday.duration == 15

    for_json = {
        "schedules":
        list(schedule.for_json() for schedule in vehicle_data.schedules)
    }
    assert for_json == {
        "schedules": [{
            "id": 1,
            "activated": True,
            "monday": {
                "startTime": "T12:00Z",
                "duration": 15
            },
            "tuesday": {
                "startTime": "T12:00Z",
                "duration": 15
            },
            "wednesday": {
                "startTime": "T22:30Z",
                "duration": 420
            },
            "thursday": {
                "startTime": "T22:00Z",
                "duration": 420
            },
            "friday": {
                "startTime": "T12:15Z",
                "duration": 15
            },
            "saturday": {
                "startTime": "T12:30Z",
                "duration": 30
            },
            "sunday": {
                "startTime": "T12:45Z",
                "duration": 45
            },
        }]
    }
def test_charging_settings() -> None:
    """Test vehicle data for charging-settings.json."""
    response: models.KamereonVehicleDataResponse = get_response_content(
        f"{FIXTURE_PATH}/charging-settings.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
    response.raise_for_error_code()
    assert response.data.raw_data["attributes"] == {
        "mode":
        "scheduled",
        "schedules": [{
            "id": 1,
            "activated": True,
            "monday": {
                "startTime": "T12:00Z",
                "duration": 15
            },
            "tuesday": {
                "startTime": "T04:30Z",
                "duration": 420
            },
            "wednesday": {
                "startTime": "T22:30Z",
                "duration": 420
            },
            "thursday": {
                "startTime": "T22:00Z",
                "duration": 420
            },
            "friday": {
                "startTime": "T12:15Z",
                "duration": 15
            },
            "saturday": {
                "startTime": "T12:30Z",
                "duration": 30
            },
            "sunday": {
                "startTime": "T12:45Z",
                "duration": 45
            },
        }],
    }

    vehicle_data = cast(
        models.KamereonVehicleChargingSettingsData,
        response.get_attributes(
            schemas.KamereonVehicleChargingSettingsDataSchema),
    )

    assert vehicle_data.mode == "scheduled"
    assert len(vehicle_data.schedules) == 1

    schedule_data = vehicle_data.schedules[0]
    assert schedule_data.id == 1
    assert schedule_data.activated is True
    assert schedule_data.monday.startTime == "T12:00Z"
    assert schedule_data.monday.duration == 15
    assert schedule_data.tuesday.startTime == "T04:30Z"
    assert schedule_data.tuesday.duration == 420
    assert schedule_data.wednesday.startTime == "T22:30Z"
    assert schedule_data.wednesday.duration == 420
    assert schedule_data.thursday.startTime == "T22:00Z"
    assert schedule_data.thursday.duration == 420
    assert schedule_data.friday.startTime == "T12:15Z"
    assert schedule_data.friday.duration == 15
    assert schedule_data.saturday.startTime == "T12:30Z"
    assert schedule_data.saturday.duration == 30
    assert schedule_data.sunday.startTime == "T12:45Z"
    assert schedule_data.sunday.duration == 45
Exemple #28
0
def test_error_response(filename: str) -> None:
    """Test all error responses."""
    response: models.GigyaResponse = get_response_content(
        filename, schemas.GigyaResponseSchema)
    with pytest.raises(exceptions.GigyaResponseException):
        response.raise_for_error_code()
def test_valid_response(filename: str) -> None:
    """Test all valid responses."""
    response: models.GigyaResponse = get_response_content(
        filename, schemas.GigyaResponseSchema
    )
    response.raise_for_error_code()