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 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')
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 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')
def test_Auction(self): data = { "procurementMethodType": "sellout.english", "auctionPeriod": { "startDate": now.isoformat(), "endDate": (now + timedelta(days=5)).isoformat() }, "tenderAttempts": 3, "tenderingDuration": 'P4DT5H', "guarantee": { "amount": 30.54, "currency": "UAH" }, "minimalStep": { "amount": 60.54, "currency": "UAH" }, "value": { "amount": 1500.54, "currency": "UAH" }, "auctionParameters": { "type": "insider", } } lot = Lot() lot.status = 'draft' data['__parent__'] = lot auction = Auction() auction.import_data(data) auction.validate() data['minimalStep']['amount'] = data['value']['amount'] + 100 data['minimalStep']['valueAddedTaxIncluded'] = True data['value']['valueAddedTaxIncluded'] = False auction.import_data(data) with self.assertRaises(ModelValidationError) as ex: auction.validate() self.assertEqual( ex.exception.messages, {'minimalStep': ['value should be less than value of auction']}) data['minimalStep']['amount'] = data['value']['amount'] / 3 data['minimalStep']['valueAddedTaxIncluded'] = True data['value']['valueAddedTaxIncluded'] = False auction.import_data(data) with self.assertRaises(ModelValidationError) as ex: auction.validate() self.assertEqual( ex.exception.messages, { 'minimalStep': [ 'valueAddedTaxIncluded should be identical to valueAddedTaxIncluded of value of auction' ] }) data['minimalStep']['valueAddedTaxIncluded'] = data['value'][ 'valueAddedTaxIncluded'] data['minimalStep']['currency'] = 'USD' Auction.minimalStep.model_class.currency.choices = ['UAH', 'USD'] auction = Auction() auction.import_data(data) with self.assertRaises(ModelValidationError) as ex: auction.validate() self.assertEqual( ex.exception.messages, { 'minimalStep': [ 'currency should be identical to currency of value of auction' ] }) data['minimalStep']['currency'] = data['value']['currency'] data['auctionParameters'] = {'dutchSteps': 0, 'type': 'insider'} auction.import_data(data) with self.assertRaises(ModelValidationError) as ex: auction.validate() self.assertEqual( ex.exception.messages, { 'auctionParameters': { 'dutchSteps': [u'Int value should be greater than 1.'] } }) data['auctionParameters'] = {'dutchSteps': 100, 'type': 'insider'} auction.import_data(data) with self.assertRaises(ModelValidationError) as ex: auction.validate() self.assertEqual( ex.exception.messages, { 'auctionParameters': { 'dutchSteps': [u'Int value should be less than 99.'] } }) auction = Auction() data['auctionParameters'] = {'dutchSteps': 55, 'type': 'insider'} data['procurementMethodType'] = 'sellout.insider' auction.import_data(data) auction.validate() self.assertEqual(auction.auctionParameters.dutchSteps, data['auctionParameters']['dutchSteps']) data['relatedProcessID'] = 'relatedProcessID' data['auctionID'] = 'auctionID' auction.import_data(data) edit_serialization = auction.serialize('edit') self.assertNotIn('relatedProcessID', edit_serialization) self.assertNotIn('auctionID', edit_serialization) edit_serialization = auction.serialize('create') self.assertNotIn('relatedProcessID', edit_serialization) self.assertNotIn('auctionID', edit_serialization)