def test_update_item_clue(self): init = [ Entry('orig text 1', 'answer1', 'prim1', oid=1, tags={'a', 'b'}), ] l = CheatSheet() for i in init: l.add_item(i, initial_load=True) assert not l.modified assert l.get_item(1).answer == 'answer1' l.update_item(1, answer='answer new') assert l.get_item(1).answer == 'answer new' assert l.modified assert l.modified_date == MOCK_TIME
def test_remove_item_after_initial(self): # removes item that was not loaded initially l = CheatSheet() i1 = Entry('clue1', 'answer1', 'primary1', ['a', 'b']) l.add_item(i1, initial_load=False) assert l.size() == 1 assert l.get_item(1) == i1 assert l.tag_set == {'primary1', 'a', 'b'} l.remove_item(1) assert l.size() == 0 with pytest.raises(base.InvalidIDError): l.get_item(1) assert l.tag_set == set()
def test_remove_item(self): l = CheatSheet() i1 = Entry('clue1', 'answer1', 'primary1', ['a', 'b'], oid=3) l.add_item(i1, initial_load=True) assert l.size() == 1 assert l.get_item(3) == i1 assert l.tag_set == set(['primary1', 'a', 'b']) l.remove_item(3) assert l.size() == 0 with pytest.raises(base.InvalidIDError): l.get_item(3) assert l.tag_set == set() assert l.modified assert l.modified_date == MOCK_TIME
def test_update_item_tags_to_set(self): l = CheatSheet() l.add_item(Entry('1', 'c1', 'prim1', tags={'a', 'b'}, oid=1), initial_load=True) l.update_item(1, tags=['a', 'b']) assert l.get_item(1).tags == {'a', 'b'} assert not l.modified
def test_update_item_clue(self): init = [ Entry('orig text 1', 'answer1', 'prim1', oid=1, tags={'a', 'b'}), Entry('orig text 2', 'answer2', 'prim2', oid=2, tags={}), Entry('orig text 3', 'answer3', 'prim2', oid=10, tags={'c'}), ] l = CheatSheet() for i in init: l.add_item(i, initial_load=True) assert not l.modified assert l.get_item(1).clue == 'orig text 1' l.update_item(1, clue='new text 1') assert l.get_item(1).clue == 'new text 1' assert l.modified assert l.modified_date == MOCK_TIME
def test_update_item_tags(self): init = [ Entry('orig text 1', 'answer1', 'prim1', oid=1, tags={'a', 'b'}), Entry('orig text 2', 'answer2', 'prim2', oid=2, tags={}), Entry('orig text 3', 'answer3', 'prim2', oid=10, tags={'c'}), ] l = CheatSheet() for i in init: l.add_item(i, initial_load=True) assert l.tag_set == {'prim1', 'prim2', 'a', 'b', 'c'} assert l.get_item(1).tags == {'a', 'b'} l.update_item(1, tags={'a', 'd'}) assert l.tag_set == {'prim1', 'prim2', 'a', 'd', 'c'} assert l.get_item(1).tags == {'a', 'd'} assert l.modified assert l.modified_date == MOCK_TIME
def test_get_item_id_inc(self): l = CheatSheet() i1 = Entry('clue1', 'answer1', 'primary1', ['tag1', 'tag2'], oid=10) i2 = Entry('clue2', 'answer1', 'primary1', ['tag1', 'tag2']) l.add_item(i1, initial_load=True) l.add_item(i2, initial_load=False) assert i2 == l.get_item(11)
def test_validate_nonset_tags(self): l = CheatSheet() l.add_item(Entry(clue='c', answer='a', primary='prim', tags={'a'})) l.validate() with pytest.raises(base.ValidationError): l = CheatSheet() l.add_item(Entry(clue='c', answer='a', primary='prim', tags=set())) l.get_item(1).tags = ['a'] l.validate()
def test_get_item_bad_id(self): l = CheatSheet() i1 = Entry('clue1', 'answer1', 'primary1', ['tag1', 'tag2'], oid=10) l.add_item(i1, initial_load=True) with pytest.raises(base.InvalidIDError): l.get_item(1)