def test_work_report_single_project(auth_client, django_assert_num_queries):
    user = auth_client.user
    # spaces should be replaced with underscore
    customer = CustomerFactory.create(name='Customer Name')
    # slashes should be dropped from file name
    project = ProjectFactory.create(customer=customer, name='Project/')
    task = TaskFactory.create(project=project)
    ReportFactory.create_batch(
        10, user=user, verified_by=user, task=task, date=date(2017, 8, 17)
    )

    url = reverse('work-report-list')
    with django_assert_num_queries(4):
        res = auth_client.get(url, data={
            'user': auth_client.user.id,
            'from_date': '2017-08-01',
            'to_date': '2017-08-31',
            'verified': 1
        })
    assert res.status_code == HTTP_200_OK
    assert '1708-20170901-Customer_Name-Project.ods' in (
        res['Content-Disposition']
    )

    content = io.BytesIO(res.content)
    doc = ezodf.opendoc(content)
    table = doc.sheets[0]
    assert table['C5'].value == '2017-08-01'
    assert table['C6'].value == '2017-08-31'
    assert table['C9'].value == 'Test User'
    assert table['C10'].value == 'Test User'
def test_work_report_multiple_projects(auth_client, django_assert_num_queries):
    NUM_PROJECTS = 2

    user = auth_client.user
    customer = CustomerFactory.create(name="Customer")
    report_date = date(2017, 8, 17)
    for i in range(NUM_PROJECTS):
        project = ProjectFactory.create(customer=customer, name="Project{0}".format(i))
        task = TaskFactory.create(project=project)
        ReportFactory.create_batch(10, user=user, task=task, date=report_date)

    url = reverse("work-report-list")
    with django_assert_num_queries(3):
        res = auth_client.get(url, data={"user": auth_client.user.id, "verified": 0})
    assert res.status_code == status.HTTP_200_OK
    assert "20170901-WorkReports.zip" in (res["Content-Disposition"])

    content = io.BytesIO(res.content)
    with ZipFile(content, "r") as zipfile:
        for i in range(NUM_PROJECTS):
            ods_content = zipfile.read(
                "1708-20170901-Customer-Project{0}.ods".format(i)
            )
            doc = ezodf.opendoc(io.BytesIO(ods_content))
            table = doc.sheets[0]
            assert table["C5"].value == "2017-08-17"
            assert table["C6"].value == "2017-08-17"
Exemple #3
0
def test_task_my_most_frequent(auth_client):
    user = auth_client.user
    tasks = TaskFactory.create_batch(6)

    report_date = date.today() - timedelta(days=20)
    old_report_date = date.today() - timedelta(days=90)

    # tasks[0] should appear as most frequently used task
    ReportFactory.create_batch(5, date=report_date, user=user, task=tasks[0])
    # tasks[1] should appear as secondly most frequently used task
    ReportFactory.create_batch(4, date=report_date, user=user, task=tasks[1])
    # tasks[2] should not appear in result, as too far in the past
    ReportFactory.create_batch(4,
                               date=old_report_date,
                               user=user,
                               task=tasks[2])
    # tasks[3] should not appear in result, as project is archived
    tasks[3].project.archived = True
    tasks[3].project.save()
    ReportFactory.create_batch(4, date=report_date, user=user, task=tasks[3])
    # tasks[4] should not appear in result, as task is archived
    tasks[4].archived = True
    tasks[4].save()
    ReportFactory.create_batch(4, date=report_date, user=user, task=tasks[4])

    url = reverse('task-list')

    response = auth_client.get(url, {'my_most_frequent': '10'})
    assert response.status_code == status.HTTP_200_OK

    data = response.json()['data']
    assert len(data) == 2
    assert data[0]['id'] == str(tasks[0].id)
    assert data[1]['id'] == str(tasks[1].id)
def test_work_report_multiple_projects(auth_client, django_assert_num_queries):
    NUM_PROJECTS = 2

    user = auth_client.user
    customer = CustomerFactory.create(name='Customer')
    report_date = date(2017, 8, 17)
    for i in range(NUM_PROJECTS):
        project = ProjectFactory.create(
            customer=customer, name='Project{0}'.format(i)
        )
        task = TaskFactory.create(project=project)
        ReportFactory.create_batch(10, user=user, task=task, date=report_date)

    url = reverse('work-report-list')
    with django_assert_num_queries(4):
        res = auth_client.get(url, data={
            'user': auth_client.user.id,
            'verified': 0
        })
    assert res.status_code == HTTP_200_OK
    assert '20170901-WorkReports.zip' in (
        res['Content-Disposition']
    )

    content = io.BytesIO(res.content)
    with ZipFile(content, 'r') as zipfile:
        for i in range(NUM_PROJECTS):
            ods_content = zipfile.read(
                '1708-20170901-Customer-Project{0}.ods'.format(i)
            )
            doc = ezodf.opendoc(io.BytesIO(ods_content))
            table = doc.sheets[0]
            assert table['C5'].value == '2017-08-17'
            assert table['C6'].value == '2017-08-17'
def test_work_report_single_project(auth_client, django_assert_num_queries):
    user = auth_client.user
    # spaces should be replaced with underscore
    customer = CustomerFactory.create(name="Customer Name")
    # slashes should be dropped from file name
    project = ProjectFactory.create(customer=customer, name="Project/")
    task = TaskFactory.create(project=project)
    ReportFactory.create_batch(10,
                               user=user,
                               verified_by=user,
                               task=task,
                               date=date(2017, 8, 17))

    url = reverse("work-report-list")
    with django_assert_num_queries(3):
        res = auth_client.get(
            url,
            data={
                "user": auth_client.user.id,
                "from_date": "2017-08-01",
                "to_date": "2017-08-31",
                "verified": 1,
            },
        )
    assert res.status_code == status.HTTP_200_OK
    assert "1708-20170901-Customer_Name-Project.ods" in (
        res["Content-Disposition"])

    content = io.BytesIO(res.content)
    doc = ezodf.opendoc(content)
    table = doc.sheets[0]
    assert table["C5"].value == "2017-08-01"
    assert table["C6"].value == "2017-08-31"
    assert table["C9"].value == "Test User"
    assert table["C10"].value == "Test User"
Exemple #6
0
    def setUp(self):
        """Set the environment for the tests up."""
        super().setUp()

        other_user = get_user_model().objects.create_user(username='******',
                                                          password='******')

        self.reports = ReportFactory.create_batch(10, user=self.user)
        self.other_reports = ReportFactory.create_batch(10, user=other_user)
Exemple #7
0
def test_task_detail_with_reports(auth_client):
    task = TaskFactory.create()
    ReportFactory.create_batch(5, task=task, duration=timedelta(minutes=30))

    url = reverse('task-detail', args=[task.id])

    res = auth_client.get(url)

    assert res.status_code == status.HTTP_200_OK

    json = res.json()
    assert json['meta']['spent-time'] == '02:30:00'
Exemple #8
0
def test_project_detail_with_reports(auth_client):
    project = ProjectFactory.create()
    task = TaskFactory.create(project=project)
    ReportFactory.create_batch(10, task=task, duration=timedelta(hours=1))

    url = reverse("project-detail", args=[project.id])

    res = auth_client.get(url)

    assert res.status_code == status.HTTP_200_OK
    json = res.json()

    assert json["meta"]["spent-time"] == "10:00:00"
def test_work_report_count(
    auth_client, settings, settings_count, given_count, expected_status
):
    user = auth_client.user
    customer = CustomerFactory.create(name="Customer")
    report_date = date(2017, 8, 17)

    settings.WORK_REPORTS_EXPORT_MAX_COUNT = settings_count

    project = ProjectFactory.create(customer=customer)
    task = TaskFactory.create(project=project)
    ReportFactory.create_batch(given_count, user=user, task=task, date=report_date)

    url = reverse("work-report-list")
    res = auth_client.get(url, data={"user": auth_client.user.id, "verified": 0})

    assert res.status_code == expected_status
Exemple #10
0
    def test_task_my_most_frequent(self):
        """Should respond with a list of my most frequent tasks."""
        report_date = date.today() - timedelta(days=20)
        old_report_date = date.today() - timedelta(days=90)

        # tasks[0] should appear as most frequently used task
        ReportFactory.create_batch(5,
                                   date=report_date,
                                   user=self.user,
                                   task=self.tasks[0])
        # tasks[1] should appear as secondly most frequently used task
        ReportFactory.create_batch(4,
                                   date=report_date,
                                   user=self.user,
                                   task=self.tasks[1])
        # tasks[2] should not appear in result, as too far in the past
        ReportFactory.create_batch(4,
                                   date=old_report_date,
                                   user=self.user,
                                   task=self.tasks[2])

        url = reverse('task-list')

        res = self.client.get(url, {'my_most_frequent': '10'})
        assert res.status_code == HTTP_200_OK

        result = self.result(res)
        data = result['data']
        assert len(data) == 2
        assert data[0]['id'] == str(self.tasks[0].id)
        assert data[1]['id'] == str(self.tasks[1].id)
Exemple #11
0
def test_report_export(auth_client, file_type, django_assert_num_queries):
    reports = ReportFactory.create_batch(2)

    url = reverse('report-export')

    with django_assert_num_queries(2):
        response = auth_client.get(url, data={'file_type': file_type})

    assert response.status_code == status.HTTP_200_OK
    book = pyexcel.get_book(file_content=response.content, file_type=file_type)
    # bookdict is a dict of tuples(name, content)
    sheet = book.bookdict.popitem()[1]
    assert len(sheet) == len(reports) + 1