Пример #1
0
    def test_get_overdue_emails_without_overdue_tasks(self):
        """Test for getting overdue emails without overdue tasks.

        """
        postfix = ' 1'
        username = '******'
        email = '*****@*****.**'
        password = '******'
        usr = User.objects.create_user(
            username=username,
            password=password,
            email=email,
        )

        deadline = timezone.now() + datetime.timedelta(days=32)
        start_date = timezone.now()
        complete_date = timezone.now() + datetime.timedelta(days=8)

        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)

        employee = create_employee(
            **{
                'firstname': firstname,
                'middlename': middlename,
                'surname': surname,
                'email': email,
                'user': usr,
                'birthdate': birthdate,
            })
        project = create_project(
            **{
                'project_name': 'Project name' + postfix,
                'description': 'Project description' + postfix,
                'budget': 100000,
                'deadline': deadline,
                'closed': True,
            })
        create_task(
            **{
                'project': project,
                'task_name': 'Task name' + postfix,
                'description': 'description',
                'start_date': start_date,
                'complete_date': complete_date,
                'author': employee,
                'assignee': employee,
                'status': NEW,
            })

        overdue_emails = get_overdue_emails()
        self.assertQuerysetEqual(overdue_emails, [])
Пример #2
0
    def test_create_overdue_notification_tasks_several_users(self):
        """Test for creating overdue notification tasks. Several users has
        overdue tasks.

        """
        postfix = ' 1'
        username = '******'
        email = '*****@*****.**'
        password = '******'
        usr1 = User.objects.create_user(
            username=username,
            password=password,
            email=email,
        )

        username = '******'
        email = '*****@*****.**'
        password = '******'
        usr2 = User.objects.create_user(
            username=username,
            password=password,
            email=email,
        )

        deadline = timezone.now() + datetime.timedelta(days=32)
        start_date = timezone.now()
        complete_date = timezone.now() + datetime.timedelta(days=8)

        firstname = 'Marshall ' + postfix
        middlename = 'Bruce ' + postfix
        surname = 'Mathers ' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)

        employee1 = create_employee(
            **{
                'firstname': firstname,
                'middlename': middlename,
                'surname': surname,
                'email': email,
                'user': usr1,
                'birthdate': birthdate,
            })

        postfix = '2'
        firstname = 'Marshall ' + postfix
        middlename = 'Bruce ' + postfix
        surname = 'Mathers ' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)

        employee2 = create_employee(
            **{
                'firstname': firstname,
                'middlename': middlename,
                'surname': surname,
                'email': email,
                'user': usr2,
                'birthdate': birthdate,
            })

        postfix = ' 1'
        project = create_project(
            **{
                'project_name': 'Project name' + postfix,
                'description': 'Project description' + postfix,
                'budget': 100000,
                'deadline': deadline,
                'closed': True,
            })
        create_task(
            **{
                'project': project,
                'task_name': 'Task name' + postfix,
                'description': 'description',
                'start_date': start_date,
                'complete_date': complete_date,
                'author': employee1,
                'assignee': employee1,
                'status': NEW,
            })
        postfix = '2'
        start_date = timezone.now() - datetime.timedelta(days=9)
        complete_date = timezone.now() - datetime.timedelta(days=8)
        create_task(
            **{
                'project': project,
                'task_name': 'Task name' + postfix,
                'description': 'description',
                'start_date': start_date,
                'complete_date': complete_date,
                'author': employee1,
                'assignee': employee1,
                'status': IN_PROGRESS,
            })
        postfix = '3'
        start_date = timezone.now() - datetime.timedelta(days=8)
        complete_date = timezone.now() - datetime.timedelta(minutes=64)
        create_task(
            **{
                'project': project,
                'task_name': 'Task name' + postfix,
                'description': 'description',
                'start_date': start_date,
                'complete_date': complete_date,
                'author': employee2,
                'assignee': employee2,
                'status': NEW,
            })
        postfix = '4'
        start_date = timezone.now() - datetime.timedelta(days=8)
        complete_date = timezone.now() - datetime.timedelta(minutes=64)
        create_task(
            **{
                'project': project,
                'task_name': 'Task name' + postfix,
                'description': 'description',
                'start_date': start_date,
                'complete_date': complete_date,
                'author': employee2,
                'assignee': employee2,
                'status': IN_PROGRESS,
            })

        with mock.patch(
                'worker.email.tasks.send_overdue_notification_email.delay'
        ) as m:
            create_overdue_notification_tasks()
        m.assert_has_calls([
            call('*****@*****.**',
                 'Task "Task name2" overdue for 8 days and 0 hours.\n'),
            call('*****@*****.**',
                 'Task "Task name4" overdue for 0 days and 1 hours.\n'),
        ], True)
Пример #3
0
    def test_employee_statistics(self):
        """Test employees statistics of home page view.

        """
        username = '******'
        email = '*****@*****.**'
        password = '******'
        usr = User.objects.create_user(username=username, password=password, email=email, )
        usr.groups.add(Group.objects.get(name='public'))

        self.client.login(username=username, password=password)

        deadline = timezone.now() + datetime.timedelta(days=32)
        postfix = ' 1'
        project_1 = create_project(**{
            'project_name': 'Project name' + postfix,
            'description': 'Project description' + postfix,
            'budget': 100000,
            'deadline': deadline,
            'closed': False,
        })

        postfix = '_1'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_1 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_2'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_2 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_3'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_3 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_4'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_4 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_5'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_5 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_6'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_6 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_7'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_7 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_8'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_8 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_9'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_9 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })
        postfix = '_10'
        firstname = 'Marshall' + postfix
        middlename = 'Bruce' + postfix
        surname = 'Mathers' + postfix
        email = f'mbm{postfix}@example.com'
        birthdate = timezone.now() + datetime.timedelta(days=-365 * 30)
        employee_10 = create_employee(**{
            'firstname': firstname,
            'middlename': middlename,
            'surname': surname,
            'email': email,
            'birthdate': birthdate,
        })

        postfix = ' 1'
        start_date = timezone.now()
        complete_date = timezone.now() + datetime.timedelta(days=8)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_2,
            'status': NEW,
        })
        postfix = ' 2'
        start_date = timezone.now() + datetime.timedelta(days=4)
        complete_date = timezone.now() + datetime.timedelta(days=8)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_2,
            'status': NEW,
        })
        postfix = ' 3'
        start_date = timezone.now() + datetime.timedelta(days=-4)
        complete_date = timezone.now() + datetime.timedelta(days=8)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_3,
            'status': NEW,
        })
        postfix = ' 4'
        start_date = timezone.now() + datetime.timedelta(days=-14)
        complete_date = timezone.now() + datetime.timedelta(days=-6)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_4,
            'status': NEW,
        })
        postfix = ' 5'
        start_date = timezone.now() + datetime.timedelta(days=-4)
        complete_date = timezone.now() + datetime.timedelta(days=10)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_4,
            'status': IN_PROGRESS,
        })
        postfix = ' 6'
        start_date = timezone.now() + datetime.timedelta(days=-8)
        complete_date = timezone.now() + datetime.timedelta(days=-4)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_2,
            'status': IN_PROGRESS,
        })
        postfix = ' 7'
        start_date = timezone.now() + datetime.timedelta(days=8)
        complete_date = timezone.now() + datetime.timedelta(days=14)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_5,
            'status': IN_PROGRESS,
        })
        postfix = ' 8'
        start_date = timezone.now() + datetime.timedelta(days=8)
        complete_date = timezone.now() + datetime.timedelta(days=14)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_6,
            'status': COMPLETED,
        })
        postfix = ' 9'
        start_date = timezone.now() + datetime.timedelta(days=-8)
        complete_date = timezone.now() + datetime.timedelta(days=14)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_7,
            'status': COMPLETED,
        })
        postfix = ' 10'
        start_date = timezone.now() + datetime.timedelta(days=-14)
        complete_date = timezone.now() + datetime.timedelta(days=-6)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_8,
            'status': COMPLETED,
        })
        postfix = ' 11'
        start_date = timezone.now() + datetime.timedelta(days=-24)
        complete_date = timezone.now() + datetime.timedelta(days=-1)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_9,
            'status': IN_PROGRESS,
        })
        postfix = ' 11'
        start_date = timezone.now() + datetime.timedelta(days=-21)
        complete_date = timezone.now() + datetime.timedelta(days=-2)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_4,
            'status': IN_PROGRESS,
        })
        postfix = ' 12'
        start_date = timezone.now() + datetime.timedelta(days=4)
        complete_date = timezone.now() + datetime.timedelta(days=6)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_3,
            'status': IN_PROGRESS,
        })
        postfix = ' 13'
        start_date = timezone.now() + datetime.timedelta(days=-3)
        complete_date = timezone.now() + datetime.timedelta(days=8)
        create_task(**{
            'project': project_1,
            'task_name': 'Task name' + postfix,
            'description': 'description',
            'start_date': start_date,
            'complete_date': complete_date,
            'author': employee_1,
            'assignee': employee_7,
            'status': IN_PROGRESS,
        })
        response = self.client.get(reverse('home:home'))
        self.assertEqual(response.status_code, 200)
        self.assertQuerysetEqual(
            response.context['employees_statistics'].values(),
            [10, 4, 3, 6],
            transform=lambda x: x
        )