Exemple #1
0
def test_get_non_empty_response_xml_todos():

    # Given
    headers = {'Content-Type': 'application/json', 'Accept': 'application/xml' } 
    
    todo1 = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description'
    }

    todo2 = {
        'title': 'Task title 2',
        'doneStatus': True,
        'description': 'this is another description'
    }

    create_todo(todo1)
    create_todo(todo2)

    # 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
def test_get_todos_categories():

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

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

    category_id = create_category(category)['id']

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

    todo_id = create_todo(todo)['id']

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

    # Then
    print_response(res)

    assert res.status_code == 200
    assert res_body['categories'][0]['id'] == category_id
    assert res_body['categories'][0]['title'] == category['title']
    assert res_body['categories'][0]['description'] == category['description']
Exemple #3
0
def test_get_project_with_tasks_xml():

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

    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(url + project_id + '/tasks', headers=headers)

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

    assert res.status_code == 200
Exemple #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
def test_get_todos_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']

    todo = {
        'title': 'Task title 1',
        'doneStatus': False,
        'description': 'this is a description',
        'categories': [{
            'id': category_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
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
def test_post_todo_invalid_attribute():

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

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

    todo_id = create_todo(todo)['id']

    edited_todo = {'invalid attr': 'test'}

    # When
    res = requests.put(url + todo_id,
                       headers=headers,
                       data=json.dumps(edited_todo))
    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 400
    assert res_body['errorMessages'][0] == 'Could not find field: invalid attr'
def test_put_todo_valid_body():

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

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

    todo_id = create_todo(todo)['id']

    edited_todo = {
        'title': 'A different title',
        'doneStatus': True,
        'description': 'a different description'
    }

    # When
    res = requests.put(url + todo_id,
                       headers=headers,
                       data=json.dumps(edited_todo))
    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 200
    assert res_body['id'] == todo_id
    assert res_body['title'] == edited_todo['title']
    assert res_body['doneStatus'] == str(edited_todo['doneStatus']).lower()
    assert res_body['description'] == edited_todo['description']
def test_post_todo_id_valid_body_xml():

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

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

    todo_id = create_todo(todo)['id']

    edited_todo = {
        'title': 'A different title',
        'doneStatus': True,
        'description': 'a different description'
    }

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

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

    assert res.status_code == 200
Exemple #10
0
def test_get_category_with_todos():

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

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

    todo_id = create_todo(todo)['id']

    category = {
        'title': 'category title',
        'description': 'a description',
        'todos': [{
            'id': todo_id
        }]
    }

    category_id = create_category(category)['id']

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

    print_response(res)

    # Then
    assert res.status_code == 200
    assert res_body['categories'][0]['todos'][0]['id'] == todo_id
    assert len(res_body['categories'][0]['todos'][0]) == 1
Exemple #11
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'
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
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
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
def test_post_todo_category_not_allowed():

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

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

    category_id = create_category(category)['id']

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

    todo_id = create_todo(todo)['id']

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

    # Then
    print_response(res)

    assert res.status_code == 405
def test_get_todo():

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

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

    todo1_id = create_todo(todo1)['id']

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

    # Then
    print_response(res)

    assert res.status_code == 200
    assert len(res_body['todos']) == 1
    assert res_body['todos'][0]['id'] == todo1_id
    assert res_body['todos'][0]['title'] == todo1['title']
    assert res_body['todos'][0]['doneStatus'] == str(
        todo1['doneStatus']).lower()
    assert res_body['todos'][0]['description'] == todo1['description']
Exemple #17
0
def test_get_category_with_todos_xml():

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

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

    todo_id = create_todo(todo)['id']

    category = {
        'title': 'category title',
        'description': 'a description',
        'todos': [{
            'id': todo_id
        }]
    }

    category_id = create_category(category)['id']

    # When
    res = requests.get(url + category_id + '/todos', headers=headers)

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

    assert res.status_code == 200
Exemple #18
0
def test_post_category_id_todos():

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

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

    todo_id = create_todo(todo)['id']

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

    todo_to_add = {'ID': todo_id}

    category_id = create_category(category)['id']

    # When
    res = requests.post(url + category_id + '/todos',
                        headers=headers,
                        data=json.dumps(todo_to_add))

    # Then
    assert res.status_code == 201

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

    # Then, assert a relationship was made
    print_response(res)
    assert res_body['categories'][0]['todos'][0]['id'] == todo_id
    assert len(res_body['categories'][0]['todos'][0]) == 1
Exemple #19
0
def test_post_category_id_todos_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

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

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

    category_id = create_category(category)['id']

    # When
    res = requests.post(url + category_id + '/todos',
                        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'
Exemple #20
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
Exemple #21
0
def test_post_project_valid_body_with_todo_relation():

    # Given
    todo = {'title': 'todo title'}

    todo_id = create_todo(todo)['id']

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

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

    # Then
    print_response(res)

    assert res.status_code == 201
    assert res_body['title'] == project['title']
    assert res_body['description'] == project['description']
    assert res_body['tasks'][0]['id'] == todo_id

    # Assert project was added to todo
    updated_todo = requests.get(base_url + 'todos/' + todo_id, headers=headers)
    updated_todo_body = updated_todo.json()

    print_response(updated_todo)
    assert updated_todo_body['todos'][0]['tasksof'][0]['id'] == res_body['id']
def test_delete_todo_project_todo_does_not_exist():

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

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

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

    project_id = create_project(project)['id']

    todo_id = create_todo(todo)['id']

    create_todo_project_relation(todo_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
def test_post_todos_projects_todo_project_does_not_exist():

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

    invalid_id = '999'

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

    todo_id = create_todo(todo)['id']

    body = {
        'id': invalid_id
    }

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

    # Then
    print_response(res)

    assert res.status_code == 404
def test_delete_todo_category_todo_does_not_exist():

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

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

    category_id = create_category(category)['id']

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

    todo_id = create_todo(todo)['id']

    create_todo_category_relation(todo_id, category_id)

    invalid_id = '999'

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

    # Then
    print_response(res)

    assert res.status_code == 400
Exemple #25
0
def step_impl(context, taskTitle):
    task_del_id = create_todo({'title': taskTitle})['id']
    context.todo_id = task_del_id
    all_todos = get_todos().json()['todos']
    if taskTitle in [t['title'] for t in all_todos]:
        task_del = [t for t in all_todos if t['title'] == taskTitle]
        for t in task_del:
            delete_todo(t['id'])
Exemple #26
0
def test_put_todo_valid_body(num):

    t_start = datetime.utcnow().timestamp()

    reset_system()

    init_existing_todos(num=num)

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

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

    todo_id = create_todo(todo)['id']

    edited_todo = {
        'title': 'A different title',
        'doneStatus': True,
        'description': 'a different description'
    }

    t_start_call = datetime.utcnow().timestamp()

    # When
    res = requests.put(url + '/' + todo_id,
                       headers=headers,
                       data=json.dumps(edited_todo))

    t_end_call = datetime.utcnow().timestamp()

    res_body = res.json()

    # Then
    print_response(res)

    assert res.status_code == 200
    assert res_body['id'] == todo_id
    assert res_body['title'] == edited_todo['title']
    assert res_body['doneStatus'] == str(edited_todo['doneStatus']).lower()
    assert res_body['description'] == edited_todo['description']

    t_end = datetime.utcnow().timestamp()

    t1 = t_end - t_start
    t2 = t_end_call - t_start_call

    f = open("perf_logs/modify_todo_performance_test.csv", "a")
    f.write(
        str(datetime.now().isoformat()) + ',' + str(num) + ',' + str(t1) +
        ',' + str(t2) + '\n')
    f.close()
Exemple #27
0
def step_impl(context):

    body = dict()

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

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

    context.todo = create_todo(body)
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
Exemple #29
0
def test_get_non_empty_response_todos():

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

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

    todo2 = {
        'title': 'Task title 2',
        'doneStatus': True,
        'description': 'this is another description'
    }

    create_todo(todo1)
    create_todo(todo2)

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

    # Then
    print_response(res)

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

    # Get todos from list since there is no guarantee on ordering in the response
    res_todo1 = [todo for todo in res_body['todos'] if todo['title'] == todo1['title']][0]
    res_todo2 = [todo for todo in res_body['todos'] if todo['title'] == todo2['title']][0]

    assert res_todo1['title'] == todo1['title']
    assert res_todo1['doneStatus'] == str(todo1['doneStatus']).lower()
    assert res_todo1['description'] == todo1['description']
    assert res_todo2['title'] == todo2['title']
    assert res_todo2['doneStatus'] == str(todo2['doneStatus']).lower()
    assert res_todo2['description'] == todo2['description']
Exemple #30
0
def step_impl(context):
    context.todos = list()
    for todo in context.table:

        todo_dict = todo.as_dict()

        if 'doneStatus' in todo_dict:
            todo_dict['doneStatus'] = todo_dict['doneStatus'] == 'True'

        context.todos.append(todo_dict)

        todo_id = create_todo(todo_dict)['id']
        create_todo_project_relation(todo_id, context.project['id'])