コード例 #1
0
def get_all_reservations(available: bool = False) -> Dict:
    content = None
    if available:
        content = requests.get(
            c.api_v1("/reservations?available=true")).content
    else:
        content = requests.get(c.api_v1("/reservations")).content
    return json.loads(content)
コード例 #2
0
def remove_all_machines():
    all_machines = get_all_machines()
    for machine in all_machines:
        r = requests.get(c.api_v1(f"/machines/{machine['id']}/delete"))
        assert r.status_code == 204, "Should return No Content"

    assert count_machines() == 0, "All machines should be removed"
コード例 #3
0
def get_machine(machine_id):
    r = requests.get(c.api_v1(f"/machines/{machine_id}"))
    try:
        return json.loads(r.content)
    except Exception as e:
        print(e)
        return {}
コード例 #4
0
def get_specific_reservation(machine_id) -> Dict:
    r = requests.get(c.api_v1(f"/reservations/{machine_id}"))
    try:
        return json.loads(r.content)
    except Exception as e:
        print(e)
        return {}
コード例 #5
0
def add_example_machine():
    r = requests.post(c.api_v1("/machines"), json={
        "name": c.random_name(),
        "address": c.random_ip()
    })
    assert r.status_code == 201, "Return code should be Created"
    try:
        return json.loads(r.content)
    except Exception as e:
        print(e)
        return {}
コード例 #6
0
def post_reservation(
    machined_id,
    start=None,
    duration=0,
    **kwargs,
):
    json_data = {"id": machined_id, "duration": duration}
    if start:
        json_data["start"] = start

    if kwargs:
        json_data = kwargs

    status = requests.post(c.api_v1(f"/reserve/{machined_id}"), json=json_data)
    return True if status.status_code == 200 else False
コード例 #7
0
def remove_specific_machine(machine_id):
    r = requests.get(c.api_v1(f"/machines/{machine_id}/delete"))
    return True if r.status_code == 204 else False
コード例 #8
0
def _change_protected(machine_id: int, password, state: bool) -> bool:
    state = "protect" if state else "unprotect"
    r = requests.post(c.api_v1(f"/machines/{machine_id}/{state}"), json={"password": password})
    return True if r.status_code == 200 else False
コード例 #9
0
def get_all_machines():
    content = requests.get(c.api_v1("/machines")).content
    return json.loads(content)
コード例 #10
0
def _change_enabled(machine_id, status):
    status = "enable" if status else "disable"
    r = requests.get(c.api_v1(f"/machines/{machine_id}/{status}"))
    return True if r.status_code == 200 else False
コード例 #11
0
def is_reserved(machine_id):
    r = requests.get(c.api_v1(f"/reserve/{machine_id}"))
    machine = json.loads(r.content)
    if not machine["start"]:
        return False
    return True
コード例 #12
0
def get_release_reservation(machine_id):
    status = requests.get(c.api_v1(f"/reserve/{machine_id}/release"))
    return True if status.status_code == 200 else False