Esempio n. 1
0
    def test_register_backend(self):
        class Foo:
            pass

        with self.assertRaises(TypeError):
            back.register_backend(Foo)

        class Bar(back.StorageBackend):
            NAME = "Bar"

        back.register_backend(Bar)
        self.assertEqual(Bar, back.__registry__["Bar"])
Esempio n. 2
0
    def test_create_backend_invalid_args(self):
        backup = back.config.BACKEND_ARGS
        back.config.BACKEND_ARGS = "lalala"
        with self.assertRaises(ValueError):
            back.create_backend("Bar")
        back.config.BACKEND_ARGS = backup
        backup = back.config.BACKEND_ARGS
        back.config.BACKEND_ARGS = ""

        class Bar(back.StorageBackend):
            NAME = "Bar"

        back.register_backend(Bar)
        git_index = ind.GitIndex(index_repo=self.default_url,
                                 cache=self.cached_path)
        try:
            self.assertIsInstance(back.create_backend("Bar", git_index), Bar)
        finally:
            back.config.BACKEND_ARGS = backup
Esempio n. 3
0
    def test_create_backend_invalid_args(self):
        backup = backends.config.BACKEND_ARGS
        backends.config.BACKEND_ARGS = "lalala"

        try:
            with self.assertRaises(ValueError):
                backends.create_backend("Bar")
        finally:
            backends.config.BACKEND_ARGS = backup

        backup = backends.config.BACKEND_ARGS
        backends.config.BACKEND_ARGS = ""

        class Bar(backends.StorageBackend):
            NAME = "Bar"

        backends.register_backend(Bar)

        try:
            self.assertIsInstance(backends.create_backend("Bar"), Bar)
        finally:
            backends.config.BACKEND_ARGS = backup