Skip to content

Commit

Permalink
Corrected resource_name and restored 404 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mansimarkaur committed Oct 14, 2016
1 parent f68d999 commit e4fdefc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions kinto/core/resource/__init__.py
Expand Up @@ -680,12 +680,12 @@ def _get_record_or_404(self, record_id):
try:
return self.model.get_record(record_id)
except storage_exceptions.RecordNotFoundError:
detail_dict = {
details = {
"id": record_id,
"resource_name": "record"
"resource_name": self.request.current_resource_name
}
response = http_error(HTTPNotFound(), errno=ERRORS.INVALID_RESOURCE_ID,
details=detail_dict)
details=details)
raise response

def _add_timestamp_header(self, response, timestamp=None):
Expand Down
5 changes: 5 additions & 0 deletions kinto/core/testing.py
Expand Up @@ -89,6 +89,11 @@ def assertFormattedError(self, response, code, errno, error,
else: # pragma: no cover
self.assertNotIn('info', response.json)

if details is not None:
self.assertEqual(response.json['details'], details)
else:
self.assertNotEqual(404, code)


def get_user_headers(user):
"""Helper to obtain a Basic Auth authorization headers from the specified
Expand Down
8 changes: 4 additions & 4 deletions kinto/views/__init__.py
Expand Up @@ -30,10 +30,10 @@ def object_exists_or_404(request, collection_id, object_id, parent_id=''):
object_id=object_id)
except exceptions.RecordNotFoundError:
# XXX: We gave up putting details about parent id here (See #53).
detail_dict = {
"id": collection_id,
"resource_name": "collection"
details = {
"id": object_id,
"resource_name": collection_id
}
response = http_error(HTTPNotFound(), errno=ERRORS.MISSING_RESOURCE,
details=detail_dict)
details=details)
raise response
15 changes: 9 additions & 6 deletions tests/core/test_views_errors.py
Expand Up @@ -39,17 +39,20 @@ def test_backoff_header_is_present_on_error_responses(self):
self.assertIn('Backoff', response.headers)
self.assertEquals(response.headers['Backoff'], '10')

def test_404_is_valid_formatted_error(self):
def test_404_is_valid_formatted_error(self):
response = self.app.get('/unknown', status=404)
self.assertFormattedError(response, 404, ERRORS.MISSING_RESOURCE, "Not Found",
"The resource you are looking for could not be found.")

def test_404_can_be_overridden(self):
custom_404 = http_error(httpexceptions.HTTPNotFound(),
errno=ERRORS.MISSING_RESOURCE,
message="Customized.",
details={"id": "abc", "resource_name": "collection"})
message="Customized.")
with mock.patch('tests.core.testapp.views.Mushroom._extract_filters',
side_effect=custom_404):
response = self.app.get(self.sample_url, headers=self.headers, status=404)
self.assertFormattedError(
response=response, code=404, errno=ERRORS.MISSING_RESOURCE, error="Not Found",
message="Customized.", details={"id": "abc", "resource_name": "collection"})
self.assertFormattedError(response, 404, ERRORS.MISSING_RESOURCE,
"Not Found", "Customized.")

def test_401_is_valid_formatted_error(self):
response = self.app.get(self.sample_url, status=401)
Expand Down

0 comments on commit e4fdefc

Please sign in to comment.