# Path: models/bases.py
# NO_VALUE = sa_symbol('NO_VALUE')
# class Base(object):
# class BaseModel(Base):
#     def __repr__(self):
#     def __str__(self):
#     def __tablename__(cls):  # pylint: disable=no-self-argument
#     def delete(self):
#     def _prepare_conditions(cls, conditions):
#     def get_all(cls, conditions=None):
#     def get_by_pk(cls, the_id):
#     def save(self, flush=False):
# 
# Path: ourapi/exceptions.py
# class Conflict(JSONAPIError, werkzeug.exceptions.Conflict):
#     """ 409 Conflict: fails server unique constraint or id issues. """
#     pass
# 
# class NotFound(JSONAPIError, werkzeug.exceptions.NotFound):
#     """ 404 Not Found: Resource doesn't exist. """
#     pass


    from builtins import *  # pylint: disable=unused-wildcard-import,redefined-builtin,wildcard-import
from models import bases
from ourapi.exceptions import Conflict, NotFound
    import sys
import datetime
import warnings
import marshmallow
import pytest
import sqlalchemy as sa
import ourapi
import ourmarshmallow
    with pytest.raises(NotFound) as excinfo:
        resource.patch(999, patch_data)

    assert excinfo.value.description == {'detail': '999 not found.',
                                         'source': {'parameter': '/id'}}

def test_detail_update_id_required(dbsession):  # pylint: disable=unused-argument
    """ Payload id and URL id must match for patch/update """
    the_model = Horses(id=30, name="Time Coin Instant Understand")
    the_model.save()

    # id is missing, but it is required: http://jsonapi.org/format/#crud-updating
    patch_data = {'data': {'attributes': {'name': 'bad request'}, 'type': 'horses'}}
    resource = HorsesResource()
    with pytest.raises(marshmallow.ValidationError) as excinfo:
            # This will be turned into a BadRequest by the error handler in the API.
        resource.patch(30, patch_data)

    assert excinfo.value.messages == {'errors': [{'detail': '`data` object must include `id` key.',
                                                  'source': {'pointer': '/data'}}]}

def test_detail_update_id_mismatch(dbsession):  # pylint: disable=unused-argument
    """ Payload id and URL id must match for patch/update """
    the_model = Horses(id=40, name="Madden Everything Wonder Pronunciation")
    the_model.save()

    # id does not match the request url id
    patch_data = {'data': {'attributes': {'name': 'bad request'},
                           'id': '999', 'type': 'horses'}}
    resource = HorsesResource()

# Path: models/bases.py
# NO_VALUE = sa_symbol('NO_VALUE')
# class Base(object):
# class BaseModel(Base):
#     def __repr__(self):
#     def __str__(self):
#     def __tablename__(cls):  # pylint: disable=no-self-argument
#     def delete(self):
#     def _prepare_conditions(cls, conditions):
#     def get_all(cls, conditions=None):
#     def get_by_pk(cls, the_id):
#     def save(self, flush=False):
# 
# Path: ourapi/exceptions.py
# class Conflict(JSONAPIError, werkzeug.exceptions.Conflict):
#     """ 409 Conflict: fails server unique constraint or id issues. """
#     pass
# 
# class NotFound(JSONAPIError, werkzeug.exceptions.NotFound):
#     """ 404 Not Found: Resource doesn't exist. """
#     pass


# Path: tests/ourapi/test_resource_detail.py
    from builtins import *  # pylint: disable=unused-wildcard-import,redefined-builtin,wildcard-import
from models import bases
from ourapi.exceptions import Conflict, NotFound
    import sys
import datetime
import warnings
import marshmallow
import pytest
import sqlalchemy as sa
import ourapi
import ourmarshmallow

    with pytest.raises(NotFound) as excinfo:
        resource.patch(999, patch_data)

    assert excinfo.value.description == {'detail': '999 not found.',
                                         'source': {'parameter': '/id'}}

def test_detail_update_id_required(dbsession):  # pylint: disable=unused-argument
    """ Payload id and URL id must match for patch/update """
    the_model = Horses(id=30, name="Time Coin Instant Understand")
    the_model.save()

    # id is missing, but it is required: http://jsonapi.org/format/#crud-updating
    patch_data = {'data': {'attributes': {'name': 'bad request'}, 'type': 'horses'}}
    resource = HorsesResource()
    with pytest.raises(marshmallow.ValidationError) as excinfo:
            # This will be turned into a BadRequest by the error handler in the API.
        resource.patch(30, patch_data)

    assert excinfo.value.messages == {'errors': [{'detail': '`data` object must include `id` key.',
                                                  'source': {'pointer': '/data'}}]}

def test_detail_update_id_mismatch(dbsession):  # pylint: disable=unused-argument
    """ Payload id and URL id must match for patch/update """
    the_model = Horses(id=40, name="Madden Everything Wonder Pronunciation")
    the_model.save()

    # id does not match the request url id
    patch_data = {'data': {'attributes': {'name': 'bad request'},
                           'id': '999', 'type': 'horses'}}
    resource = HorsesResource()

    with pytest.raises(Conflict) as excinfo: