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") serialised = [ { "name": "people", "primary_person": "primaryperson", "items": ["123", "primaryperson"], } ] list_store = ListStore.deserialise(serialised) 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_model.list_store.random_string method to return duplicates. with patch( "app.data_model.list_store.random_string", side_effect=["first", "first", "second"], ): list_store = ListStore() # pylint: disable=protected-access list_store._lists["test"] = ListModel(name="test", items=["first"]) result = list_store._generate_identifier() assert result == "second"
def test_list_representation_equal(): assert ListModel(["123", "123"]) != "123" assert ListModel(["1", "2"]) == ListModel(["1", "2"])
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"