コード例 #1
0
def test_project_invalid_id_post():

    # Given
    project = {
        'title': 'Project title 1',
        'completed': False,
        'active': True,
    }

    project_change = {'description': 'This is a description'}

    res_specific_project = create_project(project)

    res_specific_project = create_project(project)
    specific_non_existing_id = int(res_specific_project['id']) + 1
    specific_project_id_url = url + str(specific_non_existing_id)

    # When
    res = requests.put(specific_project_id_url,
                       headers=headers,
                       data=json.dumps(project_change))
    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 404
コード例 #2
0
def test_get_non_empty_response_xml_projects():

    # Given
    headers = {'Content-Type': 'application/json', 'Accept': 'application/xml'}

    # Given
    project1 = {
        'title': 'Project title 1',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    project2 = {
        'title': 'Project title 2',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim xyz'
    }

    create_project(project1)
    create_project(project2)

    # When
    res = requests.get(url, headers=headers)

    # Then
    res_xml = xml.dom.minidom.parseString(res.content)
    print(res_xml.toprettyxml())

    assert res.status_code == 200
コード例 #3
0
def test_valid_id_get_response():

    # Given
    project = {
        'title': 'Project title 1',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    res_specific_project = create_project(project)
    specific_id = res_specific_project['id']

    specific_project_id_url = url + specific_id

    # When
    res = requests.get(specific_project_id_url, headers=headers)
    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 200
    assert len(res_body['projects']) == 1

    # Get id from specific project response
    res_project = [
        project for project in res_body['projects']
        if project['title'] == project['title']
    ][0]
    assert res_project['id'] == res_specific_project['id']
コード例 #4
0
def test_get_project_with_tasks():

    # Given
    headers = {'Content-Type': 'application/json'}

    todo = {'title': 'todo title', 'description': 'description of todo'}

    todo_id = create_todo(todo)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc',
        'tasks': [{
            'id': todo_id
        }]
    }

    project_id = create_project(project)['id']

    # When
    res = requests.get('http://localhost:4567/projects/' + project_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)

    # Then
    assert res.status_code == 200
    assert res_body['projects'][0]['tasks'][0]['id'] == todo_id
    assert len(res_body['projects'][0]['tasks'][0]) == 1
コード例 #5
0
def test_project_valid_id_post_xml():

    # Given
    headers = {'Content-Type': 'application/json', 'Accept': 'application/xml'}

    project = {
        'title': 'Project title 1',
        'completed': False,
        'active': True,
    }

    project_change = {'description': 'This is a description'}

    res_specific_project = create_project(project)
    specific_id = res_specific_project['id']

    specific_project_id_url = url + specific_id

    # When
    res = requests.post(specific_project_id_url,
                        headers=headers,
                        data=json.dumps(project_change))

    # Then
    res_xml = xml.dom.minidom.parseString(res.content)
    print(res_xml.toprettyxml())

    assert res.status_code == 200
コード例 #6
0
def test_delete_category_project_category_does_not_exist():

    # Given
    headers = {'Content-Type': 'application/json'}

    project = {
        'title': 'Office Work',
        'completed': False,
        'active': False,
        'description': 'a description'
    }

    project_id = create_project(project)['id']

    category = {'title': 'todo title'}

    category_id = create_category(category)['id']

    create_category_project_relation(category_id, project_id)

    invalid_id = '999'

    # When
    res = requests.delete(url(invalid_id, project_id), headers=headers)

    # Then
    print_response(res)

    assert res.status_code == 400
コード例 #7
0
def test_post_project_id_tasks_invalid_todo_id():

    # Given
    headers = {'Content-Type': 'application/json'}

    todo = {'title': 'todo title', 'description': 'description of todo'}

    todo_id = create_todo(todo)['id']
    invalid_todo_id = int(todo_id) + 1

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    todo_to_add = {'ID': str(invalid_todo_id)}

    project_id = create_project(project)['id']

    # When
    res = requests.post(url + project_id + '/tasks',
                        headers=headers,
                        data=json.dumps(todo_to_add))
    res_body = res.json()

    # Then
    print_response(res)
    assert res.status_code == 404
    assert res_body['errorMessages'][
        0] == 'Could not find thing matching value for ID'
コード例 #8
0
def test_get_todos_projects_xml():

    # Given
    headers = {'Content-Type': 'application/json', 'Accept': 'application/xml'}

    project = {
            'title': 'Office Work',
            'completed': False,
            'active': False,
            'description': 'a description'
    }

    project_id = create_project(project)['id']

    todo = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description',
        'tasksof': [
            {
                'id': project_id
            }
        ]
    }

    todo_id = create_todo(todo)['id']

    # When
    res = requests.get(url(todo_id), headers=headers)

    # Then
    res_xml = xml.dom.minidom.parseString(res.content)
    print(res_xml.toprettyxml())

    assert res.status_code == 200
コード例 #9
0
def test_post_todos_projects_invalid_body():

    # Given
    headers = {'Content-Type': 'application/json' }

    project = {
            'title': 'Office Work',
            'completed': False,
            'active': False,
            'description': 'a description'
    }

    project_id = create_project(project)['id']

    todo = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description'
    }

    todo_id = create_todo(todo)['id']

    body = {
        'idd': project_id
    }

    # When
    res = requests.post(url(todo_id), headers=headers, data=json.dumps(body))

    # Then
    print_response(res)

    assert res.status_code == 400
コード例 #10
0
def test_project_valid_id_put():

    # Given
    project = {
        'title': 'Project title 1',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    project_change = {'title': 'Project changed title'}

    res_specific_project = create_project(project)
    specific_id = res_specific_project['id']

    specific_project_id_url = url + specific_id

    # When
    res = requests.put(specific_project_id_url,
                       headers=headers,
                       data=json.dumps(project_change))
    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 200
    assert res_body['title'] == project_change['title']
コード例 #11
0
def test_delete_categories_projects_not_allowed():

    # Given
    headers = {'Content-Type': 'application/json'}

    project = {
        'title': 'Office Work',
        'completed': False,
        'active': False,
        'description': 'a description'
    }

    project_id = create_project(project)['id']

    category = {
        'title': 'Category title 1',
        'description': 'this is a description',
        'projects': [{
            'id': project_id
        }]
    }

    category_id = create_category(category)['id']

    # When
    res = requests.delete(url(category_id), headers=headers)

    # Then
    print_response(res)

    assert res.status_code == 405
コード例 #12
0
def test_project_id_category_patch_not_allowed():

    # Given
    headers = {'Content-Type': 'application/json'}

    category = {
        'title': 'category title',
        'description': 'description of category'
    }

    category_id = create_category(category)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    category_to_add = {'ID': category_id}

    project_id = create_project(project)['id']

    # When
    res = requests.patch(url + project_id + '/categories',
                         headers=headers,
                         data=json.dumps(category_to_add))

    # Then
    print_response(res)

    assert res.status_code == 405
コード例 #13
0
def test_post_project_with_invalid_categories():

    # Given
    headers = {'Content-Type': 'application/json'}

    category = {
        'title': 'category title',
        'description': 'description of category'
    }

    category_id = create_category(category)['id']
    invalid_category_id = int(category_id) + 1

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    category_to_add = {'ID': invalid_category_id}

    project_id = create_project(project)['id']

    # When
    res = requests.post(url + project_id + '/categories',
                        headers=headers,
                        data=json.dumps(category_to_add))
    res_body = res.json()

    # Then
    print_response(res)
    assert res.status_code == 404
    assert res_body['errorMessages'][
        0] == 'Could not find thing matching value for ID'
コード例 #14
0
def test_post_project_id_tasks_id_not_allowed():

    # Given
    headers = {'Content-Type': 'application/json'}

    todo = {'title': 'todo title', 'description': 'description of todo'}

    todo_id = create_todo(todo)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    project_id = create_project(project)['id']

    # When
    res = requests.post(url + project_id + '/tasks/' + todo_id,
                        headers=headers)

    # Then
    print_response(res)
    assert res.status_code == 405
コード例 #15
0
def test_project_id_tasks_head_OK():

    # Given
    headers = {'Content-Type': 'application/json'}

    todo = {'title': 'todo title', 'description': 'description of todo'}

    todo_id = create_todo(todo)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    todo_to_add = {'ID': todo_id}

    project_id = create_project(project)['id']

    # When
    res = requests.head(url + project_id + '/tasks',
                        headers=headers,
                        data=json.dumps(todo_to_add))

    # Then
    print_response(res)
    assert res.status_code == 200
コード例 #16
0
def test_get_project_with_categories():

    # Given
    headers = {'Content-Type': 'application/json'}

    category = {
        'title': 'category title',
        'description': 'description of category'
    }

    category_id = create_category(category)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc',
        'categories': [{
            'id': category_id
        }]
    }

    project_id = create_project(project)['id']

    # When
    res = requests.get('http://localhost:4567/projects/' + project_id,
                       headers=headers)
    res_body = res.json()

    # Then
    print_response(res)
    assert res.status_code == 200
    assert res_body['projects'][0]['categories'][0]['id'] == category_id
    assert len(res_body['projects'][0]['categories'][0]) == 1
コード例 #17
0
def test_get_project_with_categories_xml():

    # Given
    headers = {'Content-Type': 'application/json', 'Accept': 'application/xml'}

    category = {
        'title': 'category title',
        'description': 'description of category'
    }

    category_id = create_category(category)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc',
        'categories': [{
            'id': category_id
        }]
    }

    project_id = create_project(project)['id']

    # When
    res = requests.get(url + project_id + '/categories', headers=headers)

    # Then
    res_xml = xml.dom.minidom.parseString(res.content)
    print(res_xml.toprettyxml())

    assert res.status_code == 200
コード例 #18
0
def test_delete_todos_projects_not_allowed():

    # Given
    headers = {'Content-Type': 'application/json' }

    project = {
            'title': 'Office Work',
            'completed': False,
            'active': False,
            'description': 'a description'
    }

    project_id = create_project(project)['id']

    todo = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description',
        'tasksof': [
            {
                'id': project_id
            }
        ]
    }

    todo_id = create_todo(todo)['id']

    # When
    res = requests.delete(url(todo_id), headers=headers)

    # Then
    print_response(res)

    assert res.status_code == 405
コード例 #19
0
def test_get_non_empty_response_projects():

    # Given
    project1 = {
        'title': 'Project title 1',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    project2 = {
        'title': 'Project title 2',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim xyz'
    }

    create_project(project1)
    create_project(project2)

    # When
    res = requests.get(url, headers=headers)
    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 200
    assert len(res_body['projects']) == 2

    # Get todos from list since there is no guarantee on ordering in the response
    res_project1 = [
        project for project in res_body['projects']
        if project['title'] == project1['title']
    ][0]
    res_project2 = [
        project for project in res_body['projects']
        if project['title'] == project2['title']
    ][0]

    assert res_project1['title'] == project1['title']
    assert res_project1['description'] == project1['description']
    assert res_project2['title'] == project2['title']
    assert res_project2['description'] == project2['description']
コード例 #20
0
def test_delete_todo_project():

    # Given
    headers = {'Content-Type': 'application/json' }

    project = {
            'title': 'Office Work',
            'completed': False,
            'active': False,
            'description': 'a description'
    }

    project_id = create_project(project)['id']

    todo = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description',
        'tasksof': [
            {
                'id': project_id
            }
        ]
    }

    todo_id = create_todo(todo)['id']

    create_todo_project_relation(todo_id, project_id)

    # When
    res = requests.delete(url(todo_id, project_id), headers=headers)

    # Then
    print_response(res)

    assert res.status_code == 200

    # Fetch todo and project to assert that the project relationship was deleted
    updated_todo = requests.get(base_url + todo_id, headers=headers)
    updated_todo_body = updated_todo.json()

    print('Todo:')
    print_response(updated_todo)

    assert updated_todo_body['todos'][0].get('tasksof') is None

    updated_project = requests.get(project_url + todo_id, headers=headers)
    updated_project_body = updated_project.json()

    print('Project:')
    print_response(updated_project)

    assert updated_project_body['projects'][0].get('tasks') is None
コード例 #21
0
def test_modify_project(num):

    t_start = datetime.utcnow().timestamp()

    reset_system()

    init_existing_projects(num=num)

    headers = {'Content-Type': 'application/json'}

    # Given
    project = {
        'title': 'Project title 1',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    project_change = {'title': 'Project changed title'}

    res_specific_project = create_project(project)
    specific_id = res_specific_project['id']

    specific_project_id_url = url + '/' + specific_id

    t_start_call = datetime.utcnow().timestamp()

    # When
    res = requests.put(specific_project_id_url,
                       headers=headers,
                       data=json.dumps(project_change))

    t_end_call = datetime.utcnow().timestamp()

    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 200
    assert res_body['title'] == project_change['title']

    t_end = datetime.utcnow().timestamp()

    t1 = t_end - t_start
    t2 = t_end_call - t_start_call

    f = open("perf_logs/modify_project_performance_test.csv", "a")
    f.write(
        str(datetime.now().isoformat()) + ',' + str(num) + ',' + str(t1) +
        ',' + str(t2) + '\n')
    f.close()
コード例 #22
0
def test_delete_category_project():

    # Given
    headers = {'Content-Type': 'application/json'}

    project = {
        'title': 'Office Work',
        'completed': False,
        'active': False,
        'description': 'a description'
    }

    project_id = create_project(project)['id']

    category = {
        'title': 'Category title 1',
        'description': 'this is a description',
        'projects': [{
            'id': project_id
        }]
    }

    category_id = create_category(category)['id']

    create_category_project_relation(category_id, project_id)

    # When
    res = requests.delete(url(category_id, project_id), headers=headers)

    # Then
    print_response(res)

    assert res.status_code == 200

    # Fetch category and project to assert that the project relationship was deleted
    updated_category = requests.get(base_url + category_id, headers=headers)
    updated_category_body = updated_category.json()

    print('Category:')
    print_response(updated_category)

    assert updated_category_body['categories'][0].get('projects') is None

    updated_project = requests.get(project_url + category_id, headers=headers)
    updated_project_body = updated_project.json()

    print('Project:')
    print_response(updated_project)

    assert updated_project_body['projects'][0].get('categories') is None
コード例 #23
0
def step_impl(context):

    body = dict()

    if 'listTitle' in context:
        body['title'] = context.listTitle

    if 'description' in context:
        body['description'] = context.description

    if 'id' in context:
        body['id'] = context.id

    context.response = create_project(body)
コード例 #24
0
def test_delete_project_id_categories_id_no_relationship():

    # Given
    headers = {'Content-Type': 'application/json'}

    category1 = {
        'title': 'category title1',
        'description': 'description of category'
    }

    category2 = {
        'title': 'category title2',
        'description': 'description of category'
    }

    category_id1 = create_category(category1)['id']
    category_id2 = create_category(category2)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc',
        'categories': [{
            'id': category_id1
        }]
    }

    project_id = create_project(project)['id']

    # When
    res = requests.delete(url + project_id + '/categories/' + category_id2,
                          headers=headers)
    res_body = res.json()

    # Then
    assert res.status_code == 404
    assert res_body['errorMessages'][
        0] == 'Could not find any instances with projects/' + project_id + '/categories/' + category_id2

    res = requests.get('http://localhost:4567/projects/' + project_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)
    # assert relationship wasn't deleted
    assert len(res_body['projects'][0]) == 6
    assert res_body['projects'][0]['categories'][0]['id'] == category_id1
コード例 #25
0
def test_delete_project_id_categories_id_allowed():

    # Given
    headers = {'Content-Type': 'application/json'}

    category = {
        'title': 'category title',
        'description': 'description of category'
    }

    category_id = create_category(category)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc',
        'categories': [{
            'id': category_id
        }]
    }

    project_id = create_project(project)['id']

    create_category_project_relation(category_id, project_id)

    # When
    res = requests.delete(url + project_id + '/categories/' + category_id,
                          headers=headers)

    # Then
    assert res.status_code == 200

    # Check that relationship was deleted from both project and category
    res = requests.get('http://localhost:4567/projects/' + project_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)
    assert res_body['projects'][0].get('categories') is None

    res = requests.get('http://localhost:4567/categories/' + category_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)
    assert res_body['categories'][0].get('projects') is None
コード例 #26
0
def test_post_project_categories_valid():

    # Given
    headers = {'Content-Type': 'application/json'}

    category = {
        'title': 'category title',
        'description': 'description of category'
    }

    category_id = str(create_category(category)['id'])

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc'
    }

    project_id = create_project(project)['id']

    category_to_add = {'id': category_id}

    # When
    res = requests.post(url + project_id + '/categories',
                        headers=headers,
                        data=json.dumps(category_to_add))

    # Then
    print_response(res)
    assert res.status_code == 201

    # Fetch project and category to ensure relation was created
    res = requests.get('http://localhost:4567/projects/' + project_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)
    assert res_body['projects'][0].get('categories') is not None

    res = requests.get('http://localhost:4567/categories/' + category_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)
    assert res_body['categories'][0].get('projects') is not None
コード例 #27
0
def test_post_todos_projects():

    # Given
    headers = {'Content-Type': 'application/json' }

    project = {
            'title': 'Office Work',
            'completed': False,
            'active': False,
            'description': 'a description'
    }

    project_id = create_project(project)['id']

    todo = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description'
    }

    todo_id = create_todo(todo)['id']

    body = {
        'id': project_id
    }

    # When
    res = requests.post(url(todo_id), headers=headers, data=json.dumps(body))

    # Then
    print_response(res)

    assert res.status_code == 201

    # Fetch todo and project to assert tasksof relationship was created
    updated_todo = requests.get(base_url + todo_id, headers=headers)
    updated_todo_body = updated_todo.json()
    print_response(updated_todo)

    assert updated_todo_body['todos'][0]['tasksof'][0]['id'] == project_id

    updated_project = requests.get(projects_url + project_id, headers=headers)
    updated_project_body = updated_project.json()
    print_response(updated_project)

    assert updated_project_body['projects'][0]['tasks'][0]['id'] == todo_id
コード例 #28
0
def test_delete_project_id_tasks_id_allowed():

    # Given
    headers = {'Content-Type': 'application/json'}

    todo = {'title': 'todo title', 'description': 'description of todo'}

    todo_id = create_todo(todo)['id']

    project = {
        'title': 'Project title',
        'completed': False,
        'active': True,
        'description': 'agna aliqua. Ut enim abc',
        'tasks': [{
            'id': todo_id
        }]
    }

    project_id = create_project(project)['id']

    create_todo_project_relation(todo_id, project_id)

    # When
    res = requests.delete(url + project_id + '/tasks/' + todo_id,
                          headers=headers)

    # Then
    print_response(res)
    assert res.status_code == 200

    # Confirm it was succesfully deleted from both project and todo
    res = requests.get('http://localhost:4567/projects/' + project_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)
    assert res_body['projects'][0].get('tasks') is None

    res = requests.get('http://localhost:4567/todos/' + todo_id,
                       headers=headers)
    res_body = res.json()

    print_response(res)
    assert res_body['todos'][0].get('tasksof') is None
コード例 #29
0
def step_impl(context):
    for todo in context.table:
        todo_table = todo.as_dict()

        todo_dict = {'title': todo_table['taskTitle']}
        if 'doneStatus' in todo_table:
            todo_dict['doneStatus'] = todo_table['doneStatus'] == 'True'
        if 'description' in todo_table:
            todo_dict['description'] = todo_table['description']

        todo_id = create_todo(todo_dict)['id']

        if 'priorityLevel' in todo_table:
            category_id = get_categories({'title': todo_table['priorityLevel']}).json()['categories'][0]['id']
            create_todo_category_relation(todo_id, category_id)
        if 'project' in todo_table:
            project_id = create_project({'title': todo_table['project']})['id']
            create_todo_project_relation(todo_id, project_id)
コード例 #30
0
def test_post_todo_valid_body_with_project_relationship():

    # Given
    headers = {'Content-Type': 'application/json' } 

    project = {
            'title': 'Office Work',
            'completed': False,
            'active': False,
            'description': 'a description'
    }

    project_id = create_project(project)['id']

    todo = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description',
        'tasksof': [
            {
                'id': project_id
            }
        ]
    }

    # When
    res = requests.post(url, headers=headers, data=json.dumps(todo))
    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 201
    assert res_body['title'] == todo['title']
    assert res_body['doneStatus'] == str(todo['doneStatus']).lower()
    assert res_body['description'] == todo['description']

    # Assert todo was added to project
    updated_project = requests.get(base_url + 'projects/' + project_id, headers=headers)
    updated_project_body = updated_project.json()

    print_response(updated_project)
    assert updated_project_body['projects'][0]['tasks'][0]['id'] == res_body['id']