Beispiel #1
0
 def test_wrong_type(self):
     class DummyPlugin(object):
         schema = Schema({}, extra=ALLOW_EXTRA)
     plugins = Plugins()
     plugins.register('repo', 'foo', DummyPlugin)
     with ShouldRaise (TypeError):
         Config.realise(dict(repos=[dict(type='foo')]),
                        plugins)
Beispiel #2
0
 def test_no_schema(self):
     class DummyPlugin(Repo): pass
     plugins = Plugins()
     plugins.register('repo', 'foo', DummyPlugin)
     with ShouldRaise (
             TypeError("'abstractproperty' object is not callable")
     ):
         Config.realise(dict(repos=[dict(type='foo')]),
                        plugins)
Beispiel #3
0
 def test_plugin_instantiation_exception(self):
     class DummyPlugin(Repo):
         schema = Schema({}, extra=ALLOW_EXTRA)
     plugins = Plugins()
     plugins.register('repo', 'foo', DummyPlugin)
     with ShouldRaise (TypeError(
             "Can't instantiate abstract class DummyPlugin "
             "with abstract methods __init__, actions, path_for"
     )):
         Config.realise(dict(repos=[dict(type='foo')]),
                        plugins)
Beispiel #4
0
    def test_missing_required_key(self):
        class DummyPlugin(Repo):
            schema = Schema({Required('type'): str, Required('foo'): int})
        plugins = Plugins()
        plugins.register('repo', 'foo', DummyPlugin)
        self.check_config_error(
            config=dict(repos=[dict(type='foo')]),
            plugins=plugins,
            expected="""\
at ['repos', 0], required key not provided, 'foo':
type: foo
"""
        )
Beispiel #5
0
    def test_invalid_config_data(self):
        class DummyPlugin(Repo):
            schema = Schema({Required('type'): str, Required('foo'): int})
        plugins = Plugins()
        plugins.register('repo', 'foo', DummyPlugin)
        self.check_config_error(
            config=dict(repos=[dict(type='foo', foo='bar')]),
            plugins=plugins,
            expected="""\
at ['repos', 0, 'foo'], expected int:
foo: bar
type: foo
"""
        )
Beispiel #6
0
    def test_full_instantiation(self):
        # one of each
        class DummyGit(Repo):
            schema = Schema({}, extra=ALLOW_EXTRA)
            def __init__(self, type, name):
                super(DummyGit, self).__init__(type, name)
            def actions(self):
                pass
            def path_for(self, source):
                pass

        class DummyPath(Source):
            schema = Schema({}, extra=ALLOW_EXTRA)
            def __init__(self, type, name, repo):
                super(DummyPath, self).__init__(type, name, repo)
            def process(self, path):
                pass

        class DummyEmail(Notifier):
            schema = Schema({}, extra=ALLOW_EXTRA)
            def __init__(self, type, name):
                super(DummyEmail, self).__init__(type, name,
                                                 level=0, fmt='f', datefmt='d')
            def start(self):
                pass
            def finish(self):
                pass

        plugins = Plugins()
        plugins.register('repo', 'git', DummyGit)
        plugins.register('source', 'path', DummyPath)
        plugins.register('notification', 'email', DummyEmail)

        source = open(self.dir.write('test.yaml', """
repos:
  - name: config
    type: git

sources:
- path: /some/path

notifications:
- email: [email protected]
"""))
        config = Config.load(source, plugins)
        compare(
            C(Config,
              repos=dict(config=C(DummyGit, type='git', name='config')),
              sources=[C(DummyPath,
                         type='path', repo='config', name='/some/path')],
              notifications=[
                  C(DummyEmail,
                    type='email', name='*****@*****.**',
                    level=0, fmt='f', datefmt='d')
              ]),
            config
        )
Beispiel #7
0
    def test_valid(self):
        # one of each
        class DummyRepo(Repo):
            schema = Schema({}, extra=ALLOW_EXTRA)
            def __init__(self, type, name, x):
                super(DummyRepo, self).__init__(type, name)
                self.x = x
            def actions(self):
                pass
            def path_for(self, source):
                pass

        class DummySource(Source):
            schema = Schema({}, extra=ALLOW_EXTRA)
            def __init__(self, type, name, repo, y):
                super(DummySource, self).__init__(type, name, repo)
                self.y = y
            def process(self, path):
                pass

        class DummyNotifier(Notifier):
            schema = Schema({}, extra=ALLOW_EXTRA)
            def __init__(self, type, name, z):
                super(DummyNotifier, self).__init__(
                    type, name, level=0, fmt='f', datefmt='d'
                )
                self.z = z
            def start(self):
                pass
            def finish(self):
                pass

        plugins = Plugins()
        plugins.register('repo', 'foo', DummyRepo)
        plugins.register('source', 'bar', DummySource)
        plugins.register('notification', 'baz', DummyNotifier)

        config = Config.realise(dict(repos=[dict(type='foo', name='po', x=1)],
                                     sources=[dict(type='bar', y=2, repo='po',
                                                   name=None)],
                                     notifications=[dict(type='baz', z=3,
                                                         name=None)]),
                                plugins)

        compare({'po': C(DummyRepo, type='foo', name='po', x=1)},
                config.repos)
        compare([C(DummySource, y=2, type='bar', repo='po', name=None)],
                config.sources)
        compare([C(DummyNotifier,
                   type='baz', name=None,
                   level=0, fmt='f', datefmt='d',
                   z=3,
                   )],
                config.notifications)
Beispiel #8
0
 def test_plugin_names(self):
     # check setup.py is as expected!
     plugins = Plugins.load()
     actual = []
     for type, stuff in sorted(plugins.plugins.items()):
         for name in sorted(stuff):
             actual.append((type, name))
     compare([
         ('notification', 'email'),
         ('notification', 'stream'),
         ('repo', 'git'),
         ('source', 'crontab'),
         ('source', 'jenkins'),
         ('source', 'packages'),
         ('source', 'paths'),
     ],actual)
Beispiel #9
0
    def test_defaults_instantiate(self):
        plugins = Plugins.load()

        git = plugins.get('repo', 'git')
        paths = plugins.get('source', 'paths')
        stream = plugins.get('notification', 'stream')

        file_path = self.dir.write('test.conf', 'conf content')
        source = open(self.dir.write('test.yaml', """
sources:
- paths:
  - {}
""".format(file_path)))
        config = Config.load(source, plugins)
        compare(
            C(Config,
              repos=dict(config=C(git, strict=False, **default_repo_config)),
              sources=[C(paths, type='paths', repo='config', name=None,
                         source_paths=[file_path])],
              notifications=[
                  C(stream, strict=False, **default_notifications_config)
              ]),
            config
        )
Beispiel #10
0
 def load_plugins(self):
     with Replacer() as r:
         r.replace('archivist.plugins.iter_entry_points',
                   self.mock_iter_entry_points)
         plugins = Plugins.load()
     return plugins