Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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"))
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    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])
Exemplo n.º 7
0
    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])
Exemplo n.º 8
0
    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))
Exemplo n.º 9
0
    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))
Exemplo n.º 10
0
    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))
Exemplo n.º 11
0
    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__()
Exemplo n.º 12
0
    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__()
Exemplo n.º 13
0
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")
Exemplo n.º 14
0
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")
Exemplo n.º 15
0
    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"))
Exemplo n.º 16
0
 def setUp(self):
     Config.__set_config_filename__("test-files/config.txt")
     Config().__drop__()
Exemplo n.º 17
0
    def test01_new(self):
        Config.__set_config_filename__("test-files/no-config.txt")

        with self.assertRaises(FileNotFoundError):
            Config()
Exemplo n.º 18
0
 def setUp(self):
     Config.__set_config_filename__("test-files/config.txt")
     Config().__drop__()
Exemplo n.º 19
0
    def test01_new(self):
        Config.__set_config_filename__("test-files/no-config.txt")

        with self.assertRaises(FileNotFoundError):
            Config()
Exemplo n.º 20
0
 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")
Exemplo n.º 21
0
 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()
Exemplo n.º 22
0
 def setUpClass(cls):
     Config.__set_config_filename__("test-files/config.txt")
Exemplo n.º 23
0
 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")