def test_remove_with_bad_args(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_remove("A")

    assert out.getvalue() == '"A" is neither flat or person.\n'
def test_flat_with_bad_param(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_flat("10")

    assert out.getvalue() == 'Unit "10" not found.\n'
def test_flat_with_param(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_flat("1")

    assert out.getvalue() == "Owners:\n 1. Petr Novák\n"
def test_add_without_param(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_add("")

    assert out.getvalue() == 'No flats passed.\nuse "add [flat1] [flat2]"\n'
def test_remove_with_empty_args(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_remove("")

    assert out.getvalue().startswith("No argument")
def test_flat_without_params(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_flat("")

    assert out.getvalue() == " 1   2  *3\n"
def test_flat_with_representation(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_flat("3")

    assert out.getvalue() == ("Owners:\n 1. Oldřich Starý\n"
                              "Represented by Radoslava Květná\n")
def test_remove_with_not_represented_flat(
        simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_remove("1")

    assert out.getvalue() == '"1" is not represented.\n'
def test_remove_with_person(simple_building: business.Building) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)

    cmd.do_remove("Radoslava Květná")

    assert out.getvalue() == ("Radoslava Květná no longer represents 3.\n"
                              "Radoslava Květná left.\n")
    assert not simple_building.get_flat("3").represented
    assert not simple_building.get_person_names("Radoslava Květná")
def test_complete_flat() -> None:
    model = business.Building(
        [create_flat("777/1"),
         create_flat("777/2"),
         create_flat("778/3")])
    cmd = __main__.AppCmd(model)

    possibilities = cmd.complete_flat("777", "flat 777/", 9, 9)

    assert possibilities == ["777/1", "777/2"]
def test_complete_remove() -> None:
    model = business.Building([
        create_flat("777/1",
                    represented=business.Person("Radoslava Květná",
                                                datetime.min))
    ])
    cmd = __main__.AppCmd(model)
    model.add_person("Peter Pan")

    possibilities = cmd.complete_remove("", "remove ", 9, 9)

    assert possibilities == ["777/1", "Peter Pan"]
def test_add_inform_about_extra_unit(
        building_with_one_owner: business.Building,
        monkeypatch: MonkeyPatch) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(building_with_one_owner, stdout=out)
    monkeypatch.setattr("shromazdeni.__main__.choice_from",
                        lambda *args, **kwargs: 1)
    monkeypatch.setattr("shromazdeni.__main__.confirm", lambda q: True)

    cmd.do_add("2")

    assert out.getvalue() == ("2 owners:\n 1. Petr Novák\n 2. Jana Nová\n"
                              "Should Jana Nová also represent: 1?\n")
def test_add_new_person(simple_building: business.Building,
                        monkeypatch: MonkeyPatch) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)
    voter = business.Person("Jakub Rychlý", datetime.min)
    monkeypatch.setattr("shromazdeni.__main__.choice_from",
                        lambda *args, **kwargs: 0)
    monkeypatch.setattr("builtins.input", lambda q: "Jakub Rychlý")
    monkeypatch.setattr("shromazdeni.__main__.confirm", lambda q: True)

    cmd.do_add("1")

    assert out.getvalue() == "1 owners:\n 1. Petr Novák\n"
    assert simple_building.get_flat("1").represented == voter
def test_add_ask_for_other_unit(building_with_one_owner: business.Building,
                                monkeypatch: MonkeyPatch) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(building_with_one_owner, stdout=out)
    voter = business.Person("Petr Novák", datetime.min)
    monkeypatch.setattr("shromazdeni.__main__.choice_from",
                        lambda *args, **kwargs: 1)
    monkeypatch.setattr("shromazdeni.__main__.confirm", lambda q: True)

    cmd.do_add("1")

    assert out.getvalue() == (
        "1 owners:\n 1. Petr Novák\n2 owners:\n 1. Petr Novák\n 2. Jana Nová\n"
    )
    assert building_with_one_owner.get_flat("1").represented == voter
    assert building_with_one_owner.get_flat("2").represented == voter
def test_add(simple_building: business.Building,
             monkeypatch: MonkeyPatch) -> None:
    out = io.StringIO()
    cmd = __main__.AppCmd(simple_building, stdout=out)
    voter = business.Person("Petr Novák", datetime.min)
    choice_from = mock.Mock(return_value=2)
    monkeypatch.setattr("shromazdeni.__main__.choice_from", choice_from)

    cmd.do_add("1 2 3")

    assert out.getvalue() == (
        "1 owners:\n 1. Petr Novák\n"
        "2 owners:\n 1. Jana Nová\n"
        "Ignoring 3. It is already represented by Radoslava Květná.\n")
    assert simple_building.get_flat("1").represented == voter
    assert simple_building.get_flat("2").represented == voter
    choice_from.assert_called_once_with(
        "Select representation",
        ["New Person", "Jana Nová", "Petr Novák", "Radoslava Květná"],
        out,
    )