def _set_rectificationPeriod(self, request): data = dict() data['startDate'] = get_now() data['endDate'] = calculate_business_date(data['startDate'], RECTIFICATION_PERIOD_DURATION, None) request.context.rectificationPeriod = type(request.context).rectificationPeriod.model_class(data)
def rectificationPeriod_auction_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) data = deepcopy(self.initial_auctions_data) lot = self.create_resource() # Change rectification period in db fromdb = self.db.get(lot['id']) fromdb = Lot(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, lot['id']) response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) response = self.app.get('/{}/auctions'.format(self.resource_id)) auctions = sorted(response.json['data'], key=lambda a: a['tenderAttempts']) english = auctions[0] response = self.app.patch_json('/{}/auctions/{}'.format( lot['id'], english['id']), headers=self.access_header, params={'data': data['english']}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change auctions after rectification period')
def rectificationPeriod_item_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) lot = self.create_resource() response = self.app.post_json('/{}/items'.format(lot['id']), headers=self.access_header, params={'data': self.initial_item_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') item_id = response.json["data"]['id'] self.assertIn(item_id, response.headers['Location']) self.assertEqual(self.initial_item_data['description'], response.json["data"]["description"]) self.assertEqual(self.initial_item_data['quantity'], response.json["data"]["quantity"]) self.assertEqual(self.initial_item_data['address'], response.json["data"]["address"]) item_id = response.json['data']['id'] response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) # Change rectification period in db fromdb = self.db.get(lot['id']) fromdb = Lot(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, lot['id']) response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) response = self.app.post_json('/{}/items'.format(lot['id']), headers=self.access_header, params={'data': self.initial_item_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change items after rectification period') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change items after rectification period') response = self.app.patch_json('/{}/items/{}'.format(lot['id'], item_id), headers=self.access_header, params={'data': self.initial_item_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change items after rectification period')
def validate_auctionPeriod(self, data, period): lot = get_lot(data['__parent__']) if data['tenderAttempts'] == 1 and lot.rectificationPeriod: min_auction_start_date = calculate_business_date( start=lot.rectificationPeriod.endDate, delta=DAYS_AFTER_RECTIFICATION_PERIOD, context=lot, working_days=True ) if min_auction_start_date > period['startDate']: raise ValidationError( 'startDate of auctionPeriod must be at least ' 'in {} days after endDate of rectificationPeriod'.format(DAYS_AFTER_RECTIFICATION_PERIOD.days) )
def validate_verification_status(request, error_handler): if request.validated['data'].get( 'status' ) == 'verification' and request.context.status == 'composing': # Decision validation if not any(decision.decisionOf == 'lot' for decision in request.context.decisions): raise_operation_error( request, error_handler, 'Can\'t switch to verification while lot decisions not available.' ) # Auction validation lot = request.validated['lot'] auctions = sorted(lot.auctions, key=lambda a: a.tenderAttempts) english = auctions[0] auction_error_message = get_auction_validation_result(lot) # Raise errors from first and second auction if auction_error_message['description']: request.errors.add(**auction_error_message) request.errors.status = 422 raise error_handler(request) duration = DAYS_AFTER_RECTIFICATION_PERIOD + RECTIFICATION_PERIOD_DURATION min_auction_start_date = calculate_business_date(start=get_now(), delta=duration, context=lot, working_days=True) auction_period = english.auctionPeriod if auction_period and min_auction_start_date > auction_period.startDate: request.errors.add( 'body', 'mode', 'startDate of auctionPeriod must be ' 'at least in {} days after today'.format(duration.days)) request.errors.status = 422 raise error_handler(request) if not lot.relatedProcesses: request.errors.add( 'body', 'mode', 'You can set verification status ' 'only when lot have at least one relatedProcess') request.errors.status = 422 raise error_handler(request) if request.errors: raise error_handler(request)
def rectificationPeriod_document_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) lot = self.create_resource() response = self.app.post_json('/{}/documents'.format(self.resource_id), headers=self.access_header, params={'data': self.initial_document_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') doc_id = response.json["data"]['id'] response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) # Change rectification period in db fromdb = self.db.get(lot['id']) fromdb = Lot(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, lot['id']) response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) response = self.app.post_json('/{}/documents'.format(lot['id']), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual( response.json['errors'][0]['description'], 'You can add only document with cancellationDetails after rectification period' ) response = self.app.patch_json('/{}/documents/{}'.format( lot['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period') response = self.app.put_json('/{}/documents/{}'.format(lot['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period') test_document_data = { # 'url': self.generate_docservice_url(), 'title': u'укр.doc', 'hash': 'md5:' + '0' * 32, 'format': 'application/msword', 'documentType': 'cancellationDetails' } test_document_data['url'] = self.generate_docservice_url() response = self.app.post_json('/{}/documents'.format(lot['id']), headers=self.access_header, params={'data': test_document_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') doc_id = response.json["data"]['id'] response = self.app.patch_json('/{}/documents/{}'.format( lot['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period') response = self.app.put_json('/{}/documents/{}'.format(lot['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period')
test_item_data, ) from openregistry.lots.loki.constants import (DAYS_AFTER_RECTIFICATION_PERIOD, RECTIFICATION_PERIOD_DURATION) now = get_now() test_loki_document_data = deepcopy(test_document_data) test_loki_document_data['documentType'] = 'notice' test_loki_document_data['documentOf'] = 'lot' auction_common = { 'auctionPeriod': { 'startDate': (calculate_business_date(start=now, delta=DAYS_AFTER_RECTIFICATION_PERIOD + RECTIFICATION_PERIOD_DURATION, context=None, working_days=True) + timedelta(minutes=5)).isoformat(), }, 'value': { 'amount': 3000.87, 'currency': 'UAH', 'valueAddedTaxIncluded': True }, 'minimalStep': { 'amount': 300.87, 'currency': 'UAH', 'valueAddedTaxIncluded': True }, 'guarantee': {
def test_docs_tutorial_with_concierge(self): ### Switch to invalid workflow ### lot, lot_id, owner_token = self.from_initial_to_decisions() self.app.authorization = ('Basic', ('concierge', '')) with open('docs/source/tutorial/switch-lot-to-invalid.http', 'w') as self.app.file_obj: response = self.app.patch_json( '/{}'.format(lot_id), params={'data': { "status": 'invalid' }}) self.assertEqual(response.status, '200 OK') ### Switch to deleted workflow ### self.app.authorization = ('Basic', ('broker', '')) lot, lot_id, owner_token = self.from_initial_to_decisions() access_header = {'X-Access-Token': str(owner_token)} # switch lot to 'pending' with open('docs/source/tutorial/switch-lot-to-pending.http', 'w') as self.app.file_obj: response = self.app.patch_json( '/{}?acc_token={}'.format(lot_id, owner_token), {'data': { "status": 'pending' }}) self.assertEqual(response.status, '200 OK') self.app.authorization = ('Basic', ('broker', '')) add_cancellationDetails_document(self, lot, access_header) # switch lot to 'deleted' with open('docs/source/tutorial/lot-delete-3pc.http', 'w') as self.app.file_obj: response = self.app.patch_json( '/{}?acc_token={}'.format(lot_id, owner_token), {'data': { "status": 'pending.deleted' }}) self.assertEqual(response.status, '200 OK') ### Switch to pending.dissolution workflow ### self.app.authorization = ('Basic', ('broker', '')) lot, lot_id, owner_token = self.from_initial_to_decisions() access_header = {'X-Access-Token': str(owner_token)} # switch lot to 'pending' response = self.app.patch_json( '/{}?acc_token={}'.format(lot_id, owner_token), {'data': { "status": 'pending' }}) self.assertEqual(response.status, '200 OK') rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) # change rectification period in db fromdb = self.db.get(lot['id']) fromdb = self.lot_model(fromdb) fromdb.status = 'pending' fromdb.decisions = [{ 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' }, { 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' }] fromdb.title = 'title' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) lot = fromdb self.assertEqual(fromdb.id, lot['id']) # switch lot to 'active.salable' response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) self.app.authorization = ('Basic', ('chronograph', '')) response = self.app.patch_json('/{}'.format(lot['id']), params={'data': { 'title': ' PATCHED' }}) self.assertNotEqual(response.json['data']['title'], 'PATCHED') self.assertEqual(lot['title'], response.json['data']['title']) self.assertEqual(response.json['data']['status'], 'active.salable') with open( 'docs/source/tutorial/concierge-patched-lot-to-active.salable.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') # switch lot to 'active.auction' self.app.authorization = ('Basic', ('concierge', '')) with open('docs/source/tutorial/switch-lot-active.auction.http', 'w') as self.app.file_obj: response = self.app.patch_json( '/{}'.format(lot_id), {'data': { "status": 'active.auction' }}) self.assertEqual(response.status, '200 OK') self.app.authorization = ('Basic', ('convoy', '')) with open('docs/source/tutorial/switch-lot-active.contracting.http', 'w') as self.app.file_obj: response = self.app.patch_json( '/{}'.format(lot_id), {'data': { "status": 'active.contracting' }}) self.assertEqual(response.status, '200 OK') # switch to 'pending.dissolution' with open('docs/source/tutorial/patch-lot-to-pending.dissolution.http', 'w') as self.app.file_obj: response = self.app.patch_json( '/{}'.format(lot_id), {'data': { "status": 'pending.dissolution' }}) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['status'], 'pending.dissolution') self.app.authorization = ('Basic', ('concierge', '')) # Switch to 'dissolved' with open('docs/source/tutorial/patch-lot-to-dissolved.http', 'w') as self.app.file_obj: response = self.app.patch_json('/{}'.format(lot_id), {'data': { "status": 'dissolved' }}) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['status'], 'dissolved') ### Switch to sold workflow ### self.app.authorization = ('Basic', ('broker', '')) lot, lot_id, owner_token = self.from_initial_to_decisions() # switch lot to 'pending' response = self.app.patch_json( '/{}?acc_token={}'.format(lot_id, owner_token), {'data': { "status": 'pending' }}) self.assertEqual(response.status, '200 OK') rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) # change rectification period in db fromdb = self.db.get(lot['id']) fromdb = self.lot_model(fromdb) fromdb.status = 'pending' fromdb.decisions = [{ 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' }, { 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' }] fromdb.title = 'title' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) lot = fromdb self.assertEqual(fromdb.id, lot['id']) # switch lot to 'active.salable' response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) self.app.authorization = ('Basic', ('chronograph', '')) response = self.app.patch_json('/{}'.format(lot['id']), params={'data': { 'title': ' PATCHED' }}) self.assertNotEqual(response.json['data']['title'], 'PATCHED') self.assertEqual(lot['title'], response.json['data']['title']) self.assertEqual(response.json['data']['status'], 'active.salable') response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') # switch lot to 'active.auction' self.app.authorization = ('Basic', ('concierge', '')) response = self.app.patch_json('/{}'.format(lot_id), {'data': { "status": 'active.auction' }}) self.assertEqual(response.status, '200 OK') # switch to 'active.contracting' self.app.authorization = ('Basic', ('convoy', '')) response = self.app.patch_json( '/{}'.format(lot_id), {'data': { "status": 'active.contracting' }}) self.assertEqual(response.status, '200 OK') # switch to 'pending.sold' with open('docs/source/tutorial/switch-lot-to-pending.sold.http', 'w') as self.app.file_obj: response = self.app.patch_json( '/{}'.format(lot_id), {'data': { "status": 'pending.sold' }}) self.assertEqual(response.status, '200 OK') # switch to 'sold' with open('docs/source/tutorial/switch-lot-to-sold.http', 'w') as self.app.file_obj: self.app.authorization = ('Basic', ('concierge', '')) response = self.app.patch_json('/{}'.format(lot_id), {'data': { "status": 'sold' }}) self.assertEqual(response.status, '200 OK')
def rectificationPeriod_document_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) lot = self.create_resource() response = self.app.get('/{}/auctions'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.content_type, 'application/json') auction_id = response.json["data"][0]['id'] response = self.app.post_json('/{}/auctions/{}/documents'.format( lot['id'], auction_id), headers=self.access_header, params={'data': self.initial_document_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') doc_id = response.json["data"]['id'] response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) # Change rectification period in db fromdb = self.db.get(lot['id']) fromdb = Lot(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, lot['id']) response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) response = self.app.post_json('/{}/auctions/{}/documents'.format( lot['id'], auction_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual( response.json['errors'][0]['description'], 'You can\'t add documents to auction after rectification period') response = self.app.patch_json('/{}/auctions/{}/documents/{}'.format( lot['id'], auction_id, doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period') response = self.app.put_json('/{}/auctions/{}/documents/{}'.format( lot['id'], auction_id, doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period')
def test_docs_tutorial_with_concierge(self): ### Switch to invalid workflow ### lot, lot_id, owner_token = self.from_initial_to_decisions() self.app.authorization = ('Basic', ('concierge', '')) response = self.app.patch_json('/{}'.format(lot_id), params={'data': {"status": 'invalid'}}) self.assertEqual(response.status, '200 OK') with open('docs/source/tutorial/lot-after-concierge-switch-to-invalid.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') ### Switch to deleted workflow ### self.app.authorization = ('Basic', ('broker', '')) lot, lot_id, owner_token = self.from_initial_to_decisions() access_header = {'X-Access-Token': str(owner_token)} # switch lot to 'pending' asset_items = [test_loki_item_data] lot = self.app.get('/{}'.format(lot_id)).json['data'] related_process_id = lot['relatedProcesses'][0]['id'] response = self.app.patch_json('/{}/related_processes/{}'.format(lot_id, related_process_id), {'data': {'identifier': 'UA-AR-P-2018-08-17-000002-1'}}) self.assertEqual(response.status, '200 OK') concierge_patch = { 'status': 'pending', 'items': asset_items, 'title': 'Нежитлове приміщення', 'description': 'Нежитлове приміщення для збереження насіння', 'lotHolder': {'name': 'Власник лоту', 'identifier': {'scheme': 'AE-ADCD', 'id': '11111-4'}}, 'lotCustodian': { 'name': 'Зберігач лоту', 'address': {'countryName': 'Україна'}, 'identifier': {'scheme': 'AE-ADCD', 'id': '11111-4'}, 'contactPoint': {'name': 'Сергій', 'email': '*****@*****.**'} }, 'decisions': [ lot['decisions'][0], {'decisionID': '11111-4-5', 'relatedItem': uuid4().hex, 'decisionOf': 'asset'} ] } response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token), {'data': concierge_patch}) self.assertEqual(response.status, '200 OK') with open('docs/source/tutorial/lot-after-concierge-patch-pending-2.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') self.app.authorization = ('Basic', ('broker', '')) add_cancellationDetails_document(self, lot, access_header) # switch lot to 'deleted' response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token), {'data': {"status": 'pending.deleted'}}) self.assertEqual(response.status, '200 OK') self.app.authorization = ('Basic', ('concierge', '')) response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token), {'data': {"status": 'deleted'}}) self.assertEqual(response.status, '200 OK') self.app.authorization = ('Basic', ('broker', '')) with open('docs/source/tutorial/lot-delete-3pc.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') ### Switch to pending.dissolution workflow ### self.app.authorization = ('Basic', ('broker', '')) lot, lot_id, owner_token = self.from_initial_to_decisions() access_header = {'X-Access-Token': str(owner_token)} # switch lot to 'pending' asset_items = [test_loki_item_data] lot = self.app.get('/{}'.format(lot_id)).json['data'] related_process_id = lot['relatedProcesses'][0]['id'] response = self.app.patch_json('/{}/related_processes/{}'.format(lot_id, related_process_id), {'data': {'identifier': 'UA-AR-P-2018-08-17-000002-1'}}) self.assertEqual(response.status, '200 OK') concierge_patch = { 'status': 'pending', 'items': asset_items, 'title': 'Нежитлове приміщення', 'description': 'Нежитлове приміщення для збереження насіння', 'lotHolder': {'name': 'Власник лоту', 'identifier': {'scheme': 'AE-ADCD', 'id': '11111-4'}}, 'lotCustodian': { 'name': 'Зберігач лоту', 'address': {'countryName': 'Україна'}, 'identifier': {'scheme': 'AE-ADCD', 'id': '11111-4'}, 'contactPoint': {'name': 'Сергій', 'email': '*****@*****.**'} }, 'decisions': [ lot['decisions'][0], {'decisionID': '11111-4-5', 'relatedItem': uuid4().hex, 'decisionOf': 'asset'} ] } response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token), {'data': concierge_patch}) self.assertEqual(response.status, '200 OK') rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date(rectificationPeriod.startDate, timedelta(1), None) # change rectification period in db fromdb = self.db.get(lot['id']) fromdb = self.lot_model(fromdb) fromdb.status = 'pending' fromdb.decisions = [ { 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' }, { 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' } ] fromdb.title = 'title' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) lot = fromdb self.assertEqual(fromdb.id, lot['id']) # switch lot to 'active.salable' response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) self.app.authorization = ('Basic', ('chronograph', '')) response = self.app.patch_json('/{}'.format(lot['id']), params={'data': {'title': ' PATCHED'}}) self.assertNotEqual(response.json['data']['title'], 'PATCHED') self.assertEqual(lot['title'], response.json['data']['title']) self.assertEqual(response.json['data']['status'], 'active.salable') with open('docs/source/tutorial/concierge-patched-lot-to-active.salable.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') # switch lot to 'active.auction' self.app.authorization = ('Basic', ('concierge', '')) with open('docs/source/tutorial/switch-lot-active.auction.http', 'w') as self.app.file_obj: response = self.app.patch_json('/{}'.format(lot_id), {'data': {"status": 'active.auction'}}) self.assertEqual(response.status, '200 OK') self.app.authorization = ('Basic', ('convoy', '')) auction_id = lot['auctions'][0]['id'] response = self.app.patch_json('/{}/auctions/{}'.format(lot_id, auction_id), {'data': {"status": 'complete'}}) self.assertEqual(response.status, '200 OK') with open('docs/source/tutorial/lot-after-convoy-patch-auction-complete.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') fromdb = self.db.get(lot['id']) fromdb = self.lot_model(fromdb) fromdb.status = 'active.auction' fromdb.auctions[0].status = 'active' fromdb.store(self.db) # switch to 'pending.dissolution' response = self.app.patch_json('/{}/auctions/{}'.format(lot_id, auction_id), {'data': {"status": 'cancelled'}}) self.assertEqual(response.status, '200 OK') response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.json['data']['status'], 'pending.dissolution') with open('docs/source/tutorial/lot-after-convoy-patch-auction-cancelled.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') self.app.authorization = ('Basic', ('concierge', '')) # Switch to 'dissolved' response = self.app.patch_json('/{}'.format(lot_id), {'data': {"status": 'dissolved'}}) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['status'], 'dissolved') with open('docs/source/tutorial/lot-after-concierge-patch-lot-dissolved.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') ### Switch to sold workflow ### self.app.authorization = ('Basic', ('broker', '')) lot, lot_id, owner_token = self.from_initial_to_decisions() # switch lot to 'pending' response = self.app.patch_json('/{}?acc_token={}'.format(lot_id, owner_token), {'data': {"status": 'pending', 'items': asset_items}}) self.assertEqual(response.status, '200 OK') rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date(rectificationPeriod.startDate, timedelta(1), None) # change rectification period in db fromdb = self.db.get(lot['id']) fromdb = self.lot_model(fromdb) fromdb.status = 'pending' fromdb.decisions = [ { 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' }, { 'decisionDate': get_now().isoformat(), 'decisionID': 'decisionAssetID' } ] fromdb.title = 'title' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) lot = fromdb self.assertEqual(fromdb.id, lot['id']) # switch lot to 'active.salable' response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) self.app.authorization = ('Basic', ('chronograph', '')) response = self.app.patch_json('/{}'.format(lot['id']), params={'data': {'title': ' PATCHED'}}) self.assertNotEqual(response.json['data']['title'], 'PATCHED') self.assertEqual(lot['title'], response.json['data']['title']) self.assertEqual(response.json['data']['status'], 'active.salable') response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') # switch lot to 'active.auction' self.app.authorization = ('Basic', ('concierge', '')) response = self.app.patch_json('/{}'.format(lot_id), {'data': {"status": 'active.auction'}}) self.assertEqual(response.status, '200 OK') # switch to 'active.contracting' self.app.authorization = ('Basic', ('convoy', '')) auction_id = lot['auctions'][0]['id'] response = self.app.patch_json('/{}/auctions/{}'.format(lot_id, auction_id), {'data': {"status": 'complete'}}) self.assertEqual(response.status, '200 OK') # switch to 'pending.sold' self.app.authorization = ('Basic', ('caravan', '')) contract_id = lot['contracts'][0]['id'] response = self.app.patch_json('/{}/contracts/{}'.format(lot_id, contract_id), {'data': {"status": 'complete'}}) self.assertEqual(response.status, '200 OK') with open('docs/source/tutorial/lot-after-caravan-patch-contract-complete.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK') # switch to 'sold' self.app.authorization = ('Basic', ('concierge', '')) response = self.app.patch_json('/{}'.format(lot_id), {'data': {"status": 'sold'}}) self.assertEqual(response.status, '200 OK') with open('docs/source/tutorial/lot-after-concierge-patch-lot-sold.http', 'w') as self.app.file_obj: response = self.app.get('/{}'.format(lot_id)) self.assertEqual(response.status, '200 OK')
def rectificationPeriod_decision_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) self.create_resource() response = self.app.get('/{}'.format(self.resource_id)) lot = response.json['data'] self.set_status('draft') add_auctions(self, lot, access_header=self.access_header) self.set_status('pending') add_lot_decision(self, lot['id'], self.access_header) response = self.app.post_json('/{}/decisions'.format(lot['id']), headers=self.access_header, params={'data': self.initial_decision_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') decision_id = response.json["data"]['id'] self.assertIn(decision_id, response.headers['Location']) self.assertEqual(self.initial_decision_data['decisionID'], response.json["data"]["decisionID"]) self.assertEqual(self.initial_decision_data['decisionDate'], response.json["data"]["decisionDate"]) self.assertEqual('lot', response.json["data"]["decisionOf"]) decision_id = response.json['data']['id'] response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) # Change rectification period in db fromdb = self.db.get(lot['id']) fromdb = Lot(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, lot['id']) response = self.app.get('/{}'.format(lot['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], lot['id']) response = self.app.post_json('/{}/decisions'.format(lot['id']), headers=self.access_header, params={'data': self.initial_decision_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual( response.json['errors'][0]['description'], 'You can\'t change or add decisions after rectification period') response = self.app.patch_json('/{}/decisions/{}'.format( lot['id'], decision_id), headers=self.access_header, params={'data': self.initial_decision_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual( response.json['errors'][0]['description'], 'You can\'t change or add decisions after rectification period')