def test_get_list_one_elem(one_goal_and_entry_in_db_client): """Test listing a database with one element""" expected = { 'data': [{ 'id': 1, 'goal_id': 1, 'occurred_date': '2020-03-20' }] } rv = one_goal_and_entry_in_db_client.get('{}/'.format( pytest.path_to_goal_entry)) expected = { 'data': [{ 'id': 1, 'name': 'goal1', 'entries': [{ 'id': 1, 'occurred_date': '2020-03-20' }] }] } rv = one_goal_and_entry_in_db_client.get('{}/'.format(pytest.path_to_goal)) assert_200_json_response(rv, expected)
def test_get_item_one_elem(one_goal_and_entry_in_db_client): """Test getting the one item of a db with one item""" expected = {'data': {'id': 1, 'goal_id': 1, 'occurred_date': '2020-03-20'}} rv = one_goal_and_entry_in_db_client.get('{}/1'.format( pytest.path_to_goal_entry)) assert_200_json_response(rv, expected)
def test_list_item_after_delete(one_in_db_client): """Ensure deleting item actually deletes the item""" expected_delete_response = {'data': 'success'} rv = one_in_db_client.delete('{}/1'.format(pytest.path_to_goal)) assert_200_json_response(rv, expected_delete_response) expected_list_response = {'data': []} rv = one_in_db_client.get('{}/'.format(pytest.path_to_goal)) assert_200_json_response(rv, expected_list_response)
def test_get_item_after_update(one_in_db_client): """Ensure update item actually updates the item""" expected_update_response = {'data': 'success'} json_in = {'name': 'new'} rv = one_in_db_client.put('{}/1'.format(pytest.path_to_goal), json=json_in) assert_200_json_response(rv, expected_update_response) expected_get_response = {'data': {'id': 1, 'name': 'new', 'entries': []}} rv = one_in_db_client.get('{}/1'.format(pytest.path_to_goal)) assert_200_json_response(rv, expected_get_response)
def test_get_item_after_update(one_goal_and_entry_in_db_client): """Ensure update item actually updates the item""" expected_update_response = {'data': 'success'} json_in = {'occurred_date': '2020-03-19'} rv = one_goal_and_entry_in_db_client.put('{}/1'.format( pytest.path_to_goal_entry), json=json_in) assert_200_json_response(rv, expected_update_response) expected_get_response = { 'data': { 'id': 1, 'goal_id': 1, 'occurred_date': '2020-03-19' } } rv = one_goal_and_entry_in_db_client.get('{}/1'.format( pytest.path_to_goal_entry)) assert_200_json_response(rv, expected_get_response)
def test_get_list_empty_db(client): """Test a blank database.""" expected = {'data': []} rv = client.get('{}/'.format(pytest.path_to_goal_entry)) assert_200_json_response(rv, expected)
def test_get_item_one_elem(one_in_db_client): """Test getting the one item of a db with one item""" expected = {'data': {'id': 1, 'name': 'item1', 'entries': []}} rv = one_in_db_client.get('{}/1'.format(pytest.path_to_goal)) assert_200_json_response(rv, expected)
def test_get_list_one_elem(one_in_db_client): """Test listing a database with one element""" expected = {'data': [{'id': 1, 'name': 'item1', 'entries': []}]} rv = one_in_db_client.get('{}/'.format(pytest.path_to_goal)) assert_200_json_response(rv, expected)
def test_insert_into_empty_db(client): """Test inserting an item into empty db""" expected = {'data': 'success'} rv = client.post('{}/'.format(pytest.path_to_goal), json={'name': 'item1'}) assert_200_json_response(rv, expected)