def test_now(self): # test with no entries running toggl.CLI()._stop_time_entry([]) self.list.reload() self.assertIsNone(self.list.now()) # test with running entry toggl.CLI()._start_time_entry([desc('now')]) self.list.reload() current = self.list.now() self.assertIsNotNone(current) self.assertEquals(current.get('description'), desc('now')) current.stop()
def test_find_by_description(self): toggl.CLI()._start_time_entry([desc('find_by_description')]) self.list.reload() # searching for something that doesn't exist returns none self.assertIsNone( self.list.find_by_description('foobar') ) # otherwise, we get an entry with the matching description entry1 = self.list.find_by_description(desc('find_by_description')) self.assertEquals( entry1.get('description'), desc('find_by_description')) # start another entry with the same description toggl.CLI()._start_time_entry([desc('find_by_description')]) self.list.reload() # searching should return the newer entry entry2 = self.list.find_by_description(desc('find_by_description'))
def test_continue_from_today(self): # create a completed time today now = datetime.datetime.utcnow().isoformat() toggl.CLI()._add_time_entry([desc('continue2'), now, 'd1:0:0']) # find it entry = self.find_time_entry(desc('continue2')) self.assertIsNotNone(entry) # continue it entry.continue_entry() # find it again, this time, it should be running. entry = self.find_time_entry(desc('continue2')) self.assertTrue(int(entry.get('duration')) < 0)
def test_continue_from_yesterday(self): # create a completed time yesterday yesterday = (datetime.datetime.utcnow() - datetime.timedelta(days=1)).isoformat() toggl.CLI()._add_time_entry([desc('continue'), yesterday, 'd1:0:0']) # find it entry = self.find_time_entry(desc('continue')) self.assertIsNotNone(entry) # continue it entry.continue_entry() # find the new one entry2 = self.find_time_entry(desc('continue')) self.assertNotEqual(entry.get('duration'), entry2.get('duration'))
self.assertIsNotNone(current) self.assertEquals(current.get('description'), desc('now')) current.stop() def tearDownModule(): """ Cleans up toggl with all the unittest entries we just created. This relies on TimeEntryList and TimeEntry.delete. """ print("Removing toggl entries created by the test...") for entry in toggl.TimeEntryList(): if entry.get('description') is not None and entry.get( 'description').startswith('unittest_'): entry.delete() if __name__ == '__main__': toggl.CLI() # this initializes Logger to INFO #toggl.Logger.level = toggl.Logger.DEBUG toggl.Logger.level = toggl.Logger.NONE try: unittest.main() except SystemExit: pass except Exception as e: if six.PY3: traceback.print_tb(e.__traceback__) else: traceback.print_tb(sys.exc_info()[2])