Ejemplo n.º 1
0
    def test_random_data_tasksperdmtp(self):
        """
        Does a lot of random test and checks the data generate matches the tasksperdmtp JSON
        """

        c = Client()
        c.login(username="******", password="******")

        departments = Department.objects.filter(company_id__company_name="company1")
        project = Project.objects.get(name="pro_random")

        n_dep = len(departments)
        # Do the random test 5 times
        for _ in range(5):
            Task.objects.all().delete()

            tasks_per_dpmt = [random.choice(range(11)) for _ in range(n_dep)]
            true_data = {'names': [], 'values': []}

            for i in range(n_dep):
                dpmt = departments[i]
                task_count = tasks_per_dpmt[i]

                true_data['names'].append(dpmt.name)
                true_data['values'].append(task_count)

                for _ in range(task_count):
                    create_task_in_projdept(project, dpmt)

            # Check that the data returned by the AJAX query matches the generated data

            response = c.get("/project/ajaxTasksPerDpmt?project_id={0}" .format(project.id))
            self.assertEquals(response.status_code, 200)
            check_json_metrics_are_equal(self, str(response.content, encoding='utf8'), true_data)
Ejemplo n.º 2
0
    def test_random_data_timepertask(self):
        """
        Does a lot of test and checks the data matches the timepertask JSON
        """
        c = Client()
        c.login(username="******", password="******")

        department = Department.objects.get(name="Dep_rand")
        projects = Project.objects.filter(company_id__company_name="company1")

        # Make the test run 5 times
        for _ in range(5):

            TimeLog.objects.all().delete()
            Task.objects.all().delete()

            true_data = {'names': [], 'values': []}

            for project in projects:

                # Create between 1 and 5 tasks for the current project and the department
                for _ in range(random.randint(1, 5)):
                    create_task_in_projdept(project, department)

                for task in Task.objects.filter(
                        projectDepartment_id__department_id=department,
                        projectDepartment_id__project_id=project):
                    # Create between 2 and 10 employees, that will assign time to that task
                    num_employees = random.randint(2, 10)
                    used_time = 0

                    for _ in range(num_employees):
                        employee = create_employee_in_projdept(
                            project, department)

                        # Make them create time logs (between 1 and 3)
                        for _ in range(random.randint(1, 3)):
                            # 25% chance of being outside of the requested time margin
                            count = random.choice([True, True, True, False])
                            date_worked = "2016-06-01 10:00+01:00" if count else "2014-01-01 10:00+00:00"
                            time_worked = random.randint(1, 1000)

                            create_timelog_in_task(task, time_worked,
                                                   date_worked, employee)

                            if count:
                                used_time += time_worked

                    true_data['names'].append(task.name)
                    true_data['values'].append(used_time)

        response = c.get(
            "/department/ajaxTimePerTask?department_id={0}&start_date=2016-01-01&end_date=2016-12-31"
            .format(Department.objects.get(name="Dep_rand").id))
        self.assertEquals(response.status_code, 200)
        check_json_metrics_are_equal(self,
                                     str(response.content, encoding='utf8'),
                                     true_data)
Ejemplo n.º 3
0
    def test_random_data_timeperdpmt(self):
        """
        Does a lot of test and checks the data matches the timeperdpmt JSON
        """
        c = Client()
        c.login(username="******", password="******")

        departments = Department.objects.filter(company_id__company_name="company1")
        project = Project.objects.get(name="pro_random")

        n_dep = len(departments)
        # Do the random test 5 times

        for _ in range(5):

            # Remove all tasks and time logs
            TimeLog.objects.all().delete()
            Task.objects.all().delete()

            true_data = {'names': [], 'values': []}

            for i in range(n_dep):
                dpmt = departments[i]

                # Create between 1 and 4 tasks for each department
                for _ in range(random.randint(1, 4)):
                    create_task_in_projdept(project, dpmt)

                # Initialize the true data for this department
                used_time = 0

                # Create between 1 and 20 timelogs for each department
                for _ in range(random.randint(1, 20)):
                    duration = random.randint(1, 100)
                    task = random.choice(Task.objects.filter(projectDepartment_id__project_id=project,
                                                             projectDepartment_id__department_id=dpmt))
                    measure = random.choice([True, True, True, False])  # Make timelogs have a 25% chance of not being counted towards the metric
                    date = "2016-06-01 10:00+00:00" if measure else "2014-05-01 21:00+00:00"

                    create_timelog_in_task(task, duration, date)

                    if measure:
                        used_time += duration

                true_data['names'].append(dpmt.name)
                true_data['values'].append(used_time)

            # Check that the data returned by the AJAX query matches the generated data

            response = c.get("/project/ajaxTimePerDpmt?project_id={0}&start_date=2016-01-01&end_date=2017-01-01" .format(project.id))
            self.assertEquals(response.status_code, 200)
            check_json_metrics_are_equal(self, str(response.content, encoding='utf8'), true_data)
Ejemplo n.º 4
0
    def test_random_data_emppertask(self):
        """
        Does a lot of random test and checks the data generate matches the emppertask JSON
        """
        c = Client()
        c.login(username="******", password="******")

        department = Department.objects.get(name="Dep_rand")
        projects = Project.objects.filter(company_id__company_name="company1")

        # Make the test run 1 time (this one's slow af)
        for _ in range(1):

            TimeLog.objects.all().delete()
            Task.objects.all().delete()

            true_data = {'names': [], 'values': []}

            for project in projects:

                # Create between 1 and 5 tasks for the current project and the department
                for _ in range(random.randint(1, 5)):
                    create_task_in_projdept(project, department)

                for task in Task.objects.filter(
                        projectDepartment_id__department_id=department,
                        projectDepartment_id__project_id=project):
                    # Create between 2 and 20 employees, that will assign time to that task
                    num_employees = random.randint(2, 20)
                    true_data['names'].append(task.name)
                    true_data['values'].append(num_employees)

                    for _ in range(num_employees):
                        employee = create_employee_in_projdept(
                            project, department)

                        # Make them create time logs
                        for _ in range(random.randint(1, 3)):
                            create_timelog_in_task(task, 100,
                                                   "2016-01-01 10:00+00:00",
                                                   employee)

        response = c.get(
            "/department/ajaxEmployeesPerTask?department_id={0}".format(
                Department.objects.get(name="Dep_rand").id))
        self.assertEquals(response.status_code, 200)
        check_json_metrics_are_equal(self,
                                     str(response.content, encoding='utf8'),
                                     true_data)
Ejemplo n.º 5
0
    def test_random_data_timeperproject(self):
        """
        Does a lot of random test,thus ensuring the dashboard provides the correct data every time
        """

        admin = Administrator.objects.get(user__username="******")
        emp = Employee.objects.get(user__username="******")
        c = Client()
        c.login(username="******", password="******")

        departments = Department.objects.filter(
            company_id__company_name="metronus")
        projects = Project.objects.filter(company_id__company_name="metronus")

        n_dep = len(departments)
        n_pro = len(projects)
        # Do the random test 5 times

        for _ in range(5):

            # Remove all tasks and time logs
            TimeLog.objects.all().delete()
            Task.objects.all().delete()

            true_data = {}

            for i in range(n_pro):
                project = projects[i]

                # Initialize the true data for this department
                true_data[str(project.id)] = {'name': project.name, 'time': 0}

                for j in range(n_dep):
                    dpmt = departments[j]

                    # Create between 1 and 4 tasks for each department
                    for _ in range(random.randint(1, 4)):
                        create_task_in_projdept(project, dpmt, admin)

                    # Create between 1 and 10 timelogs for each department
                    for _ in range(random.randint(1, 10)):
                        duration = random.randint(1, 100)
                        task = random.choice(
                            Task.objects.filter(
                                projectDepartment_id__project_id=project,
                                projectDepartment_id__department_id=dpmt))
                        measure = random.choice(
                            [True, True, True, False]
                        )  # Make the timelogs have a 25% chance of not being counted towards the metric
                        date = "2016-06-01 10:00+00:00" if measure else "2014-05-01 21:00+00:00"

                        create_timelog_in_task(task, duration, date, emp)

                        if measure:
                            true_data[str(project.id)]["time"] += duration

                # Check that the data returned by the AJAX query matches the generated data

            response = c.get(
                "/dashboard/ajaxTimePerProject?start_date=2016-01-01&end_date=2017-01-01"
            )
            self.assertEquals(response.status_code, 200)
            self.assertJSONEqual(str(response.content, encoding='utf8'),
                                 true_data)