def test_list_representation_equality():
    assert ListModel("list", ["1", "2"]) == ListModel("list", ["1", "2"])
    assert ListModel("list", ["1", "2"]) != ListModel("list", ["1"])

    assert ListModel("list", ["1"],
                     primary_person="1") == ListModel("list", ["1"],
                                                      primary_person="1")
    assert ListModel("list", ["1"], primary_person="1") != ListModel(
        "list", ["1"], primary_person="2")

    assert ListModel("list", ["1"]) != ["1"]
def test_first_raises_index_error_when_list_is_empty():
    new_list = ListModel("people", [])

    with pytest.raises(IndexError) as error:
        new_list.first  # pylint: disable=pointless-statement

    assert "unable to access first item in list, list 'people' is empty" in str(
        error.value)
def test_repr():
    test_list = ListModel("people", ["primaryperson"],
                          primary_person="primaryperson")
    serialized = [{
        "name": "people",
        "primary_person": "primaryperson",
        "items": ["123", "primaryperson"],
    }]

    list_store = ListStore.deserialize(serialized)

    assert "primary_person=primaryperson" in repr(test_list)
    assert "items=['primaryperson']" in repr(test_list)
    assert "primaryperson" in repr(list_store)
def test_unique_id_generation():
    """
    Ensure that every id generated is unique per questionnaire.
    """
    # Mock the app.data_models.list_store.random_string method to return duplicates.
    with patch(
        "app.data_models.list_store.random_string",
        side_effect=["first", "first", "second"],
    ):
        store = ListStore()
        # pylint: disable=protected-access
        store._lists["test"] = ListModel(name="test", items=["first"])
        result = store._generate_identifier()

    assert result == "second"
def test_get_item():
    store = ListStore()
    assert store["not_a_list"] == ListModel("not_a_list")
def test_first():
    test_list = ListModel("people", ["abcde", "12345"])
    assert test_list.first == "abcde"
def test_list_representation_equal():
    assert ListModel(["123", "123"]) != "123"

    assert ListModel(["1", "2"]) == ListModel(["1", "2"])
def test_list_model_get_item():
    assert ListModel("list", ["1", "2"])[0] == "1"
    assert ListModel("list", ["1", "2"])[-1] == "2"