desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Automatically created :class:`~pymongo.Connection` object corresponding to the provided configuration parameters.'
@property def cx(self):
if (self.config_prefix not in current_app.extensions['pymongo']): raise Exception('flask_pymongo extensions is not initialized') return current_app.extensions['pymongo'][self.config_prefix][0]
'Automatically created :class:`~pymongo.Database` object corresponding to the provided configuration parameters.'
@property def db(self):
if (self.config_prefix not in current_app.extensions['pymongo']): raise Exception('flask_pymongo extensions is not initialized') return current_app.extensions['pymongo'][self.config_prefix][1]
'test that regexes are stripped out of urls and #466 is fixed.'
def test_pretty_resource_urls(self):
resource_url = self.app.config['URLS']['peopleinvoices'] pretty_url = 'users/<person>/invoices' self.assertEqual(resource_url, pretty_url) resource_url = self.app.config['URLS']['peoplesearches'] pretty_url = 'users/<person>/saved_searches' self.assertEqual(resource_url, pretty_url)
'Test that the standard, custom error handler is registered for supported error codes.'
def test_custom_error_handlers(self):
codes = self.app.config['STANDARD_ERRORS'] handlers = self.app.error_handler_spec[None] challenge = (lambda code: self.assertTrue((code in handlers))) map(challenge, codes)
':param check: method checking the state of something during the event. :type: check: callable returning bool :param deepcopy: Do we need to store a copy of the argument calls? In some events arguments are changed after the event, so keeping a reference to the original object doesn\'t allow a test to check what was pas...
def __init__(self, check, deepcopy=False):
self.__called = None self.__check = check self.__deepcopy = deepcopy
'The results of the call to the event. :rtype: It returns None if the event hasn\'t been called or a tuple with the positional arguments of the last call if called.'
@property def called(self):
return self.__called
'test that #284 is fixed: If you have a media field, and set datasource projection to 0 for that field, the media will not be deleted'
def test_gridfs_media_storage_delete_projection(self):
(r, s) = self._post() _id = r[self.id_field] with self.app.test_request_context(): media_id = self.assertMediaStored(_id) self.app.config['DOMAIN']['contacts']['datasource']['projection'] = {'media': 0} (r, s) = self.parse_response(self.test_client.get(('%s/%s' % (self.url, _id)))) etag ...
'relying on POST and PATCH tests since we don\'t have an active app_context running here'
def test_unique_fail(self):
pass
'relying on POST and PATCH tests since we don\'t have an active app_context running here'
def test_unique_success(self):
pass
':param on_delete: Action to execute when the attribute is deleted'
def __init__(self, on_delete):
self.elements = [] self.on_delete = on_delete
'Prepare the test fixture :param settings_file: the name of the settings file. Defaults to `eve/tests/test_settings.py`.'
def setUp(self, settings_file=None, url_converters=None):
self.this_directory = os.path.dirname(os.path.realpath(__file__)) if (settings_file is None): settings_file = os.path.join(self.this_directory, 'test_settings.py') self.connection = None self.known_resource_count = 101 self.setupDB() self.settings_file = settings_file self.app = eve....
'If we attempt to retrieve an object by the same field that is in `auth_field`, then the request is /unauthorized/, and should fail and return 401. This test verifies that the `auth_field` does not overwrite a `client_filter` or url param.'
def test_get_by_auth_field_criteria(self):
(_, status) = self.parse_response(self.test_client.get(self.user_username_url, headers=self.valid_auth)) self.assert401(status)
'To test handling of ObjectIds'
def test_get_by_auth_field_id(self):
self.domain['users'][self.field_name] = self.domain['users']['id_field'] (_, status) = self.parse_response(self.test_client.get(self.user_id_url, headers=self.valid_auth)) self.assert401(status)
'To test handling of ObjectIds when using a `where` clause We need to make sure we *match* an object ID when it is the same'
def test_filter_by_auth_field_id(self):
_id = ObjectId('deadbeefdeadbeefdeadbeef') resource_def = self.app.config['DOMAIN']['users'] resource_def['authentication'].request_auth_value = _id resource_def[self.field_name] = '_id' user_url = '/users/' filter_by_id = 'where=_id==ObjectId("%s")' filter_query = (filter_by_id % self.user_...
'Test that if GET is in `public_methods` the `auth_field` criteria is overruled'
def test_collection_get_public(self):
self.resource['public_methods'].append('GET') (data, status) = self.parse_response(self.test_client.get(self.url)) self.assert200(status) self.assertEqual(len(data['_items']), 25)
'Test that if GET is in `public_item_methods` the `auth_field` criteria is overruled'
def test_item_get_public(self):
self.resource['public_item_methods'].append('GET') (data, status) = self.parse_response(self.test_client.get(self.item_id_url, headers=self.valid_auth)) self.assert200(status) self.assertEqual(data['_id'], self.item_id)
'Test that when BANDWIDTH_SAVER is turned off the auth_field is not exposed in the response payload'
def test_post_bandwidth_saver_off_resource_auth(self):
self.app.config['BANDWIDTH_SAVER'] = False r = self.app.test_client().post(self.url, data=self.data, headers=self.valid_auth, content_type='application/json') (r, status) = self.parse_response(r) self.assertTrue(('username' not in r))
'Test that when BANDWIDTH_SAVER is turned off the auth_field is not exposed in the response payload'
def test_put_bandwidth_saver_off_resource_auth(self):
self.app.config['BANDWIDTH_SAVER'] = False new_ref = '9999999999999999999999999' changes = json.dumps({'ref': new_ref}) (data, status) = self.post() url = ('%s/%s' % (self.url, data['_id'])) headers = [('If-Match', data['_etag']), self.valid_auth[0]] (response, status) = self.parse_response(...
'Makes sure links for `self`, `collection`, and `parent` point to the right place.'
def assertHateoasLinks(self, links, version_param):
self_url = links['self']['href'] coll_url = links['collection']['href'] prnt_url = links['parent']['href'] self.assertTrue((('?version=%s' % str(version_param)) in self_url)) if (version_param in ('all', 'diffs')): self.assertEqual(self_url.split('?')[0], coll_url) self.assertEqual(c...
''
def test_get(self):
self.do_test_get()
''
def test_getitem(self):
self.do_test_getitem(partial=False)
'Verify that a shadow document is created on post with all of the appropriate fields.'
def test_post(self):
self.do_test_post(partial=False)
'Eve literally throws single documents into an array before processing them in a POST, so I don\'t feel the need to specially test the versioning features here. Making a stub nontheless.'
def test_multi_post(self):
self.do_test_multi_post()
'Verify that an additional shadow document is created on post with all of the appropriate fields.'
def test_put(self):
self.do_test_put(partial=False)
''
def test_patch(self):
self.do_test_patch(partial=False)
''
def test_version_control_the_unkown(self):
self.do_test_version_control_the_unkown()
'Make sure that Eve return a nice error when requesting an unknown version.'
def test_getitem_version_unknown(self):
(response, status) = self.get(self.known_resource, item=self.item_id, query='?version=2') self.assert404(status)
'Make sure that Eve return a nice error when requesting an unknown version.'
def test_getitem_version_bad_format(self):
(response, status) = self.get(self.known_resource, item=self.item_id, query='?version=bad') self.assert400(status)
'Verify that all documents are returned which each appearing exactly as it would if it were accessed explicitly.'
def test_getitem_version_all(self):
meta_fields = (self.fields + [self.id_field, self.app.config['LAST_UPDATED'], self.app.config['ETAG'], self.app.config['DATE_CREATED'], self.app.config['LINKS'], self.version_field, self.latest_version_field]) (response, status) = self.put(self.item_id_url, data=self.item_change, headers=[('If-Match', self.item...
'Verify that `?version=all` and `?version=diffs` display pagination links when results exceed `PAGINATION_DEFAULT`.'
def test_getitem_version_pagination(self):
(response, status) = self.put(self.item_id_url, data=self.item_change, headers=[('If-Match', self.item_etag)]) for n in range(100): (response, status) = self.put(self.item_id_url, data=self.item_change, headers=[('If-Match', response[self.app.config['ETAG']])]) page = 2 (response, status) = self...
'Verify that on_fetched_item events are fired for versioned requests.'
def test_on_fetched_item(self):
devent = DummyEvent((lambda : True)) self.app.on_fetched_item += devent (response, status) = self.get(self.known_resource, item=self.item_id, query='?version=1') self.assertEqual(self.known_resource, devent.called[0]) self.assertEqual(self.item_id, str(devent.called[1][self.id_field])) self.asse...
'Verify that on_fetched_item_contacts events are fired for versioned requests.'
def test_on_fetched_item_contacts(self):
devent = DummyEvent((lambda : True)) self.app.on_fetched_item_contacts += devent (response, status) = self.get(self.known_resource, item=self.item_id, query='?version=1') self.assertEqual(self.item_id, str(devent.called[0][self.id_field])) self.assertEqual(1, len(devent.called)) devent = DummyEv...
'Verify that the first document is returned in its entirety and that subsequent documents are simply diff to the previous version.'
def test_getitem_version_diffs(self):
meta_fields = (self.fields + [self.id_field, self.app.config['LAST_UPDATED'], self.app.config['ETAG'], self.app.config['DATE_CREATED'], self.app.config['LINKS'], self.version_field, self.latest_version_field]) (response, status) = self.put(self.item_id_url, data=self.item_change, headers=[('If-Match', self.item...
'Verify that projections happen smoothly when versioning is on.'
def test_getitem_projection(self):
(response, status) = self.get(self.known_resource, item=self.item_id, query=('?projection={"%s": 1}' % self.unversioned_field)) self.assert200(status) self.assertTrue((self.unversioned_field in response)) self.assertFalse((self.versioned_field in response)) self.assertTrue((self.version_field in ...
'Verify that projections happen smoothly when versioning is on.'
def test_getitem_version_all_projection(self):
(response, status) = self.put(self.item_id_url, data=self.item_change, headers=[('If-Match', self.item_etag)]) self.assertGoodPutPatch(response, status) projection = ('{"%s": 1}' % self.unversioned_field) (response, status) = self.get(self.known_resource, item=self.item_id, query=('?version=all&proje...
'Verify that a cached document version is invalidated via an \'If-Modified-Since\' header when the _latest_version field has changed due to creation of a new version'
def test_getitem_version_new_latest_version_invalidates_if_modified_since(self):
r = self.test_client.get((self.item_id_url + '?version=1')) (document, status) = self.parse_response(r) self.assert200(status) self.assertEqual(document[self.latest_version_field], 1) last_modified = r.headers.get('Last-Modified') time.sleep(2) (response, status) = self.put(self.item_id_url,...
'Verify that a cached document version is invalidated via an \'If-None-Match\' header when the _latest_version field has changed due to creation of a new version'
def test_getitem_version_new_latest_version_invalidates_if_none_match(self):
r = self.test_client.get((self.item_id_url + '?version=1')) (document, status) = self.parse_response(r) self.assert200(status) self.assertEqual(document[self.latest_version_field], 1) version1_etag = r.headers.get('ETag') (response, status) = self.put(self.item_id_url, data=self.item_change, hea...
'Make sure that Eve throws an error if we try to set a versioning field manually.'
def test_automatic_fields(self):
self.item_change[self.version_field] = '1' (r, status) = self.post(self.known_resource_url, data=self.item_change) self.assertValidationErrorStatus(status) self.assertValidationError(r, {self.version_field: 'unknown field'}) self.item_change[self.latest_version_field] = '1' (r, status) = self...
'Make sure that Eve still correctly handles vanilla data_relations when versioning is turned on. (Copied from tests/methods/post.py.)'
def test_referential_integrity(self):
data = {'person': self.unknown_item_id} (r, status) = self.post('/invoices/', data=data) self.assertValidationErrorStatus(status) expected = ("value '%s' must exist in resource '%s', field '%s'" % (self.unknown_item_id, 'contacts', self.id_field)) self.assertValidationError(r...
'Verify that we don\'t throw an error if we delete a resource that is supposed to be versioned but whose shadow collection does not exist.'
def test_delete(self):
self.domain['contacts']['datasource']['filter'] = None self.assertTrue((self.countDocuments() > 0)) self.assertTrue((self.countShadowDocuments() > 0)) (response, status) = self.delete(self.known_resource_url) self.assert204(status) self.assertTrue((self.countDocuments() == 0)) self.assertTru...
'Verify that we don\'t throw an error if we delete an item that is supposed to be versioned but that doesn\'t have any shadow copies.'
def test_deleteitem(self):
self.assertTrue((self.countDocuments(self.item_id) > 0)) self.assertTrue((self.countShadowDocuments(self.item_id) > 0)) (response, status) = self.delete(self.item_id_url, headers=[('If-Match', self.item_etag)]) self.assert204(status) self.assertTrue((self.countDocuments(self.item_id) == 0)) self...
'Deleting a versioned item with soft delete enabled should create a new version marked as deleted, which is returned with 404 Not Found in response to GET requests. GETs of previous versions should continue to respond with `200 OK` responses. Requests for `?version=all/diff` should include the soft deleted version as i...
def test_softdelete(self):
self.enableSoftDelete() (response, status) = self.delete(self.item_id_url, headers=[('If-Match', self.item_etag)]) self.assert204(status) self.assertTrue((self.countDocuments(self.item_id) == 1)) self.assertTrue((self.countShadowDocuments(self.item_id) == 2)) r = self.test_client.get(self.item_i...
'Document versions created with soft delete enabled should include the DELETED field.'
def test_softdelete_version_db_fields(self):
self.enableSoftDelete() v1_doc = self._db[self.known_resource_shadow].find_one({self.document_id_field: ObjectId(self.item_id), self.version_field: 1}) self.assertEqual(v1_doc.get(self.deleted_field), None) r = self.test_client.patch(self.item_id_url, data={'ref': '1234567890123456789012345'}, headers=[...
'Make sure that Eve correctly validates a data_relation with a version and returns the version with the data_relation in the response.'
def test_referential_integrity(self):
data_relation = self.domain['invoices']['schema']['person']['data_relation'] value_field = data_relation['field'] version_field = self.app.config['VERSION'] validation_error_format = ("versioned data_relation must be a dict with fields '%s' and '%s'" % (value_field, version...
'Perform a quick check to make sure that Eve can embedded with a version in the data relation.'
def test_embedded(self):
data_relation = self.domain['invoices']['schema']['person']['data_relation'] value_field = data_relation['field'] data = {'person': {value_field: self.item_id, self.version_field: 1}} (response, status) = self.post('/invoices/', data=data) self.assert201(status) invoice_id = response[value_field...
'If a versioned embedded document is soft deleted, a previous version should still resolve correctly.'
def test_softdelete_embedded(self):
self.enableSoftDelete() data_relation = self.domain['invoices']['schema']['person']['data_relation'] value_field = data_relation['field'] version_field = self.app.config['VERSION'] data = {'person': {value_field: self.item_id, version_field: 1}} (response, status) = self.post('/invoices/', data=...
'Eve validation should not allow a data relation to a soft deleted document version. A data relation to an un-deleted version should be allowed.'
def test_softdelete_data_relation_validation(self):
self.enableSoftDelete() self.enableSoftDelete() (response, status) = self.delete(self.item_id_url, headers=[('If-Match', self.item_etag)]) self.assert204(status) data_relation = self.domain['invoices']['schema']['person']['data_relation'] value_field = data_relation['field'] version_field = ...
'Make sure that Eve correctly distinguishes between versions when referencing fields that aren\'t \'_id\'.'
def test_referential_integrity(self):
(response, status) = self.put(self.item_id_url, data=self.item_change, headers=[('If-Match', self.item_etag)]) self.assertGoodPutPatch(response, status) data = {'person': {'ref': self.item['ref'], self.version_field: 2}} (r, status) = self.post('/invoices/', data=data) self.assertValidationErrorStat...
'Make sure that Eve correctly distinguishes between versions when referencing unversioned fields'
def test_referential_integrity(self):
(response, status) = self.put(self.item_id_url, data=self.item_change, headers=[('If-Match', self.item_etag)]) self.assertGoodPutPatch(response, status) relation_field = self.unversioned_field data = {'person': {relation_field: self.item_change[relation_field], self.version_field: 1}} (r, status) = ...
'Test that get response successfully synthesize the full document even with unversioned fields.'
def test_get(self):
self.do_test_get()
'Test that get response can successfully synthesize both old and new document versions when partial versioning is in place.'
def test_getitem(self):
self.do_test_getitem(partial=True)
'Verify that partial version control can happen on POST.'
def test_post(self):
self.do_test_post(partial=True)
'Eve literally throws single documents into an array before processing them in a POST, so I don\'t feel the need to specially test the versioning features here. Making a stub nontheless.'
def test_multi_post(self):
self.do_test_multi_post()
'Verify that partial version control can happen on PUT.'
def test_put(self):
self.do_test_put(partial=True)
'Verify that partial version control can happen on PATCH.'
def test_patch(self):
self.do_test_patch(partial=True)
'Currently, the versioning scheme assumes true unless a field is explicitly marked to not be version controlled. That means, if \'allow_unknown\' is enabled, those fields are always version controlled. This is the same behavior as under TestCompleteVersioning.'
def test_version_control_the_unkown(self):
self.do_test_version_control_the_unkown()
'Make sure that Eve returns version = 1 even for documents that haven\'t been modified since version control has been turned on.'
def test_get(self):
(response, status) = self.get(self.known_resource) self.assert200(status) items = response[self.app.config['ITEMS']] self.assertEqual(len(items), self.app.config['PAGINATION_DEFAULT']) for item in items: self.assertDocumentVersionFields(item, 1)
'Make sure that Eve returns version = 1 even for documents that haven\'t been modified since version control has been turned on.'
def test_getitem(self):
(response, status) = self.get(self.known_resource, item=self.item_id) self.assert200(status) self.assertDocumentVersionFields(response, 1)
'Make sure that Eve jumps to version = 2 and saves two shadow copies (version 1 and version 2) for documents that where already in the database before version control was turned on.'
def test_put(self):
self.assertTrue((self.countShadowDocuments() == 0)) changes = {'ref': 'this is a different value'} (response, status) = self.put(self.item_id_url, data=changes, headers=[('If-Match', self.item_etag)]) self.assertGoodPutPatch(response, status) self.assertDocumentVersionFields(response, 2)...
'Make sure that Eve jumps to version = 2 and saves two shadow copies (version 1 and version 2) for documents that where already in the database before version control was turned on.'
def test_patch(self):
self.assertTrue((self.countShadowDocuments() == 0)) changes = {'ref': 'this is a different value'} (response, status) = self.patch(self.item_id_url, data=changes, headers=[('If-Match', self.item_etag)]) self.assertGoodPutPatch(response, status) self.assertDocumentVersionFields(response, ...
'Make sure that Eve uses the same mongo collection for storing versions when datasource is used.'
def test_datasource(self):
self.assertTrue((self.countShadowDocuments() == 0)) changes = {'ref': 'this is a different value'} (response, status) = self.patch(self.item_id_url, data=changes, headers=[('If-Match', self.item_etag)]) self.assertGoodPutPatch(response, status) self.assertDocumentVersionFields(response, ...
'Verify that we don\'t throw an error if we delete a resource that is supposed to be versioned but whose shadow collection does not exist.'
def test_delete(self):
self.domain['contacts']['datasource']['filter'] = None self.assertTrue((self.countDocuments() > 0)) self.assertTrue((self.countShadowDocuments() == 0)) (response, status) = self.delete(self.known_resource_url) self.assert204(status) self.assertTrue((self.countDocuments() == 0)) self.assertTr...
'Verify that we don\'t throw an error if we delete an item that is supposed to be versioned but that doesn\'t have any shadow copies.'
def test_deleteitem(self):
self.assertTrue((self.countDocuments(self.item_id) > 0)) self.assertTrue((self.countShadowDocuments(self.item_id) == 0)) (response, status) = self.delete(self.item_id_url, headers=[('If-Match', self.item_etag)]) self.assert204(status) self.assertTrue((self.countDocuments(self.item_id) == 0)) sel...
'Make sure that Eve jumps to version = 2 and saves two shadow copies (version 1 and version 2) for documents that where already in the database before version control was turned on.'
def test_softdelete(self):
self.enableSoftDelete() self.assertTrue((self.countDocuments(self.item_id) > 0)) self.assertTrue((self.countShadowDocuments(self.item_id) == 0)) (response, status) = self.delete(self.item_id_url, headers=[('If-Match', self.item_etag)]) self.assert204(status) self.assertTrue((self.countDocuments(...
'Make sure that Eve doesn\'t mind doing a data relation even when the shadow copy doesn\'t exist.'
def test_referential_integrity(self):
data_relation = self.domain['invoices']['schema']['person']['data_relation'] value_field = data_relation['field'] version_field = self.app.config['VERSION'] data = {'person': {value_field: self.item_id, version_field: 1}} (response, status) = self.post('/invoices/', data=data) self.assert201(sta...
'Perform a quick check to make sure that Eve can embedded with a version in the data relation.'
def test_embedded(self):
data_relation = self.domain['invoices']['schema']['person']['data_relation'] value_field = data_relation['field'] version_field = self.app.config['VERSION'] data = {'person': {value_field: self.item_id, version_field: 1}} (response, status) = self.post('/invoices/', data=data) self.assert201(sta...
'Make sure we can insert at least two versioning documents.'
def test_getitem(self):
self.do_test_getitem(partial=False)
'Test that #419 is closed and URL_PREFIX and API_VERSION are stipped out of hateoas links since they are now relative to the API entry point (root).'
def test_api_prefix_version_hateoas_links(self):
settings_file = os.path.join(self.this_directory, 'test_prefix_version.py') self.app = Eve(settings=settings_file) self.test_prefix = self.app.test_client() r = self.test_prefix.get('/prefix/v1/') href = json.loads(r.get_data())['_links']['child'][0]['href'] self.assertEqual(href, 'contacts') ...
'PATCH an object which is missing a field with a default value. This should result in setting the field to its default value, even if the field is not provided in the PATCH\'s payload.'
def test_patch_missing_default(self):
field = 'ref' test_value = '1234567890123456789012345' changes = {field: test_value} r = self.perform_patch(changes) self.assertEqual(self.compare_patch_with_get('title', r), 'Mr.')
'PATCH an object which is missing a field with a default value. This should result in setting the field to its default value, even if the field is not provided in the PATCH\'s payload.'
def test_patch_missing_default_with_post_override(self):
field = 'ref' test_value = '1234567890123456789012345' r = self.perform_patch_with_post_override(field, test_value) self.assert200(r.status_code) title = self.compare_patch_with_get('title', json.loads(r.get_data())) self.assertEqual(title, 'Mr.')
'Documents created outside the API context could be lacking the LAST_UPDATED and/or DATE_CREATED fields.'
def test_patch_missing_standard_date_fields(self):
contacts = self.random_contacts(1, False) ref = 'test_update_field' contacts[0]['ref'] = ref _db = self.connection[MONGO_DBNAME] _db.contacts.insert(contacts) (response, status) = self.get(self.known_resource, item=ref) etag = response[ETAG] _id = response['_id'] field = 'ref' te...
'Test that nested documents are not overwritten on PATCH and #519 is fixed.'
def test_patch_nested_document_not_overwritten(self):
schema = {'sensor': {'type': 'dict', 'schema': {'name': {'type': 'string'}, 'lon': {'type': 'float'}, 'lat': {'type': 'float'}, 'value': {'type': 'float', 'default': 10.3}, 'dict': {'type': 'dict', 'schema': {'string': {'type': 'string'}, 'int': {'type': 'integer'}}}}}, 'test': {'type': 'string', 'readonly': True, ...
'Test that when patching a field which is dependent on another and this other field is not provided with the patch but is still present on the target document, the patch will be accepted. See #363.'
def test_patch_dependent_field_on_origin_document(self):
del self.domain['contacts']['schema']['dependency_field1']['default'] changes = {'dependency_field2': 'value'} (r, status) = self.patch(self.item_id_url, data=changes, headers=[('If-Match', self.item_etag)]) self.assert422(status) changes = {'dependency_field1': 'value'} (r, status) = self.patch...
'Test that when patching a field which is dependent on another and this other field is not provided with the patch but is still present on the target document, the patch will be accepted. See #363.'
def test_patch_dependent_field_value_on_origin_document(self):
changes = {'dependency_field3': 'value'} (r, status) = self.patch(self.item_id_url, data=changes, headers=[('If-Match', self.item_etag)]) self.assert422(status) changes = {'dependency_field1': 'value'} (r, status) = self.patch(self.item_id_url, data=changes, headers=[('If-Match', self.item_etag)]) ...
'Make sure we don\'t alter document ETag when performing an oplog_push. See #590.'
def test_put_oplog_does_not_alter_document(self):
self.headers.append(('If-Match', self.item_etag)) r = self.test_client.put(self.item_id_url, data=json.dumps(self.data), headers=self.headers, environ_base={'REMOTE_ADDR': '127.0.0.1'}) etag1 = json.loads(r.get_data())['_etag'] etag2 = json.loads(self.test_client.get(self.item_id_url).get_data())['_etag...
'Soft delete should mark an item as deleted and cause subsequent requests to return 404 Not Found responses. 404s in response to GET requests should include the document in their body with the _deleted flag set to True.'
def test_delete(self):
(r, status) = self.delete(self.item_id_url, headers=self.etag_headers) self.assert204(status) r = self.test_client.get(self.item_id_url) (data, status) = self.parse_response(r) self.assert404(status) self.assertEqual(data.get(self.deleted_field), True) self.assertNotEqual(data.get('_etag'), ...
'Deleteitem internal should honor soft delete settings.'
def test_deleteitem_internal(self):
with self.app.test_request_context(self.item_id_url): (r, _, _, status) = deleteitem_internal(self.known_resource, concurrency_check=False, **{'_id': self.item_id}) self.assert204(status) r = self.test_client.get(self.item_id_url) (data, status) = self.parse_response(r) self.assert404(status...
'Soft deleting an entire resource should mark each individual item as deleted, queries to that resource should return no items, and GETs on any individual items should return 404 responses.'
def test_delete_from_resource_endpoint(self):
super(TestSoftDelete, self).test_delete_from_resource_endpoint() r = self.test_client.get(self.item_id_url) (data, status) = self.parse_response(r) self.assert404(status) self.assertEqual(data.get(self.deleted_field), True)
'Sending a PUT or PATCH to a soft deleted document should restore the document.'
def test_restore_softdeleted(self):
def soft_delete_item(etag): (r, status) = self.delete(self.item_id_url, headers=[('If-Match', etag)]) self.assert204(status) return self.test_client.get(self.item_id_url) deleted_etag = soft_delete_item(self.item_etag).headers['ETag'] r = self.test_client.patch(self.item_id_url, data...
'After an item has been soft deleted, subsequent DELETEs should return a 404 Not Found response.'
def test_multiple_softdelete(self):
(r, status) = self.delete(self.item_id_url, headers=self.etag_headers) self.assert204(status) r = self.test_client.get(self.item_id_url) new_etag = r.headers['ETag'] (r, status) = self.delete(self.item_id_url, headers=[('If-Match', new_etag)]) self.assert404(status)
'The configured \'deleted\' field should be added to all documents to indicate whether that document has been soft deleted or not.'
def test_softdelete_deleted_field(self):
r = self.test_client.get(self.item_id_url) (data, status) = self.parse_response(r) self.assert200(status) self.assertEqual(data.get(self.deleted_field), False)
'GETs on resource endpoints should include soft deleted items when the \'show_deleted\' param is included in the query, or when the DELETED field is explicitly included in the lookup.'
def test_softdelete_show_deleted(self):
(r, status) = self.delete(self.item_id_url, headers=self.etag_headers) self.assert204(status) (data, status) = self.get(self.known_resource) after_softdelete_count = data[self.app.config['META']]['total'] self.assertEqual(after_softdelete_count, (self.known_resource_count - 1)) (data, status) = ...
'Soft deleted documents embedded in other documents should not be included. They will resolve to None as if the document was actually deleted.'
def test_softdeleted_embedded_doc(self):
_db = self.connection[MONGO_DBNAME] fake_contact = self.random_contacts(1) fake_contact_id = _db.contacts.insert(fake_contact)[0] fake_contact_url = ((self.known_resource_url + '/') + str(fake_contact_id)) _db.invoices.update({'_id': ObjectId(self.invoice_id)}, {'$set': {'person': fake_contact_id}})...
'Soft deleted documents should not expand their embedded documents when returned in a 404 Not Found response. The deleted document data should reflect the state of the document when it was deleted, not change if still active embedded documents are updated'
def test_softdeleted_get_response_skips_embedded_expansion(self):
_db = self.connection[MONGO_DBNAME] fake_contact = self.random_contacts(1) fake_contact_id = _db.contacts.insert(fake_contact)[0] _db.invoices.update({'_id': ObjectId(self.invoice_id)}, {'$set': {'person': fake_contact_id}}) invoices = self.domain['invoices'] invoices['embedding'] = True inv...
'404 Not Found responses after soft delete should be cacheable'
def test_softdelete_caching(self):
(r, status) = self.delete(self.item_id_url, headers=self.etag_headers) self.assert204(status) r = self.test_client.get(self.item_id_url, headers=[('If-None-Match', self.item_etag)]) self.assert404(r.status_code) post_delete_etag = r.headers['ETag'] r = status = self.test_client.get(self.item_id_...
'Soft deleted items should not be returned by find methods in the Eve data layer unless show_deleted is explicitly configured in the request, the deleted field is included in the lookup, or the operation is \'raw\'.'
def test_softdelete_datalayer(self):
(r, status) = self.delete(self.item_id_url, headers=self.etag_headers) self.assert204(status) with self.app.test_request_context(): req = ParsedRequest() doc = self.app.data.find_one(self.known_resource, req, _id=self.item_id) self.assertEqual(doc, None) req.show_deleted = Tr...
'Documents created when soft delete is enabled should include and maintain the DELETED field in the db.'
def test_softdelete_db_fields(self):
r = self.test_client.post(self.known_resource_url, data={'ref': '1234567890123456789054321'}) (data, status) = self.parse_response(r) self.assert201(status) new_item_id = data[self.domain[self.known_resource]['id_field']] new_item_etag = data[self.app.config['ETAG']] with self.app.test_request_c...
'Test that when an exclusive projection is used in the \'datasource\' setting for the resource, enabling soft_deletes does not cause a 500 error. See #752.'
def test_exclusive_projection(self):
r = self.test_client.get('/exclusion?show_deleted') (data, status) = self.parse_response(r) self.assert200(status)
'Test that soft deleted documents are ignored when validating new documents against the \'unique\' rule. See #831.'
def test_exclude_soft_deleted_documents_from_unique_checks(self):
unique_value = '1234567890123456789054321' r = self.test_client.post(self.known_resource_url, data={'ref': unique_value}) (data, status) = self.parse_response(r) self.assert201(status) new_item_id = data[self.domain[self.known_resource]['id_field']] new_item_etag = data[self.app.config['ETAG']] ...
'Resource level soft delete configuration should override application configuration.'
def test_resource_specific_softdelete(self):
(data, status) = self.delete(self.item_id_url, headers=self.etag_headers) self.assert204(status) r = self.test_client.get(self.item_id_url) (data, status) = self.parse_response(r) self.assert404(status) self.assertEqual(data.get(self.deleted_field), True) (data, status) = self.delete(self.in...
'make sure Cerberus#48 is fixed'
def test_post_valueschema_dict(self):
del self.domain['contacts']['schema']['ref']['required'] (r, status) = self.post(self.known_resource_url, data={'valueschema_dict': {'k1': '1'}}) self.assertValidationErrorStatus(status) issues = r[ISSUES] self.assertTrue(('valueschema_dict' in issues)) self.assertEqual(issues['valueschema_dict'...
'test that pagination meta is present even when no records are being returned. #415.'
def test_get_pagination_no_documents(self):
(response, status) = self.get(self.known_resource, '?where={"ref": "not_really"}') self.assert200(status) self.assertPagination(response, 1, 0, 25)
'Make sure that query strings appear in all HATEOAS links (#464).'
def test_get_query_in_links(self):
for role in ('agent', 'client', 'vendor'): where = ('role == %s' % role) (response, _) = self.get(self.known_resource, ('?where=%s' % where)) if (response['_meta']['total'] >= (self.app.config['PAGINATION_DEFAULT'] + 1)): break links = response['_links'] total = res...
'Test that #369 is fixed and projection queries return consistent etags (as they are now stored along with the document).'
def test_get_projection_consistent_etag(self):
etag_field = self.app.config['ETAG'] data = {'inv_number': self.random_string(10)} (r, status) = self.post(self.empty_resource_url, data=data) etag = r[etag_field] projection = '{"prog": 1}' (r, status) = self.get(self.empty_resource, ('?projection=%s' % projection)) self.assertEqual(etag...
'Test that static projections are honoured'
def test_get_static_projection(self):
(response, status) = self.get(self.different_resource) self.assert200(status) resource = response['_items'] for r in resource: self.assertFalse(('location' in r)) self.assertFalse(('role' in r)) self.assertFalse(('prog' in r)) self.assertTrue(('username' in r)) se...
'the \'users\' resource is actually using the same db collection as \'contacts\'. Let\'s verify that base filters are being applied, and the right amount of items/links and the correct titles etc. are being returned. Of course \'contacts\' itself has its own base filter, which excludes the \'users\' (those with a \'use...
def test_get_same_collection_different_resource(self):
(response, status) = self.get(self.different_resource) self.assert200(status) links = response['_links'] self.assertEqual(len(links), 2) self.assertHomeLink(links) self.assertResourceLink(links, self.different_resource) resource = response['_items'] self.assertEqual(len(resource), 2) ...
'Documents created outside the API context could be lacking the LAST_UPDATED and/or DATE_CREATED fields.'
def test_documents_missing_standard_date_fields(self):
contacts = self.random_contacts(1, False) ref = 'test_update_field' contacts[0]['ref'] = ref _db = self.connection[MONGO_DBNAME] _db.contacts.insert(contacts) where = ('{"ref": "%s"}' % ref) (response, status) = self.get(self.known_resource, ('?where=%s' % where)) self.assert200(statu...
'test multipart/form-data resource fields that are JSON encoded are validated correctly. #806'
def test_get_embedded_media_validate_rest_of_fields(self):
self.app.config['MULTIPART_FORM_FIELDS_AS_JSON'] = True resource_with_media = {'image_file': {'type': 'media'}, 'some_text': {'type': 'string'}, 'some_boolean': {'type': 'boolean'}, 'some_number': {'type': 'number'}, 'some_list': {'type': 'list', 'schema': {'type': 'string'}}} self.app.register_resource('re...
'test that embeedded images are properly rendered and #305 is fixed.'
def test_get_embedded_media(self):
self.app.register_resource('digital_assets', {'schema': {'file': {'type': 'media'}}}) images = {'image_file': {'type': 'objectid', 'data_relation': {'resource': 'digital_assets', 'field': '_id', 'embeddable': True}}} self.app.register_resource('images', {'schema': images}) asset = 'a_file' data = {'...
'test that #381 is fixed.'
def test_get_invalid_idfield_cors(self):
request = ('/%s/badid' % self.known_resource) self.app.config['X_DOMAINS'] = '*' r = self.test_client.get(request, headers=[('Origin', 'test.com')]) self.assert404(r.status_code)