Ejemplo n.º 1
0
def test_approval_request_reject(conf, requests_session, headers):
    # Get an action we can work with
    action_response = requests_session.get(urljoin(conf.getoption("server"),
                                                   "/api/v3/action/"),
                                           headers=headers)
    data = action_response.json()
    action_id = data["results"][0]["id"]

    # Create a recipe associated with that action
    recipe_details = new_recipe(requests_session, action_id,
                                conf.getoption("server"), headers)

    # Update the name of the recipe
    updated_data = {
        "name":
        "update" + str(uuid.uuid4()),
        "action_id":
        action_id,
        "arguments":
        '{"learnMoreMessage":"This field may not be blank.","learnMoreUrl":"This field may not be blank.","message":"This field may not be blank.","postAnswerUrl":"This field may not be blank.","surveyId":"'
        + str(uuid.uuid4()) +
        '","thanksMessage":"This field may not be blank."}',
    }
    response = requests_session.put(
        urljoin(conf.getoption("server"),
                "/api/v3/recipe/{}/".format(recipe_details["id"])),
        data=updated_data,
        headers=headers,
    )
    assert response.status_code == 200, response.json()
    assert_valid_schema(response.json())
    latest_revision = response.json()["latest_revision"]
    assert latest_revision["name"] == updated_data["name"]
Ejemplo n.º 2
0
def test_recipe_enable(conf, requests_session, headers):
    # Get a list of actions and pick the first one
    action_response = requests_session.get(urljoin(conf.getoption("server"),
                                                   "/api/v3/action/"),
                                           headers=headers)
    data = action_response.json()
    action_id = data["results"][0]["id"]

    # Then create an approval request and submit it
    recipe_details = new_recipe(requests_session, action_id,
                                conf.getoption("server"), headers)
    response = create_approval_request(requests_session,
                                       conf.getoption("server"),
                                       recipe_details["latest_revision_id"],
                                       headers)
    data = response.json()
    approval_id = data["id"]
    approver_email = data["creator"]["email"]
    assert response.status_code != 404
    assert_valid_schema(response.json())

    # Verify that the request was actually created
    response = requests_session.get(
        urljoin(conf.getoption("server"),
                "/api/v3/approval_request/{}".format(approval_id)))
    data = response.json()
    assert response.status_code != 404
    assert_valid_schema(response.json())
    assert data["id"] == approval_id
    assert data["creator"]["email"] == approver_email

    # Approve the approval request
    response = approve_approval_request(requests_session,
                                        conf.getoption("server"), approval_id,
                                        headers)
    assert response.status_code != 404
    assert_valid_schema(response.json())

    # Look at the recipe and make sure that the recipe has been approved and our comment shows up
    response = requests_session.get(
        urljoin(conf.getoption("server"),
                "/api/v3/recipe/{}".format(recipe_details["id"])))
    assert response.status_code not in (404, 500)
    assert_valid_schema(response.json())
    approval_request = response.json()["latest_revision"]["approval_request"]
    assert approval_request["approved"] is True
    assert approval_request["comment"] == "r+"
    assert response.json()["latest_revision"]["enabled"] is False

    # Enable the recipe
    response = enable_recipe(requests_session, conf.getoption("server"),
                             recipe_details["id"], headers)
    assert response.status_code not in (404, 500)
    assert_valid_schema(response.json())
    assert response.json()["latest_revision"]["enabled"] is True
Ejemplo n.º 3
0
def test_approval_request_reject(conf, requests_session, headers):
    # Get an action we can work with
    action_response = requests_session.get(urljoin(conf.getoption("server"),
                                                   "/api/v3/action/"),
                                           headers=headers)
    data = action_response.json()
    action_id = data["results"][0]["id"]

    # Create a recipe associated with that action
    recipe_details = new_recipe(requests_session, action_id,
                                conf.getoption("server"), headers)

    # Create a approval request
    response = requests_session.post(
        urljoin(
            conf.getoption("server"),
            "/api/v3/recipe_revision/{}/request_approval/".format(
                recipe_details["latest_revision_id"]),
        ),
        headers=headers,
    )
    data = response.json()
    approval_id = data["id"]
    assert response.status_code != 404
    assert_valid_schema(response.json())

    # Reject the approval
    response = requests_session.post(
        urljoin(conf.getoption("server"),
                "/api/v3/approval_request/{}/reject/".format(approval_id)),
        data={"comment": "r-"},
        headers=headers,
    )
    assert response.status_code == 200
    assert_valid_schema(response.json())

    # Look at the recipe and make sure it the approval status has been set to False and our comment shows up
    response = requests_session.get(
        urljoin(conf.getoption("server"),
                "/api/v3/recipe/{}/".format(recipe_details["id"])))
    assert response.status_code != 404
    assert_valid_schema(response.json())
    approval_request = response.json()["latest_revision"]["approval_request"]
    assert approval_request["approved"] is False
    assert approval_request["comment"] == "r-"
Ejemplo n.º 4
0
def test_recipe_delete(conf, requests_session, headers):
    # Get an action we can work with
    action_response = requests_session.get(urljoin(conf.getoption("server"),
                                                   "/api/v3/action/"),
                                           headers=headers)
    data = action_response.json()
    action_id = data["results"][0]["id"]

    # Create a recipe associated with that action
    recipe_details = new_recipe(requests_session, action_id,
                                conf.getoption("server"), headers)

    # Delete the recipe
    response = requests_session.delete(
        urljoin(conf.getoption("server"),
                "/api/v3/recipe/{}/".format(recipe_details["id"])),
        headers=headers,
    )
    assert response.status_code == 204, response.json()
Ejemplo n.º 5
0
def test_approval_request_close(conf, requests_session, headers):
    # Get an action we can work with
    action_response = requests_session.get(urljoin(conf.getoption("server"),
                                                   "/api/v3/action/"),
                                           headers=headers)
    data = action_response.json()
    action_id = data["results"][0]["id"]

    # Create a recipe
    recipe_details = new_recipe(requests_session, action_id,
                                conf.getoption("server"), headers)

    # Create an approval request
    response = requests_session.post(
        urljoin(
            conf.getoption("server"),
            "/api/v3/recipe_revision/{}/request_approval/".format(
                recipe_details["latest_revision_id"]),
        ),
        headers=headers,
    )
    data = response.json()
    approval_id = data["id"]
    assert response.status_code != 404
    assert_valid_schema(response.json())

    # Close the approval request
    response = requests_session.post(
        urljoin(conf.getoption("server"),
                "/api/v3/approval_request/{}/close/".format(approval_id)),
        headers=headers,
    )
    assert response.status_code == 204

    # Verify that is no longer exists
    response = requests_session.get(
        urljoin(conf.getoption("server"),
                "/api/v3/approval_request/{}/".format(approval_id)),
        headers=headers,
    )
    assert response.status_code == 404