Esempio n. 1
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
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'
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
Esempio n. 4
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
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
Esempio n. 7
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
Esempio n. 8
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']
Esempio n. 9
0
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']
Esempio n. 10
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']
Esempio n. 11
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
def test_post_todos_categories_todo_does_not_exist():

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

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

    category_id = create_category(category)['id']

    invalid_id = '999'

    body = {'id': category_id}

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

    # Then
    print_response(res)

    assert res.status_code == 404
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']
Esempio n. 14
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
Esempio n. 15
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'
Esempio n. 16
0
def test_put_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'
Esempio n. 17
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
Esempio n. 18
0
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_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
Esempio n. 20
0
def test_post_category_invalid_attribute():

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

    category = {
        'title': 'Category title 1',
        'description': 'this is a description'
    }

    category_id = create_category(category)['id']

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

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

    # Then
    print_response(res)

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

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

    invalid_id = '999'

    category = {
        'title': 'Category title 1',
        'description': 'this is a description'
    }

    category_id = create_category(category)['id']

    body = {'id': invalid_id}

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

    # Then
    print_response(res)

    assert res.status_code == 404
Esempio n. 22
0
def test_put_category_valid_body():

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

    category = {
        'title': 'Category title 1',
        'description': 'this is a description'
    }

    category_id = create_category(category)['id']

    edited_category = {
        'title': 'A different title',
        'description': 'a different description'
    }

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

    # Then
    print_response(res)

    assert res.status_code == 200
    assert res_body['id'] == category_id
    assert res_body['title'] == edited_category['title']
    assert res_body['description'] == edited_category['description']
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
Esempio n. 24
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_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_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_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
Esempio n. 28
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
Esempio n. 29
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'
Esempio n. 30
0
def test_patch_not_allowed_todos():

    # When
    res = requests.patch(url, headers={'Content-Type': 'application/json' } )

    # Then
    print_response(res)

    assert res.status_code == 405