Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Item test stub * Stub view for Item * Add role `edit_auction_items` * Add validator for the POST request * Finish item's POST view * GET view for the dgfItem * View for collection_get of dgfItem * PATCH view for dgfItem + validator * Remove pdb * Remove unused import * Test for validator * Connect validator * Use present auth role `edit_auction` * Remove unused import * Rename validator
- Loading branch information
Showing
4 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from openprocurement.auctions.dgf.tests.base import ( | ||
BaseAuctionWebTest, | ||
test_bids, | ||
) | ||
from openprocurement.auctions.core.tests.items import ( | ||
DgfItemsResourceTestMixin, | ||
) | ||
|
||
|
||
class DgfItemsResourceTest(BaseAuctionWebTest, DgfItemsResourceTestMixin): | ||
initial_status = 'active.tendering' | ||
initial_bids = test_bids | ||
|
||
|
||
def suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(unittest.makeSuite(DgfItemsResourceTest)) | ||
|
||
return suite | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main(defaultTest='suite') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from openprocurement.auctions.dgf.tests.base import ( | ||
BaseAuctionWebTest, | ||
test_bids, | ||
) | ||
from openprocurement.auctions.core.tests.validation import ( | ||
RectificationPeriodValidationTestMixin, | ||
) | ||
|
||
|
||
class DgfItemsRectificationPeriodValidationResourceTest( | ||
BaseAuctionWebTest, RectificationPeriodValidationTestMixin | ||
): | ||
initial_status = 'active.tendering' | ||
initial_bids = test_bids | ||
|
||
|
||
def suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(unittest.makeSuite(DgfItemsRectificationPeriodValidationResourceTest)) | ||
|
||
return suite | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main(defaultTest='suite') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# -*- coding: utf-8 -*- | ||
from openprocurement.auctions.core.utils import ( | ||
apply_patch, | ||
context_unpack, | ||
json_view, | ||
opresource, | ||
save_auction, | ||
update_file_content_type, | ||
) | ||
from openprocurement.auctions.core.validation import ( | ||
validate_item_rectification_period, | ||
) | ||
from openprocurement.auctions.core.views.mixins import AuctionLotResource | ||
from openprocurement.auctions.core.endpoints import ENDPOINTS | ||
from openprocurement.auctions.dgf.validation import ( | ||
validate_item_data, | ||
validate_patch_item_data, | ||
) | ||
|
||
|
||
@opresource( | ||
name='dgfOtherAssets:Auction Items', | ||
collection_path=ENDPOINTS['items'], | ||
path=ENDPOINTS['item'], | ||
auctionsprocurementMethodType="dgfOtherAssets", | ||
description="Auction items") | ||
class AuctionLotResource(AuctionLotResource): | ||
|
||
@json_view( | ||
content_type="application/json", | ||
permission='edit_auction', | ||
validators=(validate_item_data)) | ||
def collection_post(self): | ||
item = self.request.validated['item'] | ||
self.context.items.append(item) | ||
if save_auction(self.request): | ||
self.LOGGER.info( | ||
'Created lot item {}'.format(item.id), | ||
extra=context_unpack( | ||
self.request, | ||
{'MESSAGE_ID': 'auction_item_create'}, | ||
{'item_id': item.id} | ||
) | ||
) | ||
self.request.response.status = 201 | ||
item_route = self.request.matched_route.name.replace("collection_", "") | ||
self.request.response.headers['Location'] = self.request.current_route_url( | ||
_route_name=item_route, | ||
item_id=item.id, | ||
_query={} | ||
) | ||
return {'data': item.serialize("view")} | ||
|
||
@json_view( | ||
content_type="application/json", | ||
permission='view_auction') | ||
def get(self): | ||
item = self.context | ||
return {'data': item.serialize('view')} | ||
|
||
@json_view( | ||
content_type="application/json", | ||
permission='view_auction') | ||
def collection_get(self): | ||
collection_data = [i.serialize("view") for i in self.context.items] | ||
return {'data': collection_data} | ||
|
||
@json_view( | ||
content_type="application/json", | ||
permission='edit_auction', | ||
validators=(validate_patch_item_data, validate_item_rectification_period)) | ||
def patch(self): | ||
if apply_patch(self.request, src=self.request.context.serialize()): | ||
update_file_content_type(self.request) | ||
self.LOGGER.info( | ||
'Updated lot item {}'.format(self.request.context.id), | ||
extra=context_unpack(self.request, {'MESSAGE_ID': 'lot_item_patch'}) | ||
) | ||
return {'data': self.request.context.serialize("view")} |