Esempio n. 1
0
 def test_entries(self):
     # need to get a timesheet for the current user.
     ts = Timesheet(self.base_uri, self.username, self.password)
     # create some entries.
     projects = ts.projects()
     self.assertTrue(len(projects) > 0)
     entries = []
     for i in xrange(random.randint(0, 5)):
         project = random.choice(projects)
         task = random.choice(project.tasks())
         entry = ts.create_entry(project.id, task.id, hours = random.random() * 10)
         entry.stop()
         entries += [entry]
     # Get the entries from the admin interface.
     person = None
     for p in self.hv.people():
         if p.id == ts.id:
             person = p
     self.assertIsNotNone(person)
     report_entries = person.entries(
         start = datetime.datetime.today(),
         end = datetime.datetime.today(),
     )
     # ensure the data is there.
     for rentry in report_entries:
         self.assertIsNotNone(rentry.hours)
         self.assertIsNotNone(rentry.id)
         self.assertTrue(hasattr(rentry, 'notes'))
         self.assertIsNotNone(rentry.project_id)
         self.assertIsNotNone(rentry.task_id)
         self.assertIsNotNone(rentry.user_id)
         self.assertIsNotNone(rentry.billed)
         self.assertIsNotNone(rentry.closed)
         self.assertIsNotNone(rentry.updated)
         self.assertIsNotNone(rentry.created)
         self.assertIsNotNone(rentry.spent)
     # ensure the data matches up.
     self.assertEqual(len(report_entries), len(entries))
     matches = 0
     for rentry in report_entries:
         for oentry in entries:
             if oentry.id == rentry.id:
                 matches += 1
                 self.assertEqual(oentry.hours, rentry.hours)
                 self.assertEqual(oentry.project_id, rentry.project_id)
                 self.assertEqual(oentry.task_id, rentry.task_id)
                 break
     # Clean up
     for entry in entries:
         entry.delete()
Esempio n. 2
0
 def test_entries(self):
     # create test entries.
     ts = Timesheet(self.base_uri, self.username, self.password)
     project = ts.projects()[0]
     tasks = project.tasks()
     self.assertIsNotNone(project)
     entries = []
     for i in xrange(random.randint(1, 5)):
         task = random.choice(tasks)
         entry = ts.create_entry(project.id, task.id, hours = random.random() * 10)
         entry.stop()
         entries += [entry]
     # get the entries from the project.
     for p in self.hv.projects():
         if p.id == project.id:
             admin_proj = p
     self.assertIsNotNone(admin_proj)
     proj_entries = admin_proj.entries(
         start = admin_proj.earliest_record,
         end = admin_proj.latest_record
     )
     # make sure the data exists.
     for proj_entry in proj_entries:
         self.assertIsNotNone(proj_entry.hours)
         self.assertIsNotNone(proj_entry.id)
         self.assertTrue(hasattr(proj_entry, 'notes'))
         self.assertIsNotNone(proj_entry.project_id)
         self.assertIsNotNone(proj_entry.task_id)
         self.assertIsNotNone(proj_entry.user_id)
         self.assertIsNotNone(proj_entry.billed)
         self.assertIsNotNone(proj_entry.closed)
         self.assertIsNotNone(proj_entry.updated)
         self.assertIsNotNone(proj_entry.created)
         self.assertIsNotNone(proj_entry.spent)
     # ensure that all entries created were found.
     for orig_entry in entries:
         found = False
         for proj_entry in proj_entries:
             if proj_entry.id == orig_entry.id:
                 found = True
                 break
         if not found:
             self.fail()
     # clean up
     for orig_entry in entries:
         orig_entry.delete()