예제 #1
0
def test_db_object_mixin_filter_by_id_model_must_be_set(app):

    mock_query = Mock()
    mixin = DBObjectMixin()
    mixin.kwargs = {'obj_id': 1}  # Simulate kwargs being set by an Endpoint class.

    with pytest.raises(ArrestedException):
        mixin.filter_by_id(mock_query.return_value)
예제 #2
0
def test_db_object_mixin_filter_by_id_invalid_id_field(app):

    mock_query = Mock()
    mixin = DBObjectMixin()
    mixin.model = Model
    mixin.model_id_param = 'bar'
    mixin.kwargs = {'obj_id': 1}  # Simulate kwargs being set by an Endpoint class.

    with pytest.raises(ArrestedException):
        mixin.filter_by_id(mock_query.return_value)
예제 #3
0
def test_db_object_mixin_get_result(app):

    mock_query = Mock()
    mock_query.return_value.one_or_none.return_value = 'foo'
    mixin = DBObjectMixin()
    mixin.kwargs = {'obj_id': 1}  # Simulate kwargs being set by an Endpoint class.

    res = mixin.get_result(mock_query.return_value)

    assert res == 'foo'
    mock_query.return_value.one_or_none.assert_called_once()
예제 #4
0
def test_db_object_mixin_filter_by_id(app):

    mock_query = Mock()
    mixin = DBObjectMixin()
    mixin.model = Model
    mixin.kwargs = {'obj_id': 1}  # Simulate kwargs being set by an Endpoint class.

    mixin.filter_by_id(mock_query.return_value)

    params = (Model.id == 1)
    mock_query.return_value.filter.assert_called_once_with(params)
예제 #5
0
def test_db_object_mixin_get_object(app):

    mixin = DBObjectMixin()
    mixin.kwargs = {'obj_id': 1}  # Simulate kwargs being set by an Endpoint class.
    mixin.model = Model
    query_mock = patch.object(DBObjectMixin, 'get_query')
    mock_query = query_mock.start()
    mock_query.return_value.filter.return_value.one_or_none.return_value = 'foo'

    res = mixin.get_object()

    assert res == 'foo'

    query_mock.stop()