def test_count_done_yesterday(self): """ Test that message about count of items done yesterday is shown. """ add("step that will be marked as done yesterday") items = load_items() pk = items[0].pk # updated time to 1 day 1 second ago query = "UPDATE item SET is_done='TRUE', done_at='{done_at}' WHERE pk={pk}".format( pk=pk, done_at=time.strftime( DATE_FORMAT, time.localtime(time.time() - 60 * 60 * 24 - 1) ) ) con = sqlite3.connect(PROGRESS_DB_FILE_NAME) cur = con.cursor() cur.execute(query) con.commit() con.close() output = subprocess.check_output( '../progressio/progressio.py count', stderr=subprocess.STDOUT, shell=True) print output self.assertTrue("done yesterday: 1" in output)
def test_done(self): """Test adding one item""" add('step that will be done') items = load_items() pk = items[0].pk done(pk) i = get_item(pk) self.assertEqual(i.is_done, 'TRUE')
def test_add_subitem(self): """Test that subitem may be added to some item.""" TEST_TEXT = 'test3' TEST_TEXT_SUBITEM = 'test33' add(TEST_TEXT) items = load_items() parent_pk = items[0].pk add(TEST_TEXT_SUBITEM, parent_pk=parent_pk) subitem_pk = get_item(parent_pk).children[0] self.assertEqual(get_item(subitem_pk).title, TEST_TEXT_SUBITEM)
def test_addition(self): """Test adding one item""" add('test2') add('test') items = load_items() is_added = False for i in items: if i.title == 'test2': is_added = True break self.assertTrue(is_added)
def test_active(self): """ Test activating one item. """ add('step that will be done and then activated again') items = load_items() pk = items[0].pk done(pk) active(pk) i = get_item(pk) self.assertEqual(i.is_done, 'FALSE')
def test_count(self): add('test1') add('test2') out, err = Popen(["../progressio/progressio.py", "count"], stdout=PIPE).communicate() self.assertTrue('done: 0' in out) self.assertTrue('total items: 2' in out) items = load_items() pk = items[0].pk done(pk) out, err = Popen(["../progressio/progressio.py", "count"], stdout=PIPE).communicate() self.assertTrue('done: 1' in out) self.assertTrue('total items: 2' in out)
def test_count_done_today(self): """ Test that message about count of items done today is shown. """ add("step that will be done") items = load_items() pk = items[0].pk p = subprocess.Popen( '../progressio/progressio.py done {}'.format(pk), shell=True) p.communicate('y\n') output = subprocess.check_output( '../progressio/progressio.py count', stderr=subprocess.STDOUT, shell=True) self.assertTrue("done today: 1" in output)
def test_active_cli(self): """ Test command line version of active command. """ add('step that will be done and then activated again') items = load_items() pk = items[0].pk done(pk) output = subprocess.check_output( "../progressio/progressio.py active {}".format(pk), stderr=subprocess.STDOUT, shell=True) print output self.assertTrue("Item {} is marked as active".format(pk) in output) i = get_item(pk) self.assertEqual(i.is_done, 'FALSE')
def test_log(self): add('test1') add('test2') out, err = Popen(["../progressio/progressio.py", "log"], stdout=PIPE).communicate() self.assertTrue('test1' in out) self.assertTrue('test2' in out) items = load_items() pk = items[0].pk done(pk) out, err = Popen(["../progressio/progressio.py", "log"], stdout=PIPE).communicate() self.assertFalse(items[0].title in out) out, err = Popen(["../progressio/progressio.py", "log", "-d"], stdout=PIPE).communicate() self.assertTrue(items[0].title in out)
def test_if_not_confirmed_not_deleted(self): """ If delete operation is not confirmed item is not deleted. """ # create progress.db p = subprocess.Popen('../progressio/progressio.py', stdin=subprocess.PIPE) p.communicate('y\n') # add item, it is added with pk=1 add('item to be deleted') p = subprocess.Popen( '../progressio/progressio.py delete 1', stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) output = p.communicate('n\n')[0] self.assertFalse("Deleted item 1" in output) # item is in database self.assertFalse(get_item(1) is None)
def test_item_can_be_deleted(self): """ Item can be deleted and message is shown. """ # create progress.db p = subprocess.Popen('../progressio/progressio.py', stdin=subprocess.PIPE) p.communicate('y\n') # add item, it is added with pk=1 add('item to be deleted') p = subprocess.Popen( '../progressio/progressio.py delete 1', stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) output = p.communicate('y\n')[0] self.assertTrue("Deleted item 1" in output) # item is not in database self.assertTrue(get_item(1) is None)
def test_add_subsubitem(self): """ Subitem to subitem can be added. """ TEST_TEXT_SUBITEM = 'sub test' TEST_TEXT_SUBSUBITEM = 'sub sub test' add(TEST_TEXT_SUBITEM) add('test2') items = load_items() parent_pk = items[1].pk add(TEST_TEXT_SUBITEM, parent_pk=parent_pk) parent = get_item(parent_pk) subitem = get_item(parent.children[0]) add(TEST_TEXT_SUBSUBITEM, parent_pk=subitem.pk) subitem = get_item(subitem.pk) subsubitem_pk = subitem.children[0] self.assertEqual(get_item(subsubitem_pk).title, TEST_TEXT_SUBSUBITEM)
def test_subitem_tabulated(self): add('test1') add('test2') add('subitem of test1', parent_pk=1) out, err = Popen(["../progressio/progressio.py"], stdout=PIPE).communicate() self.assertTrue('1 - test1\n 3 - subitem of test1' in out)
def test_get_non_existant_item(self): add('test') self.assertTrue(get_item(9999999) is None)