def test_notify_reviewers_with_cc_and_message(db, mailoutbox, cc, message):
    """Test time range 2017-7-1 till 2017-7-31."""
    # a reviewer which will be notified
    reviewer_work = UserFactory.create()
    project_work = ProjectFactory.create()
    project_work.reviewers.add(reviewer_work)
    task_work = TaskFactory.create(project=project_work)
    ReportFactory.create(date=date(2017, 7, 1),
                         task=task_work,
                         verified_by=None)

    # a reviewer which doesn't have any unverfied reports
    reviewer_no_work = UserFactory.create()
    project_no_work = ProjectFactory.create()
    project_no_work.reviewers.add(reviewer_no_work)
    task_no_work = TaskFactory.create(project=project_no_work)
    ReportFactory.create(date=date(2017, 7, 1),
                         task=task_no_work,
                         verified_by=reviewer_no_work)

    call_command(
        "notify_reviewers_unverified",
        "--cc={0}".format(cc),
        "--message={0}".format(message),
    )

    # checks
    assert len(mailoutbox) == 1
    mail = mailoutbox[0]
    assert mail.to == [reviewer_work.email]
    url = ("http://localhost:4200/analysis?fromDate=2017-07-01&"
           "toDate=2017-07-31&reviewer=%d&editable=1") % reviewer_work.id
    assert url in mail.body
    assert message in mail.body
    assert mail.cc[0] == cc
def test_notify_reviewers(db, mailoutbox):
    """Test time range 2017-7-1 till 2017-7-31."""
    # a reviewer which will be notified
    reviewer_work = UserFactory.create()
    project_work = ProjectFactory.create()
    project_work.reviewers.add(reviewer_work)
    task_work = TaskFactory.create(project=project_work)
    ReportFactory.create(date=date(2017, 7, 1), task=task_work,
                         verified_by=None)

    # a reviewer which doesn't have any unverfied reports
    reviewer_no_work = UserFactory.create()
    project_no_work = ProjectFactory.create()
    project_no_work.reviewers.add(reviewer_no_work)
    task_no_work = TaskFactory.create(project=project_no_work)
    ReportFactory.create(date=date(2017, 7, 1), task=task_no_work,
                         verified_by=reviewer_no_work)

    call_command('notify_reviewers_unverified')

    # checks
    assert len(mailoutbox) == 1
    mail = mailoutbox[0]
    assert mail.to == [reviewer_work.email]
    url = (
        'http://localhost:4200/reschedule?from_date=2017-07-01&'
        'to_date=2017-07-31&reviewer=%d'
    ) % reviewer_work.id
    assert url in mail.body
Ejemplo n.º 3
0
def test_project_list_not_archived(auth_client):
    project = ProjectFactory.create(archived=False)
    ProjectFactory.create(archived=True)

    url = reverse("project-list")

    response = auth_client.get(url, data={"archived": 0})
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert len(json["data"]) == 1
    assert json["data"][0]["id"] == str(project.id)
Ejemplo n.º 4
0
def test_project_list_not_archived(auth_client):
    project = ProjectFactory.create(archived=False)
    ProjectFactory.create(archived=True)

    url = reverse('project-list')

    response = auth_client.get(url, data={'archived': 0})
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert len(json['data']) == 1
    assert json['data'][0]['id'] == str(project.id)
def test_subscription_project_list(auth_client):
    customer = CustomerFactory.create()
    billing_type = BillingTypeFactory()
    project = ProjectFactory.create(billing_type=billing_type,
                                    customer=customer,
                                    customer_visible=True)
    PackageFactory.create_batch(2, billing_type=billing_type)
    # create spent hours
    task = TaskFactory.create(project=project)
    TaskFactory.create(project=project)
    ReportFactory.create(task=task, duration=timedelta(hours=2))
    ReportFactory.create(task=task, duration=timedelta(hours=3))
    # not billable reports should not be included in spent hours
    ReportFactory.create(not_billable=True,
                         task=task,
                         duration=timedelta(hours=4))
    # project of same customer but without customer_visible set
    # should not appear
    ProjectFactory.create(customer=customer)

    # create purchased time
    OrderFactory.create(project=project,
                        acknowledged=True,
                        duration=timedelta(hours=2))
    OrderFactory.create(project=project,
                        acknowledged=True,
                        duration=timedelta(hours=4))

    # report on different project should not be included in spent time
    ReportFactory.create(duration=timedelta(hours=2))
    # not acknowledged order should not be included in purchased time
    OrderFactory.create(project=project, duration=timedelta(hours=2))

    url = reverse('subscription-project-list')

    res = auth_client.get(url,
                          data={
                              'customer': customer.id,
                              'ordering': 'id'
                          })
    assert res.status_code == HTTP_200_OK

    json = res.json()
    assert len(json['data']) == 1
    assert json['data'][0]['id'] == str(project.id)

    attrs = json['data'][0]['attributes']
    assert attrs['spent-time'] == '05:00:00'
    assert attrs['purchased-time'] == '06:00:00'
Ejemplo n.º 6
0
def test_subscription_package_filter_customer(auth_client):
    other_project = ProjectFactory.create()
    PackageFactory.create(billing_type=other_project.billing_type)

    my_project = ProjectFactory.create()
    package = PackageFactory.create(billing_type=my_project.billing_type)

    url = reverse('subscription-package-list')

    res = auth_client.get(url, data={'customer': my_project.customer.id})
    assert res.status_code == HTTP_200_OK

    json = res.json()
    assert len(json['data']) == 1
    assert json['data'][0]['id'] == str(package.id)
Ejemplo n.º 7
0
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'
Ejemplo n.º 8
0
    def test_project_default_tasks(self):
        """Should generate tasks based on task templates for a new project."""
        templates = TaskTemplateFactory.create_batch(5)
        project = ProjectFactory.create()
        tasks = Task.objects.filter(project=project)

        assert len(templates) == len(tasks)
Ejemplo n.º 9
0
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"
Ejemplo n.º 10
0
def test_project_detail_no_auth(client):
    project = ProjectFactory.create()

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

    res = client.get(url)
    assert res.status_code == status.HTTP_401_UNAUTHORIZED
Ejemplo n.º 11
0
def test_project_update(auth_client):
    project = ProjectFactory.create()

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

    response = auth_client.patch(url)
    assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
Ejemplo n.º 12
0
def test_user_is_reviewer_filter(auth_client, value, expected):
    """Should filter users if they are a reviewer."""
    user = UserFactory.create()
    project = ProjectFactory.create()
    UserFactory.create_batch(3)

    project.reviewers.add(user)

    res = auth_client.get(reverse('user-list'), {'is_reviewer': value})
    assert len(res.json()['data']) == expected
def test_subscription_project_detail(auth_client):
    billing_type = BillingTypeFactory()
    project = ProjectFactory.create(billing_type=billing_type)
    PackageFactory.create_batch(2, billing_type=billing_type)

    url = reverse('subscription-project-detail', args=[project.id])
    res = auth_client.get(url)
    assert res.status_code == HTTP_200_OK
    json = res.json()
    assert json['data']['id'] == str(project.id)
def test_subscription_project_detail(auth_client):
    billing_type = BillingTypeFactory()
    project = ProjectFactory.create(billing_type=billing_type,
                                    customer_visible=True)
    PackageFactory.create_batch(2, billing_type=billing_type)

    url = reverse("subscription-project-detail", args=[project.id])
    res = auth_client.get(url)
    assert res.status_code == HTTP_200_OK
    json = res.json()
    assert json["data"]["id"] == str(project.id)
Ejemplo n.º 15
0
def test_project_detail_no_reports(auth_client):
    project = ProjectFactory.create()

    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"] == "00:00:00"
Ejemplo n.º 16
0
def test_project_detail_no_reports(auth_client):
    project = ProjectFactory.create()

    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'] == '00:00:00'
Ejemplo n.º 17
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"
Ejemplo n.º 18
0
def test_report_list_filter_cost_center(auth_client):
    cost_center = CostCenterFactory.create()
    # 1st valid case: report with task of given cost center
    # but different project cost center
    task = TaskFactory.create(cost_center=cost_center)
    report_task = ReportFactory.create(task=task)
    # 2nd valid case: report with project of given cost center
    project = ProjectFactory.create(cost_center=cost_center)
    task = TaskFactory.create(cost_center=None, project=project)
    report_project = ReportFactory.create(task=task)
    # Invalid case: report without cost center
    project = ProjectFactory.create(cost_center=None)
    task = TaskFactory.create(cost_center=None, project=project)
    ReportFactory.create(task=task)

    url = reverse("report-list")

    res = auth_client.get(url, data={"cost_center": cost_center.id})
    assert res.status_code == status.HTTP_200_OK
    json = res.json()
    assert len(json["data"]) == 2
    ids = {int(entry["id"]) for entry in json["data"]}
    assert {report_task.id, report_project.id} == ids
Ejemplo n.º 19
0
def test_redmine_report_no_estimated_time(db, freezer, mocker):
    redmine_instance = mocker.MagicMock()
    issue = mocker.MagicMock()
    redmine_instance.issue.get.return_value = issue
    redmine_class = mocker.patch("redminelib.Redmine")
    redmine_class.return_value = redmine_instance

    freezer.move_to("2017-07-28")
    project = ProjectFactory.create(estimated_time=None)
    task = TaskFactory.create(project=project)
    report = ReportFactory.create(comment="ADSY <=> Other", task=task)
    RedmineProject.objects.create(project=report.task.project, issue_id=1000)

    freezer.move_to("2017-07-31")
    call_command("redmine_report", last_days=7)

    redmine_instance.issue.get.assert_called_once_with(1000)
    issue.save.assert_called_once_with()
Ejemplo n.º 20
0
def test_redmine_report_no_estimated_time(db, freezer, mocker):
    redmine_instance = mocker.MagicMock()
    issue = mocker.MagicMock()
    redmine_instance.issue.get.return_value = issue
    redmine_class = mocker.patch('redminelib.Redmine')
    redmine_class.return_value = redmine_instance

    freezer.move_to('2017-07-28')
    project = ProjectFactory.create(estimated_time=None)
    task = TaskFactory.create(project=project)
    report = ReportFactory.create(comment='ADSY <=> Other', task=task)
    RedmineProject.objects.create(project=report.task.project, issue_id=1000)

    freezer.move_to('2017-07-31')
    call_command('redmine_report', options={'--last-days': '7'})

    redmine_instance.issue.get.assert_called_once_with(1000)
    issue.save.assert_called_once_with()
Ejemplo n.º 21
0
def test_project_list_include(auth_client, django_assert_num_queries):
    project = ProjectFactory.create()
    users = UserFactory.create_batch(2)
    project.reviewers.add(*users)

    url = reverse('project-list')

    with django_assert_num_queries(6):
        response = auth_client.get(
            url,
            data={
                'include':
                ','.join(ProjectSerializer.included_serializers.keys())
            })
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert len(json['data']) == 1
    assert json['data'][0]['id'] == str(project.id)
def test_notify_reviewers(db, mailoutbox):
    """Test time range 2017-7-1 till 2017-7-31."""
    # a reviewer which will be notified
    reviewer_work = UserFactory.create()
    project_work = ProjectFactory.create()
    project_work.reviewers.add(reviewer_work)
    task_work = TaskFactory.create(project=project_work)
    ReportFactory.create(date=date(2017, 7, 1),
                         task=task_work,
                         verified_by=None)

    call_command("notify_reviewers_unverified")

    # checks
    assert len(mailoutbox) == 1
    mail = mailoutbox[0]
    assert mail.to == [reviewer_work.email]
    url = ("http://localhost:4200/analysis?fromDate=2017-07-01&"
           "toDate=2017-07-31&reviewer=%d&editable=1") % reviewer_work.id
    assert url in mail.body