def __init__(self, config_filename="conf/config.txt"): ''' Create a Runner using the configuration file denoted by config_filename. :param config_filename: :return: None ''' try: Config.__set_config_filename__(config_filename) config = Config() except FileNotFoundError as err: print(err) raise err logging_configuration_file = config.prop(Config.key_logging_configuration_file, "conf/logging.conf") # logging.config.fileConfig raises "KeyError: 'formatters'" if the configuration file does not exist. # A FileNotFoundError in this case is less confusing. if not os.path.isfile(logging_configuration_file): # It seems there is no default logging configuration to the console in Python? # In that case we'll call it a day. raise FileNotFoundError("Logging configuration file not found: " + logging_configuration_file) logging.config.fileConfig(logging_configuration_file) self.logger = logging.getLogger(__name__) self.pid = os.getpid() self.sources = None self.exceptions = [] self.logger.info("Started %s with pid %d" % (__file__, self.pid)) self.logger.info("Configured %s from '%s'" % (self.__class__.__name__, config_filename)) self.logger.info("Configured logging from '%s'" % logging_configuration_file) self.__inject_dependencies__(config)
def test_inject_dependencies(self): Config.__set_config_filename__("test-files/config.txt") Config().__set_prop__(Config.key_des_processor_listeners, "des.processor_listener.SitemapWriter, des.processor.ProcessorListener") runner = DesRunner() self.assertEqual(2, len(des.processor.processor_listeners))
def test07_process_source(self): # connection and readable resourcesync, write sitemap to file try: shutil.rmtree("rs/destination/d6/sitemaps") except: pass Config.__set_config_filename__("test-files/config.txt") Config().__drop__() DestinationMap.__set_map_filename__("test-files/desmap.txt") DestinationMap().__drop__() des.reporter.reset_instance() Config().__set_prop__(Config.key_use_netloc, "False") Config().__set_prop__(Config.key_audit_only, "False") DestinationMap().__set_destination__( "http://localhost:8000/rs/source/s6", "rs/destination/d6") des.processor.processor_listeners.append(SitemapWriter()) base_uri = "http://localhost:8000/rs/source/s6/" sdproc = Sodesproc(base_uri) sdproc.read_source() self.assertEqual(200, sdproc.source_status) self.assertEqual(Status.document, sdproc.status) self.assertTrue( os.path.isfile( "rs/destination/d6/sitemaps/.well-known/resourcesync"))
def test02_new(self): Config.__set_config_filename__("test-files/config.txt") config = Config() self.assertEqual("test-files/config.txt", config._config_filename) self.assertEqual("test-files/config.txt", Config.__get_config_filename__()) self.assertEqual("logging.conf", config.prop(Config.key_logging_configuration_file)) self.assertEqual("test-files/desmap.txt", config.prop(Config.key_location_mapper_destination_file))
def test_inject_dependencies(self): Config.__set_config_filename__("test-files/config.txt") Config().__set_prop__( Config.key_des_processor_listeners, "des.processor_listener.SitemapWriter, des.processor.ProcessorListener" ) runner = DesRunner() self.assertEqual(2, len(des.processor.processor_listeners))
def test04_list_prop(self): Config.__set_config_filename__("test-files/config.txt") config = Config() list = config.list_prop("test_list") self.assertEqual(3, len(list)) self.assertEqual("foo.bar", list[0]) self.assertEqual("bar.foo", list[1]) self.assertEqual("foo.bar.baz", list[2])
def test02_new(self): Config.__set_config_filename__("test-files/config.txt") config = Config() self.assertEqual("test-files/config.txt", config._config_filename) self.assertEqual("test-files/config.txt", Config.__get_config_filename__()) self.assertEqual("logging.conf", config.prop(Config.key_logging_configuration_file)) self.assertEqual( "test-files/desmap.txt", config.prop(Config.key_location_mapper_destination_file))
def test03_boolean_prop(self): Config.__set_config_filename__("test-files/config.txt") config = Config() self.assertFalse(config.boolean_prop(Config.key_use_netloc)) config.__set_prop__(Config.key_use_netloc, str(True)) self.assertTrue(config.boolean_prop(Config.key_use_netloc)) config.__set_prop__(Config.key_use_netloc, str(False)) self.assertFalse(config.boolean_prop(Config.key_use_netloc)) self.assertTrue(config.boolean_prop("no_key", True)) self.assertFalse(config.boolean_prop("no_key", False))
def test04__drop__(self): Config.__set_config_filename__("test-files/config.txt") config1 = Config() self.assertIsNotNone(config1) self.assertIsNone(config1.prop("this_is")) config1.__drop__() self.assertIsNone(Config.__instance__) Config.__set_config_filename__("test-files/alt-config.txt") config2 = Config() self.assertIsNotNone(config2) self.assertNotEqual(config1, config2) self.assertEqual("a_test", config2.prop("this_is")) config2.__drop__()
def setUpModule(): global server server_address = ('', 8000) handler_class = SimpleHTTPRequestHandler server = HTTPServer(server_address, handler_class) t = threading.Thread(target=server.serve_forever) t.daemon = True logger.debug("Starting server at http://localhost:8000/") t.start() proc.processor_listeners.append(SitemapWriter()) Config.__set_config_filename__("test-files/config.txt") Config().__drop__() DestinationMap.__set_map_filename__("test-files/desmap.txt") DestinationMap().__drop__() DestinationMap().__set_destination__("http://localhost:8000/rs/source/discover/", "rs/destination/discover")
def setUpModule(): global server server_address = ('', 8000) handler_class = SimpleHTTPRequestHandler server = HTTPServer(server_address, handler_class) t = threading.Thread(target=server.serve_forever) t.daemon = True logger.debug("Starting server at http://localhost:8000/") t.start() proc.processor_listeners.append(SitemapWriter()) Config.__set_config_filename__("test-files/config.txt") Config().__drop__() DestinationMap.__set_map_filename__("test-files/desmap.txt") DestinationMap().__drop__() DestinationMap().__set_destination__( "http://localhost:8000/rs/source/discover/", "rs/destination/discover")
def test07_process_source(self): # connection and readable resourcesync, write sitemap to file try: shutil.rmtree("rs/destination/d6/sitemaps") except: pass Config.__set_config_filename__("test-files/config.txt") Config().__drop__() DestinationMap.__set_map_filename__("test-files/desmap.txt") DestinationMap().__drop__() des.reporter.reset_instance() Config().__set_prop__(Config.key_use_netloc, "False") Config().__set_prop__(Config.key_audit_only, "False") DestinationMap().__set_destination__("http://localhost:8000/rs/source/s6", "rs/destination/d6") des.processor.processor_listeners.append(SitemapWriter()) base_uri = "http://localhost:8000/rs/source/s6/" sdproc = Sodesproc(base_uri) sdproc.read_source() self.assertEqual(200, sdproc.source_status) self.assertEqual(Status.document, sdproc.status) self.assertTrue(os.path.isfile("rs/destination/d6/sitemaps/.well-known/resourcesync"))
def setUp(self): Config.__set_config_filename__("test-files/config.txt") Config().__drop__()
def test01_new(self): Config.__set_config_filename__("test-files/no-config.txt") with self.assertRaises(FileNotFoundError): Config()
def setUp(self): Config.__set_config_filename__("test-files/config.txt") Config().__drop__() des.dump.dump_listeners.append(SitemapWriter()) DestinationMap().__set_destination__("http://localhost:8000/rs/source", "rs/destination/d7")
def setUp(self): Config.__set_config_filename__("test-files/config.txt") Config().__drop__() DestinationMap.__set_map_filename__("test-files/desmap.txt") DestinationMap().__drop__() des.desclient.reset_instance()
def setUpClass(cls): Config.__set_config_filename__("test-files/config.txt")