def test_remove_item_complex(self): init = [ Entry('clue1', 'answer1', 'prim1', oid=1, tags={'a', 'b'}), Entry('clue2', 'answer2', 'prim2', oid=2, tags={}), Entry('clue3', 'answer3', 'prim2', oid=10, tags={'c'}), ] newly = [ Entry('new1', 'new1', 'prim3', tags={'b', 'd'}), Entry('new2', 'new2', 'prim2', tags=set()) ] l = CheatSheet() for i in init: l.add_item(i, initial_load=True) for n in newly: l.add_item(n, initial_load=False) assert l.size() == 5 assert l.tag_set == {'prim1', 'prim2', 'prim3', 'a', 'b', 'c', 'd'} l.remove_item(1) assert l.size() == 4 assert l.tag_set == {'prim2', 'prim3', 'b', 'c', 'd'} assert l.modified l.add_item(Entry('clue1', 'answer1', 'prim1', tags={'a', 'b'}), initial_load=False) assert l.size() == 5 assert l.tag_set == {'prim1', 'prim2', 'prim3', 'a', 'b', 'c', 'd'}
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_add_item_new(self): TestCheatSheet.mock_time.return_value = MOCK_TIME l = CheatSheet() i = Entry('clue1', 'answer1', 'primary1', ['a', 'b']) l.add_item(i, initial_load=False) assert l.tag_set == {'primary1', 'a', 'b'} assert l.size() == 1 assert l.modified == True assert l.modified_date == MOCK_TIME assert TestCheatSheet.mock_time.called_once_with()
def test_add_item_new_primary_in_tag_set(self): l = CheatSheet() i1 = Entry('clue1', 'answer1', 'primary1', ['tag1', 'tag2']) i2 = Entry('clue1', 'answer1', 'primary2', ['tag2', 'tag3']) l.add_item(i1, initial_load=False) assert l.tag_set == set(['primary1', 'tag1', 'tag2']) l.add_item(i2, initial_load=False) assert l.tag_set == set( ['primary1', 'primary2', 'tag1', 'tag2', 'tag3']) assert l.size() == 2 assert l.modified == True
def test_add_item_initial_load(self): l = CheatSheet(modified_date=1234.1234) i1 = Entry('clue1', 'answer1', 'primary1', ['tag1', 'tag2'], oid=1) i2 = Entry('clue2', 'answer2', 'primary1', ['tag2', 'tag3']) assert l.modified == False assert l.modified_date == 1234.1234 l.add_item(i1, initial_load=True) assert l.modified == False assert l.modified_date == 1234.1234 l.add_item(i2, initial_load=False) assert l.tag_set == set(['primary1', 'tag1', 'tag2', 'tag3']) assert l.size() == 2 assert l.modified == True assert l.modified_date == MOCK_TIME
def test_init_defaults(self): l = CheatSheet() assert l.version == None assert l.modified_date == None assert l.modified == False assert l.size() == 0
def test_init(self): l = CheatSheet(version='0.1.3', modified_date=1234.1234) assert l.version == '0.1.3' assert l.modified_date == 1234.1234 assert l.modified == False assert l.size() == 0