Beispiel #1
0
def test_get_projects(projects_model):
    project1 = create_project()
    projects_model.put_project(project1)

    project2 = create_project(project_id="ZZZZZ", name="Other project")
    projects_model.put_project(project2)

    projects = projects_model.get_projects(0, 2)
    assert projects == [project1, project2]
def test_get_object_types_by_project(objects_tracker_model, put_project):
    object_id1 = EntityId(OBJECT_ID1)
    object_id2 = EntityId(OBJECT_ID2)
    put_project(create_project(object_id1.project_id))
    put_project(create_project(object_id2.project_id))

    objects_tracker_model.track_object(object_id1, EntityType.deliverable)
    objects_tracker_model.track_object(object_id2, EntityType.issue)

    assert objects_tracker_model.get_objects_types_by_project(object_id1) == {
        object_id1: EntityType.deliverable,
    }
Beispiel #3
0
def test_get_issues_filter_project(issues_model, put_project):
    put_project(create_project())
    put_project(create_project("AAA"))

    issue1 = create_bound_issue()
    issues_model.put_issue(issue1)

    issue2 = create_bound_issue(object_id="AAA", name="Other issue")
    issues_model.put_issue(issue2)

    issues = issues_model.get_issues(EntityId(issue1.object_id.project_id),
                                     related_entity_id=None,
                                     offset=0,
                                     limit=2)
    assert issues == [issue1]
Beispiel #4
0
def test_create_issue(issues_model, put_project):
    put_project(create_project())

    issue = create_bound_issue()
    issues_model.put_issue(issue)
    saved_issue = issues_model.get_issue(issue.object_id)
    assert issue == saved_issue
Beispiel #5
0
def test_update_issue(issues_model, put_project):
    put_project(create_project())

    issue = create_bound_issue()
    issues_model.put_issue(issue)

    updated_issue = create_bound_issue(
        name="Test",
        status=IssueStatus.done,
        type=IssueType.task,
        priority=IssuePriority.major,
        description="DESC",
        date_opened=datetime(year=2020, month=1, day=1, hour=10, minute=30),
        date_closed=datetime(year=2020, month=1, day=2, hour=10, minute=30),
        deadline=datetime(year=2020, month=1, day=3, hour=10, minute=30),
        files=[create_file("file_A"),
               create_file("file_B")],
        links=[create_link("link_A"),
               create_link("link_B")],
        tasks=[create_task("task_A"),
               create_task("task_B")],
        tags=[create_tag("tag_A"), create_tag("tag_B")],
    )
    issues_model.put_issue(updated_issue)

    saved_issue = issues_model.get_issue(issue.object_id)
    assert updated_issue == saved_issue
def test_deliverable_estimated_cost(statistics_api, put_project, post_issue,
                                    put_link, post_deliverable):
    project = create_project()
    put_project(project)
    bound_deliverable = post_deliverable(project.project_id,
                                         create_deliverable())

    # Issue with default project currency
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(5)))
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    # Issue with overriden currency
    bound_issue = post_issue(
        project.project_id,
        create_issue(estimated_duration=Decimal(2),
                     hour_rate=Money(amount=Decimal(1000),
                                     currency=Currency.czk)))
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    # Issue without estimated duration
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=None))
    put_link(bound_deliverable.object_id, bound_issue.object_id)

    statistics = statistics_api.get_deliverable_statistics(
        bound_deliverable.object_id)
    assert statistics.estimated_cost == Money(amount=Decimal("5002.5"),
                                              currency=Currency.czk)
def test_deliverable_burned_cost(statistics_api, put_project, post_issue,
                                 post_timesheet, post_deliverable, put_link):
    project = create_project()
    put_project(project)
    bound_deliverable = post_deliverable(project.project_id,
                                         create_deliverable())

    # Issue with default project currency
    bound_issue = post_issue(project.project_id, create_issue())
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(2)))
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(1)))
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(1)))
    # Issue with overriden currency
    bound_issue = post_issue(
        project.project_id,
        create_issue(hour_rate=Money(Decimal(1000), currency=Currency.czk)))
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(10)))
    # Issue without timesheet
    bound_issue = post_issue(project.project_id, create_issue())
    put_link(bound_deliverable.object_id, bound_issue.object_id)

    statistics = statistics_api.get_deliverable_statistics(
        bound_deliverable.object_id)
    assert statistics.burned_cost == Money(Decimal(12402), Currency.czk)
def test_project_burned_duration(statistics_api, put_project, post_issue,
                                 post_timesheet):
    project = create_project()
    put_project(project)
    # Issue with several timesheets
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(5)))
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(2)))
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(1)))
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(1)))
    # Issue with overtime
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(2)))
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(10)))
    # Estimated issue without timesheet
    post_issue(project.project_id, create_issue(estimated_duration=Decimal(3)))
    # Unestimated issue with timesheet
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=None))
    post_timesheet(bound_issue.object_id,
                   create_timesheet(duration=Decimal(10)))
    # Issue estimated to zero
    post_issue(project.project_id, create_issue(estimated_duration=Decimal(0)))

    statistics = statistics_api.get_project_statistics(project.project_id)
    assert statistics.burned_duration == Decimal(24)
def test_deliverable_estimated_duration(statistics_api, put_project,
                                        post_issue, put_link,
                                        post_deliverable):
    project = create_project()
    put_project(project)
    bound_deliverable = post_deliverable(project.project_id,
                                         create_deliverable())
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(5)))
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(2)))
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(3)))
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=None))
    put_link(bound_deliverable.object_id, bound_issue.object_id)
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(0)))
    put_link(bound_deliverable.object_id, bound_issue.object_id)

    statistics = statistics_api.get_deliverable_statistics(
        bound_deliverable.object_id)
    assert statistics.estimated_duration == Decimal(10)
Beispiel #10
0
def test_issue_expenditures_cost(
    statistics_api,
    put_project,
    post_issue,
    post_expenditure,
):
    project = create_project()
    put_project(project)

    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(5)))
    post_expenditure(
        bound_issue.object_id,
        create_expenditure(cost=Money(Decimal(10), currency=Currency.czk)))
    post_expenditure(bound_issue.object_id,
                     create_expenditure(status=ExpenditureStatus.submitted))
    post_expenditure(bound_issue.object_id,
                     create_expenditure(status=ExpenditureStatus.refund))
    post_expenditure(
        bound_issue.object_id,
        create_expenditure(cost=Money(Decimal(100), currency=Currency.czk)))

    statistics = statistics_api.get_entity_statistics(bound_issue.object_id)
    assert statistics.burned_expenditures_cost == Money(
        Decimal(110), Currency.czk)
def test_get_deliverables_filter_related_object(
    authorized_api_request,
    post_deliverable,
    post_issue,
    put_project,
    put_link,
):
    project = create_project()
    put_project(project)
    post_deliverable(project.project_id, MINIMAL_DELIVERABLE)
    full_bound_deliverable = post_deliverable(project.project_id,
                                              FULL_DELIVERABLE)
    issue = post_issue(project.project_id, create_issue())
    put_link(issue.object_id, full_bound_deliverable.object_id)

    response = authorized_api_request(
        "GET",
        get_project_deliverables_url(project.project_id) +
        "?related_object_id={id}".format(id=issue.object_id.full_id))

    assert response.status_code == 200
    assert response.json["deliverables"][0]["id"] == str(
        full_bound_deliverable.object_id)
    del response.json["deliverables"][0]["id"]
    assert response.json == {"deliverables": [FULL_SERIALIZED_DELIVERABLE]}
Beispiel #12
0
def test_project_expenditures_cost_no_entities(statistics_api, put_project):
    project = create_project()
    put_project(project)

    statistics = statistics_api.get_project_statistics(project.project_id)
    assert statistics.burned_expenditures_cost == Money(
        Decimal(0), Currency.czk)
Beispiel #13
0
def test_project_burned_duration_no_timesheets(statistics_api, put_project,
                                               post_issue):
    project = create_project()
    put_project(project)
    post_issue(project.project_id, create_issue(estimated_duration=Decimal(5)))

    statistics = statistics_api.get_project_statistics(project.project_id)
    assert statistics.burned_duration == Decimal(0)
Beispiel #14
0
def test_delete_issue_files(issues_model, put_project, files_model):
    put_project(create_project())

    issue = create_bound_issue()
    issues_model.put_issue(issue)

    issues_model.delete_issue(issue.object_id)
    assert not files_model.get_entity_files(issue.object_id)
def test_get_object_type(objects_tracker_model, put_project):
    object_id1 = EntityId(OBJECT_ID1)
    put_project(create_project(object_id1.project_id))

    objects_tracker_model.track_object(object_id1, EntityType.deliverable)

    assert objects_tracker_model.get_object_type(
        object_id1) == EntityType.deliverable
def test_untrack_object(objects_tracker_model, put_project):
    object_id = EntityId(OBJECT_ID1)
    put_project(create_project(object_id.project_id))

    objects_tracker_model.track_object(object_id, EntityType.deliverable)
    objects_tracker_model.untrack_object(object_id)

    assert objects_tracker_model.get_objects_types([object_id]) == {}
Beispiel #17
0
def test_create_deliverable(deliverables_model, put_project):
    put_project(create_project())

    deliverable = create_bound_deliverable()
    deliverables_model.put_deliverable(deliverable)
    saved_deliverable = deliverables_model.get_deliverable(
        deliverable.object_id)
    assert deliverable == saved_deliverable
Beispiel #18
0
def test_delete_project(authorized_api_request, put_project, get_project):
    project = create_project()
    put_project(project)

    authorized_api_request("DELETE", get_project_url(project.project_id))

    with pytest.raises(ProjectDoesNotExist):
        get_project(project.project_id)
Beispiel #19
0
def test_create_link(authorized_api_request, post_issue, put_project):
    project = create_project()
    put_project(project)
    issue1 = post_issue(project.project_id, create_issue())
    issue2 = post_issue(project.project_id, create_issue())

    response = authorized_api_request(
        "PUT", get_link_url(issue1.object_id, issue2.object_id))
    assert response.status_code == 201
Beispiel #20
0
def test_get_deliverables_filter_project(deliverables_model, put_project):
    put_project(create_project())
    put_project(create_project("AAA"))

    deliverable1 = create_bound_deliverable()
    deliverables_model.put_deliverable(deliverable1)

    deliverable2 = create_bound_deliverable(object_id="AAA",
                                            name="Other deliverable")
    deliverables_model.put_deliverable(deliverable2)

    deliverables = deliverables_model.get_deliverables(
        EntityId(deliverable1.object_id.project_id),
        related_entity_id=None,
        offset=0,
        limit=2,
    )
    assert deliverables == [deliverable1]
Beispiel #21
0
def test_delete_issue_with_timesheets(post_timesheet, authorized_api_request,
                                      post_issue, put_project, get_timesheets):
    project = create_project()
    put_project(project)
    bound_issue = post_issue(project.project_id, create_issue())
    post_timesheet(bound_issue.object_id, create_timesheet())
    request = authorized_api_request("DELETE",
                                     get_issue_url(str(bound_issue.object_id)))
    assert request.status_code == 200
    assert not get_timesheets(bound_issue.object_id)
Beispiel #22
0
def test_project_with_children_cant_be_deleted(authorized_api_request,
                                               post_deliverable, put_project):
    project = create_project()
    put_project(project)
    post_deliverable(project.project_id, create_deliverable())

    response = authorized_api_request("DELETE",
                                      get_project_url(project.project_id))
    assert response.status_code == 400
    assert response.json["code"] == "project_has_child_elements"
Beispiel #23
0
def test_deliverable_progress_no_entities(statistics_api, put_project,
                                          post_deliverable):
    project = create_project()
    put_project(project)
    bound_deliverable = post_deliverable(project.project_id,
                                         create_deliverable())

    statistics = statistics_api.get_deliverable_statistics(
        bound_deliverable.object_id)
    assert statistics.progress is None
Beispiel #24
0
def test_delete_issue(authorized_api_request, post_issue, get_issue,
                      put_project):
    project = create_project()
    put_project(project)
    issue = create_issue()
    bound_issue = post_issue(project.project_id, issue)

    authorized_api_request("DELETE", get_issue_url(str(bound_issue.object_id)))

    with pytest.raises(IssueDoesNotExist):
        get_issue(bound_issue.object_id)
Beispiel #25
0
def test_create_expenditure_for_invalid_entity(authorized_api_request,
                                               post_deliverable, put_project):
    project = create_project()
    put_project(project)
    bound_deliverable = post_deliverable(project.project_id,
                                         create_deliverable())
    response = authorized_api_request(
        "POST", get_expenditure_url(bound_deliverable.object_id),
        {"expenditure": MINIMAL_SERIALIZED_EXPENDITURE})
    assert response.status_code == 400
    assert response.json["code"] == "invalid_parent_type"
def test_project_recreate_resets_object_ids(projects_api, deliverables_api):
    project = create_project()
    projects_api.put_project(project)
    deliverable = deliverables_api.create_deliverable(project.project_id, create_deliverable())

    deliverables_api.delete_deliverable(deliverable.object_id)
    projects_api.delete_project(project.project_id)

    projects_api.put_project(project)
    deliverable = deliverables_api.create_deliverable(project.project_id, create_deliverable())
    assert deliverable.object_id == EntityId.from_parts(project.project_id, 1)
Beispiel #27
0
def test_create_timesheet_for_invalid_entity(authorized_api_request, post_deliverable, put_project):
    project = create_project()
    put_project(project)
    bound_deliverable = post_deliverable(project.project_id, create_deliverable())
    response = authorized_api_request(
        "POST",
        get_timesheet_url(bound_deliverable.object_id),
        {"timesheet": SERIALIZED_TIMESHEET}
    )
    assert response.status_code == 400
    assert response.json["code"] == "invalid_parent_type"
Beispiel #28
0
def test_issue_progress_issue_no_timesheets(statistics_api, put_project,
                                            post_issue):
    project = create_project()
    put_project(project)

    # Issue without timesheets
    bound_issue = post_issue(project.project_id,
                             create_issue(estimated_duration=Decimal(5)))

    statistics = statistics_api.get_entity_statistics(bound_issue.object_id)
    assert statistics.progress == Decimal(0)
Beispiel #29
0
def test_delete_issue(issues_model, put_project):
    put_project(create_project())

    issue = create_bound_issue()
    issues_model.put_issue(issue)

    issues_model.delete_issue(issue.object_id)
    assert not issues_model.get_issues(EntityId(issue.object_id.project_id),
                                       related_entity_id=None,
                                       offset=0,
                                       limit=1)
Beispiel #30
0
def test_project_estimated_duration(statistics_api, put_project, post_issue):
    project = create_project()
    put_project(project)
    post_issue(project.project_id, create_issue(estimated_duration=Decimal(5)))
    post_issue(project.project_id, create_issue(estimated_duration=Decimal(2)))
    post_issue(project.project_id, create_issue(estimated_duration=Decimal(3)))
    post_issue(project.project_id, create_issue(estimated_duration=None))
    post_issue(project.project_id, create_issue(estimated_duration=Decimal(0)))

    statistics = statistics_api.get_project_statistics(project.project_id)
    assert statistics.estimated_duration == Decimal(10)