예제 #1
0
def test_http_post_file(tmpdir: Any, mocked_responses: aioresponses,
                        cli_runner: CliRunner) -> None:
    """It exits with a status code of zero."""
    credential_store = FileCredentialStore(os.path.expanduser(CREDENTIAL_PATH))
    credential_store[CONF_LOCALE] = Credential(TEST_LOCALE)
    credential_store[CONF_ACCOUNT_ID] = Credential(TEST_ACCOUNT_ID)
    credential_store[CONF_VIN] = Credential(TEST_VIN)
    credential_store[GIGYA_LOGIN_TOKEN] = Credential(TEST_LOGIN_TOKEN)
    credential_store[GIGYA_PERSON_ID] = Credential(TEST_PERSON_ID)
    credential_store[GIGYA_JWT] = JWTCredential(fixtures.get_jwt())

    url = fixtures.inject_set_charge_schedule(mocked_responses, "schedules")

    endpoint = ("/commerce/v1/accounts/{account_id}"
                "/kamereon/kca/car-adapter"
                "/v2/cars/{vin}/actions/charge-schedule")
    body = {
        "data": {
            "type": "ChargeSchedule",
            "attributes": {
                "schedules": []
            }
        }
    }

    json_file = tmpdir.mkdir("json").join("sample.json")
    json_file.write(json.dumps(body))

    result = cli_runner.invoke(
        __main__.main,
        f"http post-file {endpoint} '{json_file}'",
    )
    assert result.exit_code == 0, result.exception

    expected_output = (
        "{'data': {'type': 'ChargeSchedule', 'id': 'guid', "
        "'attributes': {'schedules': ["
        "{'id': 1, 'activated': True, "
        "'tuesday': {'startTime': 'T04:30Z', 'duration': 420}, "
        "'wednesday': {'startTime': 'T22:30Z', 'duration': 420}, "
        "'thursday': {'startTime': 'T22:00Z', 'duration': 420}, "
        "'friday': {'startTime': 'T23:30Z', 'duration': 480}, "
        "'saturday': {'startTime': 'T18:30Z', 'duration': 120}, "
        "'sunday': {'startTime': 'T12:45Z', 'duration': 45}}]}}}\n")
    assert expected_output == result.output

    expected_json = {
        "data": {
            "type": "ChargeSchedule",
            "attributes": {
                "schedules": []
            }
        }
    }

    request: RequestCall = mocked_responses.requests[("POST", URL(url))][0]
    assert expected_json == request.kwargs["json"]
예제 #2
0
async def test_set_charge_schedules(vehicle: RenaultVehicle,
                                    mocked_responses: aioresponses) -> None:
    """Test set_charge_schedules."""
    url = fixtures.inject_set_charge_schedule(mocked_responses, "schedules")

    schedules: List[ChargeSchedule] = []
    assert await vehicle.set_charge_schedules(schedules)

    expected_json = {
        "data": {
            "type": "ChargeSchedule",
            "attributes": {
                "schedules": []
            }
        }
    }

    request: RequestCall = mocked_responses.requests[("POST", URL(url))][0]
    assert expected_json == request.kwargs["json"]
예제 #3
0
def test_charging_settings_deactivate(mocked_responses: aioresponses,
                                      cli_runner: CliRunner) -> None:
    """It exits with a status code of zero."""
    initialise_credential_store(include_account_id=True, include_vin=True)
    fixtures.inject_get_charging_settings(mocked_responses)
    url = fixtures.inject_set_charge_schedule(mocked_responses, "schedules")

    result = cli_runner.invoke(__main__.main, "charge schedule deactivate 1")
    assert result.exit_code == 0, result.exception

    expected_json = {
        "data": {
            "attributes": {
                "schedules": [
                    {
                        "id": 1,
                        "activated": False,
                        "monday": {
                            "duration": 15,
                            "startTime": "T12:00Z"
                        },
                        "tuesday": {
                            "duration": 420,
                            "startTime": "T04:30Z"
                        },
                        "wednesday": {
                            "duration": 420,
                            "startTime": "T22:30Z"
                        },
                        "thursday": {
                            "duration": 420,
                            "startTime": "T22:00Z"
                        },
                        "friday": {
                            "duration": 15,
                            "startTime": "T12:15Z"
                        },
                        "saturday": {
                            "duration": 30,
                            "startTime": "T12:30Z"
                        },
                        "sunday": {
                            "duration": 45,
                            "startTime": "T12:45Z"
                        },
                    },
                    {
                        "id": 2,
                        "activated": False,
                        "monday": {
                            "startTime": "T01:00Z",
                            "duration": 15
                        },
                        "tuesday": {
                            "startTime": "T02:00Z",
                            "duration": 30
                        },
                        "wednesday": {
                            "startTime": "T03:00Z",
                            "duration": 45
                        },
                        "thursday": {
                            "startTime": "T04:00Z",
                            "duration": 60
                        },
                        "friday": {
                            "startTime": "T05:00Z",
                            "duration": 75
                        },
                        "saturday": {
                            "startTime": "T06:00Z",
                            "duration": 90
                        },
                        "sunday": {
                            "startTime": "T07:00Z",
                            "duration": 105
                        },
                    },
                ]
            },
            "type": "ChargeSchedule",
        }
    }
    expected_output = "{'schedules': [{'id': 1, 'activated': True, "

    request: RequestCall = mocked_responses.requests[("POST", URL(url))][0]

    assert expected_json == request.kwargs["json"]
    assert result.output.startswith(expected_output)
예제 #4
0
def test_charging_settings_set(mocked_responses: aioresponses,
                               cli_runner: CliRunner) -> None:
    """It exits with a status code of zero."""
    initialise_credential_store(include_account_id=True, include_vin=True)
    fixtures.inject_get_charging_settings(mocked_responses, "multi")
    url = fixtures.inject_set_charge_schedule(mocked_responses, "schedules")

    monday = "--monday clear"
    friday = "--friday T23:30Z,480"
    saturday = "--saturday 19:30,120"
    result = cli_runner.invoke(
        __main__.main, f"charge schedule set 1 {monday} {friday} {saturday}")
    assert result.exit_code == 0, result.exception

    expected_json = {
        "data": {
            "attributes": {
                "schedules": [
                    {
                        "id": 1,
                        "activated": True,
                        "monday": None,
                        "tuesday": {
                            "startTime": "T00:00Z",
                            "duration": 450
                        },
                        "wednesday": {
                            "startTime": "T00:00Z",
                            "duration": 450
                        },
                        "thursday": {
                            "startTime": "T00:00Z",
                            "duration": 450
                        },
                        "friday": {
                            "startTime": "T23:30Z",
                            "duration": 480
                        },
                        "saturday": {
                            "startTime": "T18:30Z",
                            "duration": 120
                        },
                        "sunday": {
                            "startTime": "T00:00Z",
                            "duration": 450
                        },
                    },
                    {
                        "id": 2,
                        "activated": True,
                        "monday": {
                            "startTime": "T23:30Z",
                            "duration": 15
                        },
                        "tuesday": {
                            "startTime": "T23:30Z",
                            "duration": 15
                        },
                        "wednesday": {
                            "startTime": "T23:30Z",
                            "duration": 15
                        },
                        "thursday": {
                            "startTime": "T23:30Z",
                            "duration": 15
                        },
                        "friday": {
                            "startTime": "T23:30Z",
                            "duration": 15
                        },
                        "saturday": {
                            "startTime": "T23:30Z",
                            "duration": 15
                        },
                        "sunday": {
                            "startTime": "T23:30Z",
                            "duration": 15
                        },
                    },
                    {
                        "id": 3,
                        "activated": False,
                        "monday": None,
                        "tuesday": None,
                        "wednesday": None,
                        "thursday": None,
                        "friday": None,
                        "saturday": None,
                        "sunday": None,
                    },
                    {
                        "id": 4,
                        "activated": False,
                        "monday": None,
                        "tuesday": None,
                        "wednesday": None,
                        "thursday": None,
                        "friday": None,
                        "saturday": None,
                        "sunday": None,
                    },
                    {
                        "id": 5,
                        "activated": False,
                        "monday": None,
                        "tuesday": None,
                        "wednesday": None,
                        "thursday": None,
                        "friday": None,
                        "saturday": None,
                        "sunday": None,
                    },
                ],
            },
            "type": "ChargeSchedule",
        }
    }
    expected_output = "{'schedules': [{'id': 1, 'activated': True, "
    request: RequestCall = mocked_responses.requests[("POST", URL(url))][0]
    assert expected_json == request.kwargs["json"]
    assert result.output.startswith(expected_output)