def test_oid_write_once(self): t = Todo('some text', oid=None) assert not t.oid t.oid = 5 assert t.oid == 5 with pytest.raises(base.ReadOnlyError): t.oid = 6
def test_equality_same_oid(self): t1 = Todo('some text', oid=3) t2 = Todo('diff text', oid=3) assert t1 != t2 t1 = Todo('same text', oid=3) t2 = Todo('same text', oid=3) assert t1 == t2
def test_update_item_bad_id(self): l = self.setup_initial_list([ Todo('first todo item', oid=1, tags=set(['a', 'b'])), Todo('2nd todo item', oid=2, tags=set()), Todo('3rd', oid=10, tags=set(['c'])) ]) with pytest.raises(base.InvalidIDError): l.update_item(6, text='stuff')
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)
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)
def test_remove_item_readd_dupe_id(self): l = self.setup_initial_list([ Todo('old toto item', oid=1, tags=set(['a', 'b', 'c'])), Todo('old toto item', oid=2, tags=set(['b', 'c', 'd'])) ]) l.remove_item(1) l.add_item(Todo('old toto item', oid=1, tags=set(['a', 'b', 'c'])), initial_load=True) assert bool(l.get_item(1))
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'])
def test_update_item_tags(self): l = self.setup_initial_list([ Todo('first todo item', oid=1, tags=set(['a', 'b'])), Todo('2nd todo item', oid=2, tags=set()), Todo('3rd', oid=10, tags=set(['c'])) ]) assert l.tag_set == set(['a', 'b', 'c']) l.update_item(1, tags=['a', 'd']) assert l.tag_set == set(['a', 'd', 'c']) assert l.modified
def test_update_item_text(self): l = self.setup_initial_list([ Todo('original text', oid=1, tags=set(['a', 'b'])), Todo('2nd todo item', oid=2, tags=set()), Todo('3rd', oid=10, tags=set(['c'])) ]) assert l.get_item(1).text == 'original text' l.update_item(1, text='new text') assert l.get_item(1).text == 'new text' assert l.tag_set == set(['a', 'b', 'c']) assert l.modified
def test_update_item_priority(self): l = self.setup_initial_list([ Todo('original text', oid=1, tags=set(['a', 'b'])), Todo('2nd todo item', oid=2, tags=set()), Todo('3rd', oid=10, tags=set(['c'])) ]) assert l.get_item(1).priority == PriorityEnum.DEFAULT.value l.update_item(1, priority=PriorityEnum.URGENT.value) assert l.get_item(1).priority == PriorityEnum.URGENT.value assert l.tag_set == set(['a', 'b', 'c']) assert l.modified
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
def test_update_item_nochange(self): l = self.setup_initial_list([ Todo('first todo item', oid=1, tags=set(['a', 'b'])), Todo('2nd todo item', oid=2, tags=set()), Todo('3rd', oid=10, tags=set(['c'])) ]) l.update_item(1, text='first todo item', priority=PriorityEnum.DEFAULT.value, tags=set(['a', 'b'])) assert not l.modified
def test_query_tags_finished(self): lib = [ Todo('first todo item', oid=1, tags=set(['d', 'a', 'b'])), Todo('2nd todo item', oid=2, priority=PriorityEnum.URGENT.value), Todo('3rd', oid=10, tags=set(['c'])), Todo('4th', oid=3, finished=True, tags=set(['c'])), Todo('3rd', oid=11, tags=set(['a', 'b', 'e'])) ] l = self.setup_initial_list(lib) ret = l.query_items(TodoMatcher(finished=True)) assert ret == [lib[3]]
def test_query_tag(self): lib = [ Todo('first todo item', oid=1, tags=set(['d', 'a', 'b'])), Todo('2nd todo item', oid=2, priority=PriorityEnum.URGENT.value), Todo('3rd', oid=10, tags=set(['a', 'c'])), Todo('4th', oid=3, finished=True, tags=set(['c'])), Todo('3rd', oid=11, tags=set(['a', 'b', 'e'])) ] l = self.setup_initial_list(lib) ret = l.query_items(TodoMatcher(tags=['a'])) assert len(ret) == 3 assert lib[0] in ret assert lib[2] in ret assert lib[4] in ret
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
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)
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()
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)
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
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()
def make_todo(self, oid=3): return Todo('some text', priority=PriorityEnum.URGENT, tags=['tag1', 'tag2'], finished=True, created_date='1527001163.5411422', finished_date='1527015163.5411422', oid=oid)
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()
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()
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
def test_validate_okay_finished(self): self.run_validate([ Todo('some text', priority=PriorityEnum.URGENT.value, tags=set(['some', 'tags']), finished=True, created_date=1234.2134, finished_date=1234.1234, oid=1) ])
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
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()
def test_equality_tag_order(self): t1 = Todo('some text', tags=set(['a', 'b', 'tag']), oid=3) t2 = Todo('some text', tags=set(['a', 'b', 'tag']), oid=3) assert t1 == t2 t1 = Todo('some text', tags=['a', 'b', 'tag'], oid=3) t2 = Todo('some text', tags=set(['a', 'b', 'tag']), oid=3) assert t1 == t2 t1 = Todo('some text', tags=['tag', 'b', 'a', 'tag'], oid=3) t2 = Todo('some text', tags=set(['a', 'b', 'tag']), oid=3) assert t1 == t2 t1 = Todo('some text', tags=['tag', 'a', 'a', 'tag'], oid=3) t2 = Todo('some text', tags=set(['a', 'b', 'tag']), oid=3) assert t1 != t2
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
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()