def test_patch_milestone(app, centralized_milestone):
    """
    milestone owner can patch it
    """
    milestone_data, plan_data = centralized_milestone["milestone"], centralized_milestone["plan"]
    milestone, milestone_token = milestone_data["data"], milestone_data["token"]
    plan, plan_token = plan_data["data"], plan_data["token"]
    app.authorization = ("Basic", ("broker", "broker"))

    request_data = {
        "id": "a" * 32,
        "description": "What?",
        "dueDate": "2001-10-30T11:15:26.641038+03:00",
        "documents": [
            {
                "title": "text.txt",
                "url": generate_docservice_url(app),
                "hash": "md5:" + "0" * 32,
                "format": "text/plain",
            }
        ],
        "status": Milestone.STATUS_MET,
        "author": {
            "identifier": {
                "scheme": "UA-EDR",
                "id": "222222",
                "legalName": "ЦЗО 2"
            },
            "name": "ЦЗО 2"
        },
        "dateModified": "2001-10-30T11:15:26.641038+03:00",
        "dateMet": "1917-10-30T11:15:26.641038+03:00",
        "owner": "wtf",
        "owner_token": "b" * 4,
    }
    response = app.patch_json(
        "/plans/{}/milestones/{}?acc_token={}".format(plan["id"], milestone["id"], milestone_token),
        {"data": request_data}
    )
    assert response.status_code == 200

    result_plan = app.app.registry.databases.plans.get(plan["id"])
    result = result_plan.get("milestones")[0]
    # fields that haven"t been changed
    assert result["id"] == milestone["id"]
    assert result["documents"] == milestone["documents"]
    assert result["author"] == milestone["author"]
    assert result["owner"] == milestone["owner"]
    assert result["owner_token"] == milestone_token
    assert result_plan["dateModified"] == result["dateModified"]

    # changed
    assert result["dueDate"] == request_data["dueDate"]
    assert result["status"] == request_data["status"]
    assert result["description"] == request_data["description"]
    assert result["dateModified"] > milestone["dateModified"]
    assert result["dateModified"] == result["dateMet"] == response.json["data"]["dateMet"]
def test_milestone_data(app):
    test_milestone = {
        "title": MILESTONE_APPROVAL_TITLE,
        "type": Milestone.TYPE_APPROVAL,
        "author": milestone_author,
        "dueDate": datetime.now().isoformat(),
        "documents": [
            {
                "title": "name.doc",
                "url": generate_docservice_url(app),
                "hash": "md5:" + "0" * 32,
                "format": "application/msword",
            }
        ]
    }
    return test_milestone
def test_update_milestone_documents(app, centralized_milestone):
    """
    as a milestone owner I can manage it's documents
    """
    milestone_data, plan_data = centralized_milestone["milestone"], centralized_milestone["plan"]
    milestone, milestone_token = milestone_data["data"], milestone_data["token"]
    plan, plan_token = plan_data["data"], plan_data["token"]
    app.authorization = ("Basic", ("broker", "broker"))
    plan_date_modified = plan["dateModified"]
    milestone_date_modified = milestone["dateModified"]

    request_data = {
        "title": "sign.p7s",
        "url": generate_docservice_url(app),
        "hash": "md5:" + "0" * 32,
        "format": "application/pk7s",
    }
    response = app.post_json(
        "/plans/{}/milestones/{}/documents?acc_token={}".format(plan["id"], milestone["id"], milestone_token),
        {"data": request_data},
    )
    assert response.status_code == 201

    result_plan = app.app.registry.databases.plans.get(plan["id"])
    result_milestone = result_plan.get("milestones")[0]
    assert len(result_milestone["documents"]) == 2
    new_doc = result_milestone["documents"][1]
    assert new_doc["title"] == request_data["title"]
    assert new_doc["hash"] == request_data["hash"]
    assert new_doc["format"] == request_data["format"]
    assert new_doc["url"].split("Signature")[0] == request_data["url"].split("Signature")[0]
    assert result_plan["dateModified"] > plan_date_modified
    plan_date_modified = result_plan["dateModified"]
    assert result_plan["milestones"][0]["dateModified"] > milestone_date_modified
    milestone_date_modified = result_plan["milestones"][0]["dateModified"]

    # put
    request_data = {
        "title": "sign-2.p7s",
        "url": generate_docservice_url(app),
        "hash": "md5:" + "0" * 32,
        "format": "application/signature",
    }
    response = app.put_json(
        "/plans/{}/milestones/{}/documents/{}?acc_token={}".format(
            plan["id"], milestone["id"], new_doc["id"], milestone_token),
        {"data": request_data},
    )
    assert response.status_code == 200

    result_plan = app.app.registry.databases.plans.get(plan["id"])
    result_milestone = result_plan.get("milestones")[0]
    assert len(result_milestone["documents"]) == 3
    old_doc = new_doc
    new_doc = result_milestone["documents"][2]
    assert new_doc["id"] == old_doc["id"]
    assert new_doc["title"] == request_data["title"]
    assert new_doc["hash"] == request_data["hash"]
    assert new_doc["format"] == request_data["format"]
    assert new_doc["url"].split("Signature")[0] == request_data["url"].split("Signature")[0]
    assert result_plan["dateModified"] > plan_date_modified
    plan_date_modified = result_plan["dateModified"]
    assert result_plan["milestones"][0]["dateModified"] > milestone_date_modified
    milestone_date_modified = result_plan["milestones"][0]["dateModified"]

    # patch
    request_data = {
        "title": "sign-3.p7s",
        "url": generate_docservice_url(app),
        "hash": "md5:" + "0" * 32,
        "format": "ms/sms",
        "documentOf": "my ma",
        "documentType": "notice",
        "language": "c++",
    }
    response = app.patch_json(
        "/plans/{}/milestones/{}/documents/{}?acc_token={}".format(
            plan["id"], milestone["id"], new_doc["id"], milestone_token),
        {"data": request_data},
    )
    assert response.status_code == 200

    result_plan = app.app.registry.databases.plans.get(plan["id"])
    result_milestone = result_plan.get("milestones")[0]
    assert len(result_milestone["documents"]) == 3
    patched_doc = result_milestone["documents"][2]
    assert patched_doc["id"] == new_doc["id"]
    assert patched_doc["hash"] == new_doc["hash"]
    assert patched_doc["url"].split("Signature")[0] == new_doc["url"].split("Signature")[0]
    assert patched_doc["format"] == request_data["format"]
    assert patched_doc["title"] == request_data["title"]
    assert patched_doc["documentOf"] == request_data["documentOf"]
    assert patched_doc["documentType"] == request_data["documentType"]
    assert patched_doc["language"] == request_data["language"]
    assert result_plan["dateModified"] > plan_date_modified
    assert result_plan["milestones"][0]["dateModified"] > milestone_date_modified
예제 #4
0
def test_fail_update_complete_or_cancelled_plan(app, status):
    app.authorization = ("Basic", ("broker", "broker"))
    test_data = deepcopy(test_plan_data)
    test_data["documents"] = [{
        "title": u"укр.doc",
        "url": generate_docservice_url(app),
        "hash": "md5:" + "0" * 32,
        "format": "application/msword",
    }]
    test_data["status"] = status
    if status == "cancelled":
        test_data["cancellation"] = dict(reason="Because", status="active")

    response = app.post_json("/plans", {"data": test_data})
    assert response.status == "201 Created"
    assert response.json["data"].get("status") == status
    plan_id = response.json["data"]["id"]
    doc_id = response.json["data"]["documents"][0]["id"]
    acc_token = response.json["access"]["token"]

    # patch
    response = app.patch_json("/plans/{}?acc_token={}".format(
        plan_id, acc_token), {"data": {}},
                              status=422)
    assert response.json == {
        u"status":
        u"error",
        u"errors": [{
            u"description":
            u"Can't update plan in '{}' status".format(status),
            u"location":
            u"body",
            u"name":
            u"status",
        }],
    }

    #  docs
    response = app.post_json(
        "/plans/{}/documents?acc_token={}".format(plan_id, acc_token),
        {
            "data": {
                "title": u"укр.doc",
                "url": generate_docservice_url(app),
                "hash": "md5:" + "0" * 32,
                "format": "application/msword",
            }
        },
        status=422,
    )
    assert response.json == {
        u"status":
        u"error",
        u"errors": [{
            u"description":
            u"Can't update plan in '{}' status".format(status),
            u"location":
            u"body",
            u"name":
            u"status",
        }],
    }

    response = app.put_json(
        "/plans/{}/documents/{}?acc_token={}".format(plan_id, doc_id,
                                                     acc_token),
        {
            "data": {
                "title": u"укр_2.doc",
                "url": generate_docservice_url(app),
                "hash": "md5:" + "0" * 32,
                "format": "application/msword",
            }
        },
        status=422,
    )
    assert response.json == {
        u"status":
        u"error",
        u"errors": [{
            u"description":
            u"Can't update plan in '{}' status".format(status),
            u"location":
            u"body",
            u"name":
            u"status",
        }],
    }

    response = app.patch_json(
        "/plans/{}/documents/{}?acc_token={}".format(plan_id, doc_id,
                                                     acc_token),
        {"data": {
            "title": u"whatever.doc"
        }},
        status=422,
    )
    assert response.json == {
        u"status":
        u"error",
        u"errors": [{
            u"description":
            u"Can't update plan in '{}' status".format(status),
            u"location":
            u"body",
            u"name":
            u"status",
        }],
    }

    # tender creation
    response = app.post_json("/plans/{}/tenders".format(plan_id), {"data": {}},
                             status=422)
    assert response.json == {
        u"status":
        u"error",
        u"errors": [{
            u"description":
            u"Can't update plan in '{}' status".format(status),
            u"location":
            u"body",
            u"name":
            u"status",
        }],
    }