Exemplo n.º 1
0
    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'}
Exemplo n.º 2
0
    def test_remove_item_tagset(self):
        l = CheatSheet()
        i1 = Entry('clue1', 'answer1', 'prim1', oid=1, tags={'a', 'b', 'c'})
        i2 = Entry('clue1', 'answer1', 'prim2', oid=2, tags={'b', 'c', 'd'})
        l.add_item(i1, initial_load=True)
        l.add_item(i2, initial_load=True)

        assert l.tag_set == {'prim1', 'prim2', 'a', 'b', 'c', 'd'}
        l.remove_item(1)
        assert l.tag_set == {'prim2', 'b', 'c', 'd'}
Exemplo n.º 3
0
    def test_remove_item_overlapping_tags(self):
        # tests that library keeps tags on removal shared with non-removed objects
        l = CheatSheet()
        i1 = Entry('clue1', 'answer1', 'primary1', ['a', 'b'], oid=1)
        i2 = Entry('clue2', 'answer1', 'primary1', ['b', 'c'], oid=2)
        l.add_item(i1, initial_load=True)
        l.add_item(i2, initial_load=True)

        assert l.tag_set == {'primary1', 'a', 'b', 'c'}
        l.remove_item(1)
        assert l.tag_set == {'primary1', 'b', 'c'}  # b still there
Exemplo n.º 4
0
    def test_primary_map(self):
        l = CheatSheet()
        i1 = l.add_item(Entry(clue='c', answer='a', primary='p1', tags={'a'}))
        i2 = l.add_item(Entry(clue='c', answer='a', primary='p1', tags={'a'}))
        i3 = l.add_item(Entry(clue='c', answer='a', primary='p3', tags={'a'}))
        i4 = l.add_item(Entry(clue='c', answer='a', primary='p4', tags={'a'}))

        assert i1 in l.primary_map['p1']
        assert i2 in l.primary_map['p1']
        assert [i3] == l.primary_map['p3']
        assert [i4] == l.primary_map['p4']
        assert len(l.primary_map['p1']) == 2
        l.remove_item(3)
        assert 'p3' not in l.primary_map
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
 def test_remove_item_bad_id(self):
     l = CheatSheet()
     i1 = Entry('clue1', 'answer1', 'prim1', oid=3, tags={'a', 'b', 'c'})
     with pytest.raises(base.InvalidIDError):
         l.remove_item(1)