def test_register_utilities_disabled_deadline(self): worker_config = { 'context': { 'context': 'config' }, 'datasource': { 'datasource': 'config' }, 'database': { 'database': 'config' }, 'deadline': { 'enabled': False, 'deadline_time': { 'hour': 20 } } } args = munch.Munch({}) args.auction_doc_id = '1' * 32 args.standalone = False register_utilities(worker_config, args) self.assertEqual(self.mocked_db.get_auction_document.call_count, 1) self.mocked_db.get_auction_document.assert_called_with( args.auction_doc_id) self.assertEqual(self.mocked_prepare_database.call_count, 2) self.mocked_prepare_database.assert_called_with( worker_config['database']) self.assertEqual(self.mocked_prepare_context.call_count, 1) self.mocked_prepare_context.assert_called_with( worker_config['context']) self.assertEqual(self.mocked_prepare_datasource.call_count, 1) resulted_datasource_config = deepcopy(worker_config['datasource']) resulted_datasource_config['auction_id'] = args.auction_doc_id self.mocked_prepare_datasource.assert_called_with( resulted_datasource_config) self.assertEqual(self.mocked_prepare_job_service.call_count, 1) self.mocked_prepare_job_service.assert_called_with() self.assertEqual(self.mocked_gsm.registerUtility.call_count, 4) self.assertEqual(self.mocked_gsm.queryUtility.call_count, 1) self.mocked_gsm.queryUtility.assert_called_with(IContext) resulted_worker_config = deepcopy(worker_config) resulted_worker_config['datasource'] = resulted_datasource_config resulted_worker_config['deadline'] = { 'enabled': False, 'deadline_time': {} } self.assertEqual(self.context['worker_defaults'], resulted_worker_config) self.assertEqual(self.context['server_actions'], self.bounded_semaphore)
def create_test_app(): worker_app = initialize_application() update_auctionPeriod(tender_data) logger = MagicMock() logger.name = 'some-logger' yaml_config = yaml.load(open(worker_defaults_file_path)) args = munch.Munch({ 'standalone': False, 'auction_doc_id': str(tender_data['data']['auctionID']) }) db = MagicMock() db.get.return_value = test_auction_document with patch('openprocurement.auction.texas.cli.prepare_database', db): register_utilities(yaml_config, args) app_auction = Auction( tender_id=tender_data['data']['auctionID'], worker_defaults=yaml.load(open(worker_defaults_file_path)), ) worker_app.config.update(app_auction.worker_defaults) worker_app.logger_name = logger.name worker_app._logger = logger worker_app.config['auction'] = app_auction worker_app.config['timezone'] = tz('Europe/Kiev') worker_app.config['SESSION_COOKIE_PATH'] = '/{}/{}'.format( 'auctions', tender_data['data']['auctionID']) worker_app.config['SESSION_COOKIE_NAME'] = 'auction_session' worker_app.oauth = MagicMock() worker_app.bids_form = BidsForm worker_app.form_handler = MagicMock() worker_app.form_handler.return_value = {'data': 'ok'} worker_app.remote_oauth = MagicMock() # Add context to app worker_app.gsm = getGlobalSiteManager() worker_app.context = worker_app.gsm.queryUtility(IContext) worker_app.context['bidders_data'] = tender_data['data']['bids'] worker_app.context['auction_document'] = {} worker_app.remote_oauth.authorized_response.side_effect = [ None, { u'access_token': u'aMALGpjnB1iyBwXJM6betfgT4usHqw', u'token_type': u'Bearer', u'expires_in': 86400, u'refresh_token': u'uoRKeSJl9UFjuMwOw6PikXuUVp7MjX', u'scope': u'email' } ] worker_app.remote_oauth.authorize.return_value = \ redirect('https://my.test.url') worker_app.logins_cache[(u'aMALGpjnB1iyBwXJM6betfgT4usHqw', '')] = { u'bidder_id': u'f7c8cd1d56624477af8dc3aa9c4b3ea3', u'expires': (datetime.now(tzlocal()) + timedelta(0, 600)).isoformat() } worker_app.auction_bidders = { u'f7c8cd1d56624477af8dc3aa9c4b3ea3': { 'clients': {}, 'channels': {} } } # Register views add_url_rules(worker_app) return worker_app.test_client()