import dataclasses
import typing

from dataclass_structor import structure, unstructure

from ._fixtures import DataClassGuest as Guest


@dataclasses.dataclass
class Invite:
    email: str
    guests: typing.List["Guest"]


def test_unstructure__invite_with_no_guests():
    value_type = Invite(email="<EMAIL>", guests=[])
    expected = {"email": "<EMAIL>", "guests": []}
    assert unstructure(value_type) == expected


def test_unstructure__invite_with_a_guest():
    value_type = Invite(
        email="<EMAIL>", guests=[Guest(first_name="<NAME>")]
    )
    expected = {
        "email": "<EMAIL>",
        "guests": [{"first_name": "<NAME>"}],
    }
    assert unstructure(value_type) == expected


def test_structure__invite_with_no_guests():
    expected = Invite(email="<EMAIL>", guests=[])
    value_to_structure = {"email": "<EMAIL>", "guests": []}
    assert structure(value_to_structure, Invite) == expected


def test_structure__invite_with_a_guest():
    expected = Invite(
        email="<EMAIL>", guests=[Guest(first_name="<NAME>")]
    )
    value_to_structure = {
        "email": "<EMAIL>",
        "guests": [{"first_name": "<NAME>"}],
    }
    assert structure(value_to_structure, Invite) == expected

import dataclasses
import typing

from dataclass_structor import structure, unstructure

from ._fixtures import DataClassGuest as Guest


@dataclasses.dataclass
class Invite:
    email: str
    guests: typing.List["Guest"]


def test_unstructure__invite_with_no_guests():
    value_type = Invite(email="<EMAIL>", guests=[])
    expected = {"email": "<EMAIL>", "guests": []}
    assert unstructure(value_type) == expected


def test_unstructure__invite_with_a_guest():
    value_type = Invite(
        email="<EMAIL>", guests=[Guest(first_name="<NAME>")]
    )
    expected = {
        "email": "<EMAIL>",
        "guests": [{"first_name": "<NAME>"}],
    }
    assert unstructure(value_type) == expected


def test_structure__invite_with_no_guests():
    expected = Invite(email="<EMAIL>", guests=[])
    value_to_structure = {"email": "<EMAIL>", "guests": []}
    assert structure(value_to_structure, Invite) == expected


def test_structure__invite_with_a_guest():
    expected = Invite(
        email="<EMAIL>", guests=[Guest(first_name="<NAME>")]
    )
    value_to_structure = {
        "email": "<EMAIL>",
        "guests": [{"first_name": "<NAME>"}],
    }
    assert structure(value_to_structure, Invite) == expected
