from pytest_mock import MockerFixture

from tests.scsi.utils import MockedSCSIDevice

VALID_IDENTIFY_RESPONSE = bytes(
    [
        0x40,
        0x00,
        0xFF,
        0x3F,
        0x37,
        0xC8,
        0x10,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x3F,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x33,
        0x51,
        0x21,
        0x5A,
        0x42,
        0x4E,
        0x4B,
        0x30,
        0x32,
        0x33,
        0x33,
        0x35,
        0x32,
        0x38,
        0x20,
        0x54,
        0x20,
        0x20,
        0x20,
        0x20,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x56,
        0x52,
        0x30,
        0x54,
        0x42,
        0x31,
        0x51,
        0x36,
        0x61,
        0x53,
        0x73,
        0x6D,
        0x6E,
        0x75,
        0x20,
        0x67,
        0x53,
        0x53,
        0x20,
        0x44,
        0x36,
        0x38,
        0x20,
        0x30,
        0x56,
        0x45,
        0x20,
        0x4F,
        0x54,
        0x31,
        0x20,
        0x42,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
        0x20,
    ]
)


def test_identify(mocker: MockerFixture):
    """
    Test we're properly parsing the response to an SCSI/ATA IDENTIFY.
    """
    get_device = mocker.patch(
        "smartie.device.get_device",
        return_value=MockedSCSIDevice(
            "/dev/test", return_data=VALID_IDENTIFY_RESPONSE
        ),
    )

    with get_device("/dev/test") as device:
        assert device.model == "Samsung SSD 860 EVO 1TB"
        assert device.serial == "Q3Z!NB0K325382T"
