def test_main_without_worker_config(self):
        args = munch.Munch({
            'cmd': '',
            'auction_worker_config': 'path/to/config',
            'with_api_version': None,
            'auction_doc_id': '1' * 32,
            'debug': False
        })
        self.mocked_os.path.isfile.return_value = False
        self.mocked_parser_obj.parse_args.return_value = args

        with self.assertRaises(SystemExit):
            main()

        self.assertEqual(self.mocked_os.path.isfile.call_count, 1)

        self.assertEqual(self.mocked_yaml.load.call_count, 0)

        self.assertEqual(self.mocked_open.call_count, 0)

        self.assertEqual(self.mocked_logging.config.dictConfig.call_count, 0)

        self.assertEqual(self.mocked_register_utilities.call_count, 0)

        self.assertEqual(self.mocked_auction_class.call_count, 0)
    def test_cmd_check(self):
        args = munch.Munch({
            'cmd': 'check',
            'auction_worker_config': 'path/to/config',
            'with_api_version': 'another api version',
            'auction_doc_id': '1' * 32,
            'debug': False
        })
        self.mocked_parser_obj.parse_args.return_value = args

        with self.assertRaises(SystemExit):
            main()
    def test_cmd_cancel(self):
        args = munch.Munch({
            'cmd': 'cancel',
            'auction_worker_config': 'path/to/config',
            'with_api_version': 'another api version',
            'auction_doc_id': '1' * 32,
            'debug': False
        })
        self.mocked_parser_obj.parse_args.return_value = args

        main()

        self.assertEqual(self.auction_instance.cancel_auction.call_count, 1)
        self.auction_instance.cancel_auction.assert_called_with()
    def test_cmd_post_auction_protocol(self):
        args = munch.Munch({
            'cmd': 'post_auction_protocol',
            'auction_worker_config': 'path/to/config',
            'with_api_version': 'another api version',
            'auction_doc_id': '1' * 32,
            'debug': False,
            'doc_id': 'some document id'
        })
        self.mocked_parser_obj.parse_args.return_value = args

        main()

        self.assertEqual(
            self.auction_instance.post_auction_protocol.call_count, 1)
        self.auction_instance.post_auction_protocol.assert_called_with(
            args.doc_id)
    def test_without_cleanup(self):
        resulted_yaml = deepcopy(self.yaml_output)

        args = munch.Munch({
            'cmd': '',
            'auction_worker_config': 'path/to/config',
            'with_api_version': 'another api version',
            'auction_doc_id': '1' * 32,
            'debug': False
        })
        self.mocked_parser_obj.parse_args.return_value = args

        main()

        self.assertEqual(self.mocked_os.path.isfile.call_count, 1)
        self.mocked_os.path.isfile.assert_called_with(
            args.auction_worker_config)

        self.assertEqual(self.mocked_yaml.load.call_count, 1)
        self.mocked_yaml.load.assert_called_with(self.open_result)

        self.assertEqual(self.mocked_open.call_count, 1)
        self.mocked_open.assert_called_with(args.auction_worker_config)

        self.assertEqual(self.mocked_logging.config.dictConfig.call_count, 1)
        resulted_yaml['resource_api_version'] = args.with_api_version
        resulted_yaml['handlers']['journal'][
            'TENDERS_API_VERSION'] = resulted_yaml['resource_api_version']
        resulted_yaml['handlers']['journal'][
            'TENDERS_API_URL'] = resulted_yaml['resource_api_server']
        resulted_yaml['handlers']['journal']['TENDER_ID'] = args.auction_doc_id
        self.mocked_logging.config.dictConfig.assert_called_with(resulted_yaml)

        self.assertEqual(self.mocked_register_utilities.call_count, 1)
        self.mocked_register_utilities.assert_called_with(resulted_yaml, args)

        self.assertEqual(self.mocked_auction_class.call_count, 1)
        self.mocked_auction_class.assert_called_with(
            args.auction_doc_id,
            worker_defaults=resulted_yaml,
            debug=args.debug)
    def test_cmd_run(self):
        args = munch.Munch({
            'cmd': 'run',
            'auction_worker_config': 'path/to/config',
            'with_api_version': 'another api version',
            'auction_doc_id': '1' * 32,
            'debug': False
        })
        self.mocked_parser_obj.parse_args.return_value = args

        main()
        self.assertEqual(self.mocked_SCHEDULER.start.call_count, 1)
        self.mocked_SCHEDULER.start.assert_called_with()

        self.assertEqual(self.mocked_SCHEDULER.shutdown.call_count, 1)
        self.mocked_SCHEDULER.shutdown.assert_called_with()

        self.assertEqual(self.auction_instance.schedule_auction.call_count, 1)
        self.auction_instance.schedule_auction.assert_called_with()

        self.assertEqual(self.auction_instance.wait_to_end.call_count, 1)
        self.auction_instance.wait_to_end.assert_called_with()