import pytest
from pybrary.databrary.pilot import Pilot


@pytest.fixture
def expected_pilot_dict():
    return {
        "key": "1250",
        "name": "pilot 1250",
        "category": "pilot"
    }


@pytest.fixture
def databrary_pilot_dict():
    return {
        "id": 1250,
        "category": 2,
        "measures": { }
    }


@pytest.fixture
def databrary_pilot_dict_fail():
    return {
        "category": 2,
    }


def test_to_dict(expected_pilot_dict):
    assert Pilot(
        record_key=1250,
        record_id=1250,
    ).to_dict() == expected_pilot_dict


def test_from_databrary(databrary_pilot_dict):
    pilot = Pilot.from_databrary(databrary_pilot_dict)
    assert pilot is not None


def test_from_databrary_fail(databrary_pilot_dict_fail):
    with pytest.raises(Exception) as e:
        Pilot.from_databrary(databrary_pilot_dict_fail)

import pytest
from pybrary.databrary.pilot import Pilot


@pytest.fixture
def expected_pilot_dict():
    return {
        "key": "1250",
        "name": "pilot 1250",
        "category": "pilot"
    }


@pytest.fixture
def databrary_pilot_dict():
    return {
        "id": 1250,
        "category": 2,
        "measures": { }
    }


@pytest.fixture
def databrary_pilot_dict_fail():
    return {
        "category": 2,
    }


def test_to_dict(expected_pilot_dict):
    assert Pilot(
        record_key=1250,
        record_id=1250,
    ).to_dict() == expected_pilot_dict


def test_from_databrary(databrary_pilot_dict):
    pilot = Pilot.from_databrary(databrary_pilot_dict)
    assert pilot is not None


def test_from_databrary_fail(databrary_pilot_dict_fail):
    with pytest.raises(Exception) as e:
        Pilot.from_databrary(databrary_pilot_dict_fail)
