@mock.patch('ckanext.datastore.db._get_fields')
def test_upsert_with_insert_method_and_invalid_data(mock_get_fields_function):
 mock_connection = mock.Mock()
 mock_connection.execute.side_effect = sqlalchemy.exc.DataError('statement', 'params', 'orig', connection_invalidated=False)
 context = {'connection': mock_connection}
 data_dict = {'fields': [{'id': 'value', 'type': 'numeric'}], 'records': [{'value': 0}, {'value': 1}, {'value': 2}, {'value': 3}, {'value': '   '}, {'value': 5}, {'value': 6}, {'value': 7}], 'method': 'insert', 'resource_id': 'fake-resource-id'}
 mock_get_fields_function.return_value = data_dict['fields']
 nose.tools.assert_raises(db.InvalidDataError, db.upsert_data, context, data_dict)

@ mock . patch ( 'ckanext.datastore.db._get_fields' ) def test_upsert_with_insert_method_and_invalid_data ( mock_get_fields_function ) : mock_connection = mock . Mock ( ) mock_connection . execute . side_effect = sqlalchemy . exc . DataError ( 'statement' , 'params' , 'orig' , connection_invalidated = False ) context = { 'connection' : mock_connection } data_dict = { 'fields' : [ { 'id' : 'value' , 'type' : 'numeric' } ] , 'records' : [ { 'value' : 0 } , { 'value' : 1 } , { 'value' : 2 } , { 'value' : 3 } , { 'value' : '   ' } , { 'value' : 5 } , { 'value' : 6 } , { 'value' : 7 } ] , 'method' : 'insert' , 'resource_id' : 'fake-resource-id' } mock_get_fields_function . return_value = data_dict [ 'fields' ] nose . tools . assert_raises ( db . InvalidDataError , db . upsert_data , context , data_dict )
upsert_data() should raise invaliddataerror if given invalid data .