Example #1
0
 def test_save_without_intended_task(self):
     wp1 = WorkingPeriod(
         employee=self.employee,
         intended="test if employee has working period",
         #intended_task=self.task, # no task
         start=datetime.now())
     wp1.save()
Example #2
0
    def test_total_time(self):
        wp1 = WorkingPeriod(employee=self.employee,
                            intended="test if employee has working period",
                            intended_task=self.task,
                            executed="made the employe have it",
                            executed_task=self.task,
                            start=datetime(2011, 1, 23, 1, 8),
                            end=datetime(2011, 1, 23, 9, 38))
        self.assertEqual(wp1.total_time, 8.5)
        self.assertEqual(wp1.timedelta,
                         timedelta(0, (9 - 1) * 60 * 60 + (38 - 8) * 60))
        self.assertEqual(wp1.hours_minutes, (8, 30))
        self.assertEqual(wp1.hours, 8)
        self.assertEqual(wp1.minutes, 30)

        wp2 = WorkingPeriod(
            intended_task=self.task,
            employee=self.employee,
            intended="test if employee has working period again",
            start=datetime(2011, 1, 23, 1, 8))
        self.assertEqual(wp2.total_time, None)
        self.assertEqual(wp2.timedelta, None)
        self.assertEqual(wp2.hours_minutes, None)
        self.assertEqual(wp2.hours, None)
        self.assertEqual(wp2.minutes, None)
Example #3
0
def post_to_add(request):
    employee = request.user.get_profile()
    activity = request.POST['activity']
    task_id = request.POST['task']
    if not activity.strip():
        messages.error(request, _("What did you do?"))
        return HttpResponseRedirect(reverse(add))
    try:
        task_id = int(task_id)
        task = Task.objects.get(id=task_id) if task_id > 0 else None
    except ValueError:
        messages.error(request, _("What task did you help?"))
        return HttpResponseRedirect(reverse(add))

    start_date = request.POST['start-date']
    end_date = request.POST['end-date']
    start_time = request.POST['start-time']
    end_time = request.POST['end-time']

    if not start_date.strip() or not start_time.strip():
        messages.error(request, _("When did you start this period?"))
        return HttpResponseRedirect(reverse(add))

    if not end_date.strip() or not end_time.strip():
        messages.error(request, _("When did you end this period?"))
        return HttpResponseRedirect(reverse(add))

    try:
        start = datetime.strptime(
            start_date + " " + start_time,
            NETUNONG_DATE_FORMAT + " " + NETUNONG_TIME_FORMAT)
    except ValueError:
        messages.error(request, _("Your start date or time is invalid."))
        return HttpResponseRedirect(reverse(add))

    try:
        end = datetime.strptime(
            end_date + " " + end_time,
            NETUNONG_DATE_FORMAT + " " + NETUNONG_TIME_FORMAT)
    except ValueError:
        messages.error(request, _("Your end date or time is invalid."))
        return HttpResponseRedirect(reverse(add))
    working_period = WorkingPeriod(executed_task=task,
                                   employee=employee,
                                   executed=activity,
                                   start=start,
                                   end=end)
    working_period.save()
    messages.success(request, _("Period registered."))
    # TODO use reverse
    return HttpResponseRedirect('/netunong/manage')
Example #4
0
 def test_last_activity_last_task(self):
     wp1 = WorkingPeriod(employee=self.employee,
                         intended="test if employee has working period",
                         intended_task=self.task,
                         executed="made the employe have it",
                         executed_task=self.task,
                         start=datetime.now(),
                         end=datetime.now())
     self.assertEqual(wp1.last_activity, wp1.executed)
     self.assertEqual(wp1.last_task, wp1.executed_task)
     wp2 = WorkingPeriod(
         intended_task=self.task,
         employee=self.employee,
         intended="test if employee has working period again",
         start=datetime.now())
     self.assertEqual(wp2.last_activity, wp2.intended)
     self.assertEqual(wp2.last_task, wp2.intended_task)
Example #5
0
 def test_is_exported(self):
     org, _, task = get_organization_project_task()
     emp = get_employee(org)
     start = datetime(2011, 12, 31, 8, 0)
     end = datetime(2011, 12, 31, 12, 0)
     wp = WorkingPeriod(
         employee=emp,
         intended="Write a function for creating better descriptions",
         intended_task=task,
         executed="Created function to describe exported WP",
         executed_task=task,
         start=start,
         end=end)
     wp.save()
     self.assertFalse(ExportedLog.is_exported(wp))
     el = ExportedLog(working_period=wp)
     el.save()
     self.assertTrue(ExportedLog.is_exported(wp))
Example #6
0
    def test_export(self): 
        emp, task, start, end = self.get_depencencies()

        wp = WorkingPeriod(employee=emp,
            intended="Write a function for creating better descriptions",
            intended_task=task,
            executed="Created function to describe exported WP",
            executed_task=task,
            start= start, end=end)
        wp.save()

        exporter = agents.Exporter()
        exporter.export_logs([wp], ROOT_URL, 'adam', 'senha')
        
        content = self.get_list_of_submitted_logs()
        self.assertTrue(('Task id: 2376') in content)
        self.assertTrue('Log creator: 1' in content)
        self.assertTrue(('Date: %s' % start.strftime("%Y%m%d")) in content)
        self.assertTrue('Worked hours: %s' % wp.total_time in content)
        self.assertTrue('Description: %s' % get_exported_description(wp) in content)
Example #7
0
def open_period(request):
    """
    Opens a new working period.
    """
    employee = request.user.get_profile()
    intention = request.POST['intention']
    if not intention.strip():
        messages.error(request, _("What do you intend to do?"))
        return HttpResponseRedirect(reverse(get_index))
    task_id = request.POST['task']
    try:
        task_id = int(task_id)
        task = Task.objects.get(id=task_id) if task_id > 0 else None
    except ValueError:
        task = None
    start = datetime.now()
    working_period = WorkingPeriod(intended_task=task,
                                   employee=employee,
                                   intended=intention,
                                   start=start)
    working_period.save()
    return HttpResponseRedirect(reverse(get_index))
Example #8
0
 def test_last_activity_without_end(self):
     task1 = self.task
     task2 = Task(name="Another task",
                  project=self.project,
                  description="Just another task")
     wp1 = WorkingPeriod(employee=self.employee,
                         intended="test if employee has working period",
                         intended_task=task1,
                         executed="made the employe have it",
                         executed_task=task2,
                         start=datetime.now(),
                         end=datetime.now())
     self.assertEqual(wp1.last_activity, wp1.executed)
     self.assertEqual(wp1.last_task, wp1.executed_task)
     wp2 = WorkingPeriod(
         intended_task=task2,
         employee=self.employee,
         intended="test if employee has working period again",
         executed="i tested it",
         executed_task=task1,
         start=datetime.now())
     self.assertEqual(wp2.last_activity, wp2.executed)
     self.assertEqual(wp2.last_task, wp2.executed_task)
Example #9
0
    def test_formatted_time_values(self):
        wp1 = WorkingPeriod(employee=self.employee,
                            intended="test if employee has working period",
                            intended_task=self.task,
                            executed="made the employe have it",
                            executed_task=self.task,
                            start=datetime(2011, 1, 23, 1, 8),
                            end=datetime(2011, 1, 23, 9, 38))
        self.assertEqual(wp1.formatted_start_date,
                         wp1.start.strftime(NETUNONG_DATE_FORMAT))
        self.assertEqual(wp1.formatted_start_time,
                         wp1.start.strftime(NETUNONG_TIME_FORMAT))
        self.assertEqual(wp1.formatted_end_date,
                         wp1.end.strftime(NETUNONG_DATE_FORMAT))
        self.assertEqual(wp1.formatted_end_time,
                         wp1.end.strftime(NETUNONG_TIME_FORMAT))

        wp2 = WorkingPeriod(
            intended_task=self.task,
            employee=self.employee,
            intended="test if employee has working period again",
            start=datetime(2011, 1, 23, 1, 8))
        self.assertEqual(wp2.formatted_end_date, '')
        self.assertEqual(wp2.formatted_end_time, '')
Example #10
0
    def test_get_something(self):
        org, _, task = get_organization_project_task()
        emp = get_employee(org)
        start = datetime(2011, 12, 31, 8, 0)
        end = datetime(2011, 12, 31, 12, 0)
        wp = WorkingPeriod(
            employee=emp,
            intended="Write a function for creating better descriptions",
            intended_task=task,
            executed="Created function to describe exported WP",
            executed_task=task,
            start=start,
            end=end)

        self.assertEqual(
            "%s - %s: Created function to describe exported WP" % (
                start.strftime(settings.NETUNONG_TIME_FORMAT),
                end.strftime(settings.NETUNONG_TIME_FORMAT),
            ), parser.get_exported_description(wp))
Example #11
0
 def test_is_closed(self):
     wp1 = WorkingPeriod(employee=self.employee,
                         intended="test if employee has working period",
                         intended_task=self.task,
                         executed="made the employe have it",
                         executed_task=self.task,
                         start=datetime.now(),
                         end=datetime.now())
     self.assertTrue(wp1.is_closed())
     wp2 = WorkingPeriod(
         intended_task=self.task,
         employee=self.employee,
         intended="test if employee has working period again",
         start=datetime.now())
     self.assertFalse(wp2.is_closed())
Example #12
0
    def test_export_two_wps(self): 
        emp, task, start, end = self.get_depencencies()

        wp1 = WorkingPeriod(employee=emp,
            intended="Write a function for creating better descriptions",
            intended_task=task,
            executed="Created function to describe exported WP",
            executed_task=task,
            start= start, end=end)
        wp1.save()

        delta = timedelta(1)
        tomorrow_start=start+delta
        tomorrow_end=end+delta
        wp2 = WorkingPeriod(employee=emp,
            intended="Export stuff",
            intended_task=task,
            executed="Exporting WPs to old netuno",
            executed_task=task,
            start=tomorrow_start, end=tomorrow_end)
        wp2.save()



        exporter = agents.Exporter()
        exporter.export_logs([wp1, wp2], ROOT_URL, 'adam', 'senha')
        
        content = self.get_list_of_submitted_logs()
        self.assertTrue(('Task id: 2376') in content)
        self.assertTrue('Log creator: 1' in content)
        self.assertTrue(('Date: %s' % start.strftime("%Y%m%d")) in content)
        self.assertTrue('Worked hours: %s' % wp1.total_time in content)
        self.assertTrue('Description: %s' % get_exported_description(wp1) in content)     
        self.assertTrue(('Task id: 2376') in content)
        self.assertTrue('Log creator: 1' in content)
        self.assertTrue(('Date: %s' % tomorrow_start.strftime("%Y%m%d")) in content)
        self.assertTrue('Worked hours: %s' % wp2.total_time in content)
        self.assertTrue('Description: %s' % get_exported_description(wp2) in content)    
Example #13
0
 def test_is_complete_requires_executed_task(self):
     wp1 = WorkingPeriod(employee=self.employee,
                         intended="test if employee has working period",
                         intended_task=self.task,
                         executed="made the employe have it",
                         executed_task=self.task,
                         start=datetime.now(),
                         end=datetime.now())
     self.assertTrue(wp1.is_complete())
     wp2 = WorkingPeriod(
         employee=self.employee,
         intended="test if employee has working period",
         intended_task=self.task,
         executed="made the employe have it",
         #executed_task=self.task,
         start=datetime.now(),
         end=datetime.now())
     self.assertFalse(wp2.is_complete())
Example #14
0
    def test_does_not_export_incomplete(self): 
        emp, task, start, end = self.get_depencencies()

        wp1 = WorkingPeriod(employee=emp,
            intended="Write a function for creating better descriptions",
            intended_task=task,
            executed="Created function to describe exported WP",
            executed_task=task,
            start= start, end=end)
        wp1.save()

        wp2 = WorkingPeriod(employee=emp,
            intended="Export stuff",
            intended_task=task,
            executed="Exporting WPs to old netuno",
            executed_task=task,
            start=start) # No end
        wp2.save()

        wp3 = WorkingPeriod(employee=emp,
            intended="Thinking about future",
            intended_task=task,
            #executed="Exporting WPs to old netuno", # No final message
            executed_task=task,
            start=start, end=end)
        wp3.save()

        wp4 = WorkingPeriod(employee=emp,
            intended="PLanning how to spend money",
            intended_task=task,
            executed="Exporting WPs to old netuno",
            # executed_task=task, # No updated task
            start=start, end=end)
        wp4.save()

        wp5 = WorkingPeriod(employee=emp,
            intended="Write a function for creating better descriptions",
            intended_task=task,
            executed="Closing WP",
            executed_task=task,
            start= start, end=end)
        wp5.save()

        exporter = agents.Exporter()
        exporter.export_logs([wp1, wp2, wp3, wp4, wp5], ROOT_URL, 'adam', 'senha')
        
        content = self.get_list_of_submitted_logs()
        self.assertTrue(('Task id: 2376') in content)
        self.assertTrue('Log creator: 1' in content)
        self.assertTrue(('Date: %s' % start.strftime("%Y%m%d")) in content)
        self.assertTrue('Worked hours: %s' % wp1.total_time in content)

        self.assertTrue('Description: %s' % get_exported_description(wp1) in content)     
        self.assertFalse('Description: %s' % get_exported_description(wp2) in content)     
        self.assertFalse('Description: %s' % get_exported_description(wp3) in content)     
        self.assertFalse('Description: %s' % get_exported_description(wp4) in content)     
        self.assertTrue('Description: %s' % get_exported_description(wp5) in content)     

        self.assertTrue(ExportedLog.is_exported(wp1))
        self.assertFalse(ExportedLog.is_exported(wp2))
        self.assertFalse(ExportedLog.is_exported(wp3))
        self.assertFalse(ExportedLog.is_exported(wp4))
        self.assertTrue(ExportedLog.is_exported(wp5))