Skip to content

Commit

Permalink
Fixed not found errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Jan 20, 2015
1 parent f9290b7 commit 2d8426d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/openprocurement/api/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def get_db_schema_version(db):
schema_doc = db.get(SCHEMA_DOC, {"_id": SCHEMA_DOC})
return schema_doc.get("version", SCHEMA_VERSION)
return schema_doc.get("version", SCHEMA_VERSION - 1)


def set_db_schema_version(db, version):
Expand Down
10 changes: 10 additions & 0 deletions src/openprocurement/api/tests/bidder.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ def test_not_found(self):
{u'description': u'Not Found', u'location': u'url', u'name': u'document_id'}
])

self.app.authorization = ('Basic', ('invalid', ''))
response = self.app.put('/tenders/{}/bids/{}/documents/some_id'.format(
self.tender_id, self.bid_id), status=404, upload_files=[('file', 'name.doc', 'content2')])
self.assertEqual(response.status, '404 Not Found')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': u'Not Found', u'location': u'url', u'name': u'document_id'}
])

def test_create_tender_bidder_document(self):
response = self.app.post('/tenders/{}/bids/{}/documents'.format(
self.tender_id, self.bid_id), upload_files=[('file', 'name.doc', 'content')])
Expand Down
29 changes: 11 additions & 18 deletions src/openprocurement/api/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Deny,
Everyone,
)
from pyramid.httpexceptions import HTTPNotFound
from openprocurement.api.utils import error_handler


class Root(object):
Expand Down Expand Up @@ -39,9 +41,10 @@ def get_item(parent, key, request, root):
if not items:
request.errors.add('url', '{}_id'.format(key), 'Not Found')
request.errors.status = 404
return root
raise error_handler(request.errors)
else:
request.validated['{}s'.format(key)] = items
if key == 'document':
request.validated['{}s'.format(key)] = items
item = items[-1]
request.validated[key] = item
request.validated['id'] = request.matchdict['{}_id'.format(key)]
Expand All @@ -59,29 +62,23 @@ def factory(request):
if not tender:
request.errors.add('url', 'tender_id', 'Not Found')
request.errors.status = 404
return root
raise error_handler(request.errors)
tender.__parent__ = root
request.validated['tender'] = tender
request.validated['tender_status'] = tender.status
if request.method != 'GET':
request.validated['tender_src'] = tender.serialize('plain')
if request.matchdict.get('award_id'):
award = get_item(tender, 'award', request, root)
if award == root:
return root
elif request.matchdict.get('complaint_id'):
if request.matchdict.get('complaint_id'):
complaint = get_item(award, 'complaint', request, root)
if complaint == root:
return root
elif request.matchdict.get('document_id'):
if request.matchdict.get('document_id'):
return get_item(complaint, 'document', request, root)
else:
return complaint
elif request.matchdict.get('contract_id'):
contract = get_item(award, 'contract', request, root)
if contract == root:
return root
elif request.matchdict.get('document_id'):
if request.matchdict.get('document_id'):
return get_item(contract, 'document', request, root)
else:
return contract
Expand All @@ -91,17 +88,13 @@ def factory(request):
return award
elif request.matchdict.get('bid_id'):
bid = get_item(tender, 'bid', request, root)
if bid == root:
return root
elif request.matchdict.get('document_id'):
if request.matchdict.get('document_id'):
return get_item(bid, 'document', request, root)
else:
return bid
elif request.matchdict.get('complaint_id'):
complaint = get_item(tender, 'complaint', request, root)
if complaint == root:
return root
elif request.matchdict.get('document_id'):
if request.matchdict.get('document_id'):
return get_item(complaint, 'document', request, root)
else:
return complaint
Expand Down

0 comments on commit 2d8426d

Please sign in to comment.