Пример #1
0
def test_get_project_categories():
    verify_service_is_running()
    endpoint = '/projects/100/categories'
    response = requests.get(apiURL + endpoint)
    assert response.status_code == 200

    return
Пример #2
0
def test_delete_todo_by_id():
    verify_service_is_running()
    endpoint = 'todos'

    # create a new todo
    test_todo = {
        "title": "unit tests",
        "description": "create unit tests for ECSE429 project"
    }
    response_post = requests.post(apiURL + endpoint, json=test_todo)
    assert (response_post.ok)

    # number of todos before delete
    r = requests.get(apiURL + endpoint).json()
    num = len(r["todos"])

    # delete it
    new_id = response_post.json()["id"]
    response_delete = requests.delete(apiURL + endpoint + '/' + new_id)
    assert (response_delete.ok)

    #assert that it is gone from the todos endpoint and its previous /todos/id endpoint
    r = requests.get(apiURL + endpoint).json()
    assert_equal(num - 1, len(r["todos"]))
    r = requests.get(apiURL + endpoint + '/' + new_id)
    assert_equal(r.status_code, 404)  # 404 not found since it was deleted
    return
Пример #3
0
def test_get_all_projects():
    verify_service_is_running()
    endpoint = 'projects'
    response = requests.get(apiURL + endpoint)
    assert response.status_code == 200

    return
Пример #4
0
def test_post_todo_link_project():
    verify_service_is_running()
    endpoint = 'todos/1/tasksof'

    # num projects before adding new link
    r = requests.get(apiURL + endpoint).json()
    num = len(r["projects"])

    # create a new project for test
    r = requests.post(apiURL + 'projects', json={
        'title': 'Test Project'
    }).json()
    proj_id = r["id"]

    # post new link of project to a todo
    r = requests.post(apiURL + endpoint, json={"id": proj_id})
    assert (r.ok)

    # check that project link is posted at 'todos/1/tasksof'
    r = requests.get(apiURL + endpoint).json()
    assert_equal(len(r["projects"]), num + 1)

    # @after: delete this new link, delete test project
    requests.delete(apiURL + endpoint + '/' + proj_id)
    requests.delete(apiURL + 'projects/' + proj_id)
    return
Пример #5
0
def test_categories_in_random_order():
    verify_service_is_running()
    """
        Test code is in directory tests/category_tests/
    """
    for test_function in random_order_category_test():
        test_function()
Пример #6
0
def test_post_todo():
    verify_service_is_running()
    endpoint = 'todos'
    test_todo = {
        "title": "unit tests",
        "description": "create unit tests for ECSE429 project"
    }

    response = requests.post(apiURL + endpoint, json=test_todo)
    # assert that it is posted at /todos
    assert (response.ok)
    assert_equal(response.status_code, 201)  # new todo created
    response_body = response.json()
    assert_equal(response_body["title"], "unit tests")
    assert_equal(response_body["description"],
                 "create unit tests for ECSE429 project")
    assert_equal(response_body["doneStatus"],
                 'false')  # false done status on default creation

    #assert that new todo is also posed at /todos/id
    new_id = response_body["id"]
    response_by_id = requests.get(apiURL + endpoint + '/' + new_id)
    assert (response_by_id.ok)
    response_body_by_id = response.json()
    assert_equal(response_body_by_id["id"], new_id)
    assert_equal(response_body_by_id["title"], "unit tests")
    assert_equal(response_body_by_id["description"],
                 "create unit tests for ECSE429 project")
    assert_equal(response_body_by_id["doneStatus"], 'false')

    # delete new todo that was created
    r = requests.delete(apiURL + endpoint + '/' + new_id)
    assert (r.ok)
    return
Пример #7
0
def test_get_project_todos():
    verify_service_is_running()
    # get the tasks associated to a project
    endpoint = 'projects/1/tasks'
    response = requests.get(apiURL + endpoint)
    assert response.status_code == 200

    return
Пример #8
0
def test_post_todo_link_category_invalid():
    verify_service_is_running()
    endpoint = 'todos/1/categories'

    # post invalid category to this todo
    r = requests.post(apiURL + endpoint, json={"id": "9000"})
    assert_equal(r.status_code, 404)
    return
Пример #9
0
def test_API():
    verify_service_is_running()
    # Send a request to the API server and store the response.
    response = requests.get(apiURL)

    # Confirm that the request-response cycle completed successfully.
    assert_true(response.ok)
    return
Пример #10
0
def test_get_all_todos():
    verify_service_is_running()
    endpoint = 'todos'
    response = requests.get(apiURL + endpoint)

    # default /todos api has 2 todos
    assert_true(response.ok)
    response_body = response.json()
    assert_equal(len(response_body["todos"]), 2)
    return
Пример #11
0
def test_post_project_link_category():
    verify_service_is_running()
    # create a link between a project and a category (that exists or doesnt exist)
    endpoint = 'projects/1/categories'
    test_project = {"id": "2"}

    response = requests.post(apiURL + endpoint, json=test_project)
    assert response.status_code == 201
    response = requests.delete(apiURL + endpoint + '/2')
    assert response.status_code == 200
    return
Пример #12
0
def test_post_project_link_tasks():
    verify_service_is_running()
    endpoint = 'projects/1/tasks'
    test_project = {"id": "2"}

    response = requests.post(apiURL + endpoint, json=test_project)
    print(response)
    assert response.status_code == 201
    response = requests.delete(apiURL + endpoint + '/2')
    assert response.status_code == 200
    return
Пример #13
0
def test_post_invalid_project():
    verify_service_is_running()
    endpoint = 'projects'
    test_project = {
        "id": "1",
        "title": "fail test",
        "description": "helloworld"
    }

    response = requests.post(apiURL + endpoint, json=test_project)
    assert response.status_code == 400
    return
Пример #14
0
def test_post_project():
    verify_service_is_running()
    endpoint = 'projects'
    test_project = {"title": "correct test", "description": "helloworld"}

    response = requests.post(apiURL + endpoint, json=test_project)
    print(response)
    assert response.status_code == 201
    response_body = response.json()
    new_id = response_body["id"]
    anotherresponse = requests.delete(apiURL + endpoint + '/' + new_id)
    assert anotherresponse.status_code == 200
Пример #15
0
def test_delete_project_with_category():
    verify_service_is_running()
    # deleting a project that has tasks should not delete the task

    endpoint = 'projects/1/categories'
    test_project = {"id": "2"}

    response = requests.post(apiURL + endpoint, json=test_project)
    assert response.status_code == 201
    response = requests.delete(apiURL + endpoint + '/2')
    assert response.status_code == 200
    return
Пример #16
0
def test_get_todo_categories():
    verify_service_is_running()
    endpoint = 'todos/1/categories'
    r = requests.get(apiURL + endpoint)
    assert (r.ok)
    r_body = r.json()
    assert_equal(len(r_body["categories"]), 1)
    assert_equal(r_body["categories"], [{
        "id": "1",
        "title": "Office",
        "description": ""
    }])
    return
Пример #17
0
def test_post_invalid_todo():
    verify_service_is_running()
    # the API does not allow creating a todo with an ID
    # all IDs are autogenerated
    endpoint = 'todos'
    test_todo_invalid = {
        "id": 1234,
        "title": "invalid todo",
        "description": "should not be able to create todo with id"
    }

    response = requests.post(apiURL + endpoint, json=test_todo_invalid)
    response_body = response.json()
    # assert error message
    assert_equal(response.status_code, 400)  # 400 bad request
    assert_equal(
        response_body["errorMessages"],
        ["Invalid Creation: Failed Validation: Not allowed to create with id"])
    return
Пример #18
0
def test_post_todo_link_category():
    verify_service_is_running()
    endpoint = 'todos/1/categories'

    # num categories before adding new link
    r = requests.get(apiURL + endpoint).json()
    num = len(r["categories"])

    # post new link
    r = requests.post(apiURL + endpoint, json={"id": "2"})
    assert (r.ok)

    # check that category link is posted at 'todos/1/categories'
    r = requests.get(apiURL + endpoint).json()
    assert_equal(len(r["categories"]), num + 1)

    # @after: delete this new link
    requests.delete(apiURL + endpoint + '/2')
    return
Пример #19
0
def test_delete_todo_link_category():
    verify_service_is_running()
    endpoint = 'todos/1/categories'

    # @before:  post new link
    r = requests.post(apiURL + endpoint, json={"id": "2"})

    # num categories before deleting
    r = requests.get(apiURL + endpoint).json()
    num = len(r["categories"])

    # delete the link
    r = requests.delete(apiURL + endpoint + '/2')
    assert (r.ok)

    # check that link does not exist anymore
    r = requests.get(apiURL + endpoint + '/2')
    assert_equal(r.status_code, 404)
    r = requests.get(apiURL + endpoint).json()
    assert_equal(num - 1, len(r["categories"]))
    return
Пример #20
0
def test_get_todo_by_id():
    verify_service_is_running()
    endpoint = 'todos/1'
    response = requests.get(apiURL + endpoint)

    assert (response.ok)
    response_body = response.json()
    expected_response = [{
        "id": "1",
        "title": "scan paperwork",
        "doneStatus": "false",
        "description": "",
        "tasksof": [{
            "id": "1"
        }],
        "categories": [{
            "id": "1"
        }],
    }]
    assert_equal(len(response_body["todos"]), 1)
    assert_list_equal(response_body["todos"], expected_response)
    return
Пример #21
0
def test_delete_todo_link_project():
    verify_service_is_running()
    endpoint = 'todos/1/tasksof'

    # @before:  create new proj for test and post new link
    r = requests.post(apiURL + 'projects', json={
        'title': 'Test Project'
    }).json()
    proj_id = r["id"]
    r = requests.post(apiURL + endpoint, json={"id": proj_id})

    # num projects before deleting
    r = requests.get(apiURL + endpoint).json()
    num = len(r["projects"])

    # delete the link to test project
    r = requests.delete(apiURL + endpoint + '/' + proj_id)
    requests.delete(apiURL + 'projects/' + proj_id)
    assert (r.ok)

    # check that link does not exist anymore
    r = requests.get(apiURL + endpoint).json()
    assert_equal(num - 1, len(r["projects"]))
    return
Пример #22
0
def test_shutdown():
    verify_service_is_running()
    return
Пример #23
0
def test_docs():
    verify_service_is_running()
    endpoint = 'docs'
    return
Пример #24
0
def test_get_todo_projects():
    verify_service_is_running()
    endpoint = 'todos/2/tasksof'
    r = requests.get(apiURL + endpoint)
    assert (r.ok)
    return
Пример #25
0
def test_get_project_by_id():
    verify_service_is_running()
    endpoint = 'projects/1'
    response = requests.get(apiURL + endpoint)
    assert response.status_code == 200