示例#1
0
 def test_validate_nonset_tags(self):
     l = TodoList()
     l.add_item(Todo('some text'))
     l.get_item(1).tags = set(['a', 'b'])
     l.validate()
     with pytest.raises(base.ValidationError):
         l.get_item(1).tags = ['a', 'b']
         l.validate()
示例#2
0
    def test_get_item_new_item(self):
        l = TodoList()
        i1 = Todo('old toto item')
        i2 = Todo('new toto item')
        l.add_item(i1, initial_load=False)
        l.add_item(i2, initial_load=False)

        assert i2 == l.get_item(2)
示例#3
0
 def test_validate_finished_None(self):
     l = TodoList()
     l.add_item(Todo('some text'))
     l.get_item(1).finished = False
     l.validate()
     with pytest.raises(base.ValidationError):
         l.get_item(1).finished = None
         l.validate()
示例#4
0
 def test_complete_item_reverse(self):
     l = TodoList()
     i1 = Todo('old toto item', oid=3, tags=set(['a', 'b']))
     l.add_item(i1, initial_load=True)
     l.complete_item(3, set_complete=True)
     assert l.get_item(3).finished
     assert l.get_item(3).finished_date == 4163.5411422
     l.complete_item(3, set_complete=False)
     assert not l.get_item(3).finished
     assert not l.get_item(3).finished_date
示例#5
0
 def test_validate_finished_not_bool(self):
     l = TodoList()
     l.add_item(Todo('some text'))
     l.get_item(1).finished = True
     l.get_item(1).finished_date = 1234.1234
     l.validate()
     with pytest.raises(base.ValidationError):
         l.get_item(1).finished = 'ham'
         l.get_item(1).finished_date = 1234.1234
         l.validate()
示例#6
0
    def test_add_item_new(self):
        l = TodoList()
        item = Todo('new toto item')
        l.add_item(item, initial_load=False)

        assert item.created_date == 4163.5411422
        assert item.finished == False
        assert not item.finished_date
        assert l.size() == 1
        assert l.modified == True
        assert l.modified_date == 4163.5411422
        assert TestTodoList.mock_time.call_count == 2
示例#7
0
 def test_complete_item_already_completed(self):
     l = TodoList()
     i1 = Todo('old toto item', oid=3, tags=set(['a', 'b']))
     l.add_item(i1, initial_load=True)
     l.complete_item(3, set_complete=True)
     with pytest.raises(base.IllegalStateError):
         l.complete_item(3, set_complete=True)
示例#8
0
    def test_add_item_initial_load(self):
        l = TodoList()
        i1 = Todo('old item',
                  oid=1,
                  tags=['tag1', 'tag2'],
                  created_date='some date')
        i2 = Todo('new item', oid=2, tags=['tag2', 'tag3'], finished=True)

        assert l.modified == False
        l.add_item(i1, initial_load=True)
        l.add_item(i2, initial_load=True)
        assert i1.created_date == 'some date'
        assert i2.finished == True
        assert l.tag_set == set(['tag1', 'tag2', 'tag3'])
        assert l.size() == 2
        assert l.modified == False
示例#9
0
    def test_get_item_id_inc(self):
        l = TodoList()
        i1 = Todo('old toto item', oid=10)
        i2 = Todo('new toto item')
        l.add_item(i1, initial_load=True)
        l.add_item(i2, initial_load=False)

        assert i2 == l.get_item(11)
示例#10
0
    def test_add_item_initial_load_no_id(self):
        l = TodoList()
        i1 = Todo('old item', tags=['tag1', 'tag2'])

        with pytest.raises(base.IllegalStateError):
            l.add_item(i1, initial_load=True)
        l.add_item(i1, initial_load=False)
示例#11
0
    def test_add_item_new_tag_set(self):
        l = TodoList()
        i1 = Todo('old item', tags=['tag1', 'tag2'])
        i2 = Todo('new item', tags=['tag2', 'tag3'])

        l.add_item(i1, initial_load=False)
        assert l.tag_set == set(['tag1', 'tag2'])
        l.add_item(i2, initial_load=False)
        assert l.tag_set == set(['tag1', 'tag2', 'tag3'])
        assert l.size() == 2
        assert l.modified == True
示例#12
0
 def test_modified_date_remove(self):
     l = TodoList(version='version str', modified_date=1234.1234)
     assert l.modified_date == 1234.1234
     l.add_item(Todo('a new todo', oid=1, created_date=4.4),
                initial_load=True)
     assert l.modified_date == 1234.1234
     l.remove_item(1)
     assert l.modified_date == 4163.5411422
示例#13
0
    def test_remove_item_tagset(self):
        l = TodoList()
        i1 = Todo('old toto item', oid=1, tags=set(['a', 'b', 'c']))
        i2 = Todo('old toto item', oid=2, tags=set(['b', 'c', 'd']))
        l.add_item(i1, initial_load=True)
        l.add_item(i2, initial_load=True)

        assert l.tag_set == set(['a', 'b', 'c', 'd'])
        l.remove_item(1)
        assert l.tag_set == set(['b', 'c', 'd'])
示例#14
0
 def test_add_item_new_has_id(self):
     l = TodoList()
     item = Todo('new toto item', oid=1)
     with pytest.raises(base.IllegalStateError):
         l.add_item(item, initial_load=False)
示例#15
0
 def test_add_item_new_is_finished(self):
     l = TodoList()
     with pytest.raises(base.IllegalStateError):
         l.add_item(Todo('new', finished=True, finished_date=1234.1234))
         l.validate()
示例#16
0
 def test_validate_invalid_priority(self):
     l = TodoList()
     l.add_item(Todo('some text'))
     l.get_item(1).priority = PriorityEnum.URGENT.value
     l.validate()
     with pytest.raises(base.ValidationError):
         l.get_item(1).priority = None
         l.validate()
     with pytest.raises(base.ValidationError):
         l.get_item(1).priority = 16
         l.validate()
     with pytest.raises(base.ValidationError):
         l.get_item(1).priority = 'cactus'
         l.validate()
     l.get_item(1).priority = PriorityEnum.DEFAULT.value
     l.validate()
示例#17
0
 def test_validate_invalid_tags(self):
     l = TodoList()
     l.add_item(Todo(text='text', tags={'a'}))
     l.validate()
     with pytest.raises(base.ValidationError):
         l = TodoList()
         l.add_item(Todo(text='text', tags={'a', ''}))
         l.validate()
     with pytest.raises(base.ValidationError):
         l = TodoList()
         l.add_item(Todo(text='text', tags={'a', 34}))
         l.validate()
     with pytest.raises(base.ValidationError):
         l = TodoList()
         l.add_item(Todo(text='text', tags={'a', None}))
         l.validate()
示例#18
0
 def test_validate_new_item(self):
     l = TodoList()
     l.add_item(Todo('some text'))
     l.validate()
示例#19
0
 def test_add_item_initial_load_dupe_id(self):
     l = TodoList()
     l.add_item(Todo('new todo item', oid=5), initial_load=True)
     with pytest.raises(base.IllegalStateError):
         l.add_item(Todo('new todo item', oid=5), initial_load=True)
示例#20
0
 def setup_initial_list(self, todos):
     l = TodoList()
     for t in todos:
         l.add_item(t, initial_load=True)
     return l
示例#21
0
 def run_validate(self, todos):
     l = TodoList()
     for t in todos:
         l.add_item(t, initial_load=True)
     l.validate()
示例#22
0
 def test_remove_item_bad_id(self):
     l = TodoList()
     i1 = Todo('old toto item', oid=3, tags=set(['a', 'b']))
     with pytest.raises(base.InvalidIDError):
         l.remove_item(1)
示例#23
0
 def test_add_item_new_has_creation_date(self):
     l = TodoList()
     with pytest.raises(base.IllegalStateError):
         l.add_item(Todo('new', created_date=1234.1234))
示例#24
0
 def test_get_item_bad_id(self):
     l = TodoList()
     i1 = Todo('old toto item', oid=10)
     l.add_item(i1, initial_load=True)
     with pytest.raises(base.InvalidIDError):
         l.get_item(1)
示例#25
0
    def test_to_dict(self):
        l = TodoList(version='version str', modified_date=1234.1234)
        init = [
            Todo('text 1', oid=1, created_date=1234.1),
            Todo('text 2',
                 oid=2,
                 created_date=1234.2,
                 finished=True,
                 finished_date=2345.2),
            Todo('text 5', oid=5, created_date=1234.5, tags=['c', 'd'])
        ]
        init_exp = [{
            'oid': 1,
            'text': 'text 1',
            'priority': PriorityEnum.DEFAULT.value,
            'tags': [],
            'finished': False,
            'created_date': 1234.1,
            'finished_date': None
        }, {
            'oid': 2,
            'text': 'text 2',
            'priority': PriorityEnum.DEFAULT.value,
            'tags': [],
            'finished': True,
            'created_date': 1234.2,
            'finished_date': 2345.2
        }, {
            'oid': 5,
            'text': 'text 5',
            'priority': PriorityEnum.DEFAULT.value,
            'tags': ['c', 'd'],
            'finished': False,
            'created_date': 1234.5,
            'finished_date': None
        }]
        new = [Todo('new item 1'), Todo('new item 2')]
        new_exp = [{
            'oid': 6,
            'text': 'new item 1',
            'priority': PriorityEnum.DEFAULT.value,
            'tags': [],
            'finished': False,
            'created_date': 4163.5411422,
            'finished_date': None
        }, {
            'oid': 7,
            'text': 'new item 2',
            'priority': PriorityEnum.DEFAULT.value,
            'tags': [],
            'finished': False,
            'created_date': 4163.5411422,
            'finished_date': None
        }]

        for i in init:
            l.add_item(i, initial_load=True)
        for n in new:
            l.add_item(n, initial_load=False)

        d = l.to_dict()['todo_list']
        assert d['version'] == 'version str'
        assert d['modified_date'] == 4163.5411422
        assert len(d.keys()) == 3
        todos = d['todos']
        assert len(todos) == 5
        for e in init_exp:
            assert e in todos
        for e in new_exp:
            assert e in todos
示例#26
0
 def test_modified_date_add_new(self):
     l = TodoList(version='version str', modified_date=1234.1234)
     assert l.modified_date == 1234.1234
     l.add_item(Todo('a new todo'))
     assert l.modified_date == 4163.5411422
示例#27
0
    def test_remove_item(self):
        l = TodoList()
        i1 = Todo('old toto item', oid=3, tags=set(['a', 'b']))
        l.add_item(i1, initial_load=True)

        assert l.size() == 1
        assert l.get_item(3) == i1
        assert l.tag_set == set(['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
示例#28
0
    def test_remove_item_after_initial(self):
        l = TodoList()
        i1 = Todo('old toto item', tags=set(['a', 'b']))
        l.add_item(i1, initial_load=False)

        assert l.size() == 1
        assert l.get_item(1) == i1
        assert l.tag_set == set(['a', 'b'])
        l.remove_item(1)
        assert l.size() == 0
        with pytest.raises(base.InvalidIDError):
            l.get_item(1)
        assert l.tag_set == set()
示例#29
0
    def test_from_dict(self):
        d = {
            'todo_list': {
                'version':
                'version str',
                'modified_date':
                4.1,
                'todos': [{
                    'oid': 1,
                    'tags': [],
                    'priority': PriorityEnum.URGENT.value,
                    'text': 'text 1',
                    'finished': False,
                    'created_date': 1234.1,
                    'finished_date': None
                }, {
                    'oid': 2,
                    'tags': [],
                    'priority': PriorityEnum.DEFAULT.value,
                    'text': 'text 2',
                    'finished': True,
                    'created_date': 1234.2,
                    'finished_date': 2345.2
                }, {
                    'oid': 5,
                    'tags': ['c', 'd'],
                    'priority': PriorityEnum.DEFAULT.value,
                    'text': 'text 5',
                    'finished': False,
                    'created_date': 1234.5,
                    'finished_date': None
                }, {
                    'oid': 6,
                    'tags': [],
                    'priority': PriorityEnum.DEFAULT.value,
                    'text': 'new item 1',
                    'finished': False,
                    'created_date': 4163.5411422,
                    'finished_date': None
                }, {
                    'oid': 7,
                    'tags': [],
                    'priority': PriorityEnum.DEFAULT.value,
                    'text': 'new item 2',
                    'finished': False,
                    'created_date': 4163.5411422,
                    'finished_date': None
                }]
            }
        }
        exp_todos = [
            Todo('text 1',
                 oid=1,
                 created_date=1234.1,
                 priority=PriorityEnum.URGENT.value),
            Todo('text 2',
                 oid=2,
                 created_date=1234.2,
                 finished=True,
                 finished_date=2345.2),
            Todo('text 5', oid=5, created_date=1234.5, tags=['c', 'd']),
            Todo('new item 1', oid=6, created_date=4163.5411422),
            Todo('new item 2', oid=7, created_date=4163.5411422)
        ]
        l = TodoList.from_dict(d)
        assert not l.modified
        assert l.version == 'version str'
        assert l.modified_date == 4.1

        assert l.size() == 5
        for t in l.items:
            assert t in exp_todos
        assert l.tag_set == {'c', 'd'}
示例#30
0
 def test_init_defaults(self):
     l = TodoList()
     assert l.version == None
     assert l.modified_date == None
     assert l.modified == False
     assert l.size() == 0