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 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 #3
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 #4
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 #5
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 #6
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 #7
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))