Example #1
0
"""Tests for Gigya models."""
import pytest
from tests import fixtures

from renault_api.gigya import models
from renault_api.gigya import schemas


@pytest.mark.parametrize("filename",
                         fixtures.get_json_files(fixtures.GIGYA_FIXTURE_PATH))
def test_valid_response(filename: str) -> None:
    """Test all valid responses."""
    response: models.GigyaResponse = fixtures.get_file_content_as_schema(
        filename, schemas.GigyaResponseSchema)
    response.raise_for_error_code()


def test_login_response() -> None:
    """Test login response."""
    response: models.GigyaLoginResponse = fixtures.get_file_content_as_schema(
        f"{fixtures.GIGYA_FIXTURE_PATH}/login.json",
        schemas.GigyaLoginResponseSchema)
    response.raise_for_error_code()
    assert response.get_session_cookie() == "sample-cookie-value"


def test_get_account_info_response() -> None:
    """Test get_account_info response."""
    response: models.GigyaGetAccountInfoResponse = fixtures.get_file_content_as_schema(
        f"{fixtures.GIGYA_FIXTURE_PATH}/get_account_info.json",
        schemas.GigyaGetAccountInfoResponseSchema,
Example #2
0
"""Tests for Kamereon models."""
from typing import cast

import pytest
from tests import fixtures

from renault_api.kamereon import enums
from renault_api.kamereon import models
from renault_api.kamereon import schemas
from renault_api.kamereon.helpers import DAYS_OF_WEEK


@pytest.mark.parametrize(
    "filename",
    fixtures.get_json_files(f"{fixtures.KAMEREON_FIXTURE_PATH}/vehicle_data"),
)
def test_vehicle_data_response(filename: str) -> None:
    """Test vehicle data response."""
    response: models.KamereonVehicleDataResponse = fixtures.get_file_content_as_schema(
        filename, schemas.KamereonVehicleDataResponseSchema)
    response.raise_for_error_code()
    # Ensure the VIN is hidden
    assert response.data.id.startswith("VF1AAAA")


def test_battery_status_1() -> None:
    """Test vehicle data for battery-status.1.json."""
    response: models.KamereonVehicleDataResponse = fixtures.get_file_content_as_schema(
        f"{fixtures.KAMEREON_FIXTURE_PATH}/vehicle_data/battery-status.1.json",
        schemas.KamereonVehicleDataResponseSchema,
    )
Example #3
0
"""Tests for Gigya errors."""
import pytest
from tests import fixtures

from renault_api.gigya import exceptions
from renault_api.gigya import models
from renault_api.gigya import schemas


@pytest.mark.parametrize(
    "filename",
    fixtures.get_json_files(f"{fixtures.GIGYA_FIXTURE_PATH}/error"))
def test_error_response(filename: str) -> None:
    """Test all error responses."""
    response: models.GigyaResponse = fixtures.get_file_content_as_schema(
        filename, schemas.GigyaResponseSchema)
    with pytest.raises(exceptions.GigyaResponseException):
        response.raise_for_error_code()


def test_get_jwt_403005_response() -> None:
    """Test get_jwt.403005 response."""
    response: models.GigyaGetJWTResponse = fixtures.get_file_content_as_schema(
        f"{fixtures.GIGYA_FIXTURE_PATH}/error/get_jwt.403005.json",
        schemas.GigyaGetJWTResponseSchema,
    )
    with pytest.raises(exceptions.GigyaResponseException) as excinfo:
        response.raise_for_error_code()
    assert excinfo.value.error_code == 403005
    assert excinfo.value.error_details == "Unauthorized user"
"""Tests for Kamereon models."""
import pytest
from tests import fixtures

from renault_api.kamereon import has_required_contracts
from renault_api.kamereon import models
from renault_api.kamereon import schemas


@pytest.mark.parametrize(
    "filename",
    fixtures.get_json_files(f"{fixtures.KAMEREON_FIXTURE_PATH}/vehicle_contract"),
)
def test_vehicle_contract_response(filename: str) -> None:
    """Test vehicle contract response."""
    response: models.KameronVehicleContractsReponse = (
        fixtures.get_file_content_as_wrapped_schema(
            filename, schemas.KameronVehicleContractsReponseSchema, "contractList"
        )
    )
    response.raise_for_error_code()
    assert response.contractList
    for contract in response.contractList:
        if contract.contractId:
            assert contract.contractId.startswith(
                "AB1234"
            ), "Ensure contractId is obfuscated."


def test_has_required_contract_1() -> None:
    """Test has_required_contract."""
Example #5
0
"""Tests for Kamereon models."""
import pytest
from tests import fixtures

from renault_api.kamereon import exceptions
from renault_api.kamereon import models
from renault_api.kamereon import schemas


@pytest.mark.parametrize(
    "filename", fixtures.get_json_files(f"{fixtures.KAMEREON_FIXTURE_PATH}/error")
)
def test_vehicle_error_response(filename: str) -> None:
    """Test vehicle error response."""
    response: models.KamereonVehicleDataResponse = fixtures.get_file_content_as_schema(
        filename, schemas.KamereonVehicleDataResponseSchema
    )
    with pytest.raises(exceptions.KamereonResponseException):
        response.raise_for_error_code()
    assert response.errors is not None


def test_vehicle_error_quota_limit() -> None:
    """Test vehicle quota_limit response."""
    response: models.KamereonVehicleDataResponse = fixtures.get_file_content_as_schema(
        f"{fixtures.KAMEREON_FIXTURE_PATH}/error/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"
Example #6
0
    "zoe_50.1.json": {
        "get_brand_label": "RENAULT",
        "get_energy_code": "ELEC",
        "get_model_code": "X102VE",
        "get_model_label": "ZOE",
        "reports_charging_power_in_watts": False,
        "uses_electricity": True,
        "uses_fuel": False,
        "supports-hvac-status": False,
        "supports-location": True,
    },
}


@pytest.mark.parametrize(
    "filename", fixtures.get_json_files(f"{fixtures.KAMEREON_FIXTURE_PATH}/vehicles")
)
def test_vehicles_response(filename: str) -> None:
    """Test vehicles list response."""
    response: models.KamereonVehiclesResponse = fixtures.get_file_content_as_schema(
        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"), "Ensure vin is obfuscated."

        vehicle_details = vehicle_link.vehicleDetails