Пример #1
0
    def __init__(self,
                 path,
                 config_paths=None,
                 ui=None,
                 PluginManagerClass=None,
                 ExternalManagerClass=None,
                 DeploymentEngineClass=None,
                 verb=VERB_UNKNOWN):

        # Load the config engine
        if config_paths is None:
            config_paths = []
        self.config = ConfigRouter(config_paths)
        self.verb = verb

        # Load site-specific config values
        self.prettify_urls = self.config.get('prettify', False)
        self.compress_extensions = self.config.get(
            'compress', ['html', 'css', 'js', 'txt', 'xml'])
        self.fingerprint_extensions = self.config.get('fingerprint', [])
        self.locale = self.config.get("locale", None)

        # Verify our location looks correct
        self.path = path
        self.verify_path()

        # Load Managers
        if ui is None:
            ui = ui_module
        self.ui = ui

        if PluginManagerClass is None:
            PluginManagerClass = PluginManager
        self.plugin_manager = PluginManagerClass(
            self,
            [
                CustomPluginsLoader(self.plugin_path),  # User plugins
                ObjectsPluginLoader([  # Builtin plugins
                    ContextPlugin(),
                    CacheDurationPlugin(),
                    IgnorePatternsPlugin(),
                    PageContextCompatibilityPlugin(),
                ])
            ])

        if ExternalManagerClass is None:
            ExternalManagerClass = ExternalManager
        self.external_manager = ExternalManagerClass(self)

        if DeploymentEngineClass is None:
            hosting_provider = self.config.get("provider", DEFAULT_PROVIDER)
            DeploymentEngineClass = get_deployment_engine_class(
                hosting_provider)
            assert DeploymentEngineClass is not None, \
                   "Could not load Deployment for Provider: {0}".format(hosting_provider)
        self.deployment_engine = DeploymentEngineClass(self)

        # Load Django settings
        self.setup()
Пример #2
0
    def test_read(self):
        """
        Check that the config router reads correctly from the filesystem
        """
        router = ConfigRouter([self.path1, self.path2])

        self.assertEqual(router.get("a"), 1)
        self.assertEqual(router.get("b"), 2)
        self.assertEqual(router.get("c"), None)
Пример #3
0
    def test_duplicate(self):
        """
        Check that the config router handles duplicate files properly.
        """
        router = ConfigRouter([self.path1, self.path1])
        router.set("a", 3)
        router.write()

        self.conf1.load()
        self.assertEqual(self.conf1.get("a"), 3)
Пример #4
0
    def setUp(self):
        super(SiteTestCase, self).setUp()
        self.config_path = os.path.join(self.path, 'config.json')
        self.conf = ConfigRouter([self.config_path])
        self.conf.set('site-url', 'http://example.com/')
        for k, v in self.get_config_for_test().items():
            self.conf.set(k, v)
        self.conf.write()

        self.site = Site(self.path, [self.config_path])
        self.site._parallel = PARALLEL_DISABLED
Пример #5
0
    def test_read_write(self):
        """
        Check that our config is readable after writing it
        """
        router = ConfigRouter([self.path1, self.path2])

        router.set("a", 3)
        router.set("b", 4)

        self.assertEqual(3, router.get("a"))
        self.assertEqual(4, router.get("b"))
Пример #6
0
    def test_collision(self):
        """
        Check that we get the right key when there is a collision
        """
        self.conf1.set("b", 3)
        self.conf2.set("a", 4)
        self.conf1.write()
        self.conf2.write()

        router = ConfigRouter([self.path1, self.path2])

        self.assertEqual(router.get("a"), 1)
        self.assertEqual(router.get("b"), 3)
Пример #7
0
    def test_missing_file(self):
        """
        Test that we don't throw on a missing file, and that the configuration
        remains in a consistent state.
        """
        wrong_path = os.path.join(self.path, "does_not_exist.json")

        self.conf1.set("context", {"k1": "v1"})
        self.conf1.write()

        router = ConfigRouter([wrong_path, self.path1])

        self.assertEqual(router.get("context").get("k1"), "v1")
Пример #8
0
    def setUp(self):
        self.test_dir = tempfile.mkdtemp()
        self.build_path = os.path.join(self.test_dir, '.build')
        os.mkdir(self.build_path)

        self.site = mock.MagicMock()
        self.site.plugin_manager = PluginManager(self.site, [])
        self.site.path = self.test_dir
        self.site.build_path = self.build_path
        self.site.config = ConfigRouter(
            [os.path.join(self.test_dir, "config.json")])
        self.site.config.set("site-url", "http://example.com")

        self.engine = TestDeploymentEngine(self.site)
Пример #9
0
    def test_nested(self):
        """
        Test that we support nested config for context
        """
        self.conf1.set("context", {"k1": "v1"})
        self.conf2.set("context", {"k2": "v2"})
        self.conf1.write()
        self.conf2.write()

        router = ConfigRouter([self.path1, self.path2])
        context = router.get("context", default={}, nested=True)

        self.assertEqual(context.get("k1"), "v1")
        self.assertEqual(context.get("k2"), "v2")
Пример #10
0
    def test_broken_file(self):
        """
        Test that we don't throw on a broken file, and that the configuration
        remains in a consistent state.
        """

        with open(self.path1, "w") as f:
            f.write("{broken}")

        self.conf2.set("context", {"k1": "v1"})
        self.conf2.write()

        router = ConfigRouter([self.path1, self.path2])

        self.assertEqual(router.get("context").get("k1"), "v1")
Пример #11
0
    def test_write(self):
        """
        Check that the config router writes correctly to the filesystem
        """
        router = ConfigRouter([self.path1, self.path2])
        router.set("a", 3)
        router.set("b", 4)
        router.write()

        self.conf1.load()
        self.conf2.load()

        self.assertEqual(self.conf1.get("a"), 3)
        self.assertEqual(self.conf1.get("b"), None)
        self.assertEqual(self.conf2.get("b"), 4)
        self.assertEqual(self.conf2.get("a"), None)