def test_do_run(self):
        with mock.patch(
                'collector.app.socorro_app.ConfigurationManager') as cm:
            cm.return_value.context.return_value = mock.MagicMock()
            with mock.patch('collector.app.socorro_app.signal'):

                class SomeOtherApp(SocorroApp):
                    app_name = 'SomeOtherApp'
                    app_verision = '1.2.3'
                    app_description = 'a silly app'

                    def main(self):
                        ok_(self.config is cm.return_value.context.
                            return_value.__enter__.return_value)
                        return 17

                result = main(SomeOtherApp)
                args = cm.call_args_list
                args, kwargs = args[0]
                ok_(isinstance(args[0], Namespace))
                ok_(isinstance(kwargs['values_source_list'], list))
                eq_(kwargs['app_name'], SomeOtherApp.app_name)
                eq_(kwargs['app_version'], SomeOtherApp.app_version)
                eq_(kwargs['app_description'], SomeOtherApp.app_description)
                eq_(kwargs['config_pathname'], './config')
                ok_(kwargs['values_source_list'][-1], command_line)
                ok_(isinstance(kwargs['values_source_list'][-2], DotDict))
                ok_(kwargs['values_source_list'][-3] is ConfigFileFutureProxy)
                ok_(
                    isinstance(kwargs['values_source_list'][0],
                               ApplicationDefaultsProxy))
                eq_(result, 17)
    def test_do_run(self):
        with mock.patch('collector.app.socorro_app.ConfigurationManager') as cm:
            cm.return_value.context.return_value = mock.MagicMock()
            with mock.patch('collector.app.socorro_app.signal'):
                class SomeOtherApp(SocorroApp):
                    app_name='SomeOtherApp'
                    app_verision='1.2.3'
                    app_description='a silly app'
                    def main(self):
                        ok_(
                            self.config
                            is cm.return_value.context.return_value.__enter__
                                 .return_value
                        )
                        return 17

                result = main(SomeOtherApp)
                args = cm.call_args_list
                args, kwargs = args[0]
                ok_(isinstance(args[0], Namespace))
                ok_(isinstance(kwargs['values_source_list'], list))
                eq_(kwargs['app_name'], SomeOtherApp.app_name)
                eq_(kwargs['app_version'], SomeOtherApp.app_version)
                eq_(kwargs['app_description'], SomeOtherApp.app_description)
                eq_(kwargs['config_pathname'], './config')
                ok_(kwargs['values_source_list'][-1], command_line)
                ok_(isinstance(kwargs['values_source_list'][-2], DotDict))
                ok_(kwargs['values_source_list'][-3] is ConfigFileFutureProxy)
                ok_(isinstance(
                    kwargs['values_source_list'][0],
                    ApplicationDefaultsProxy
                ))
                eq_(result, 17)
    def test_do_run_with_alternate_values_source_list(self):
        with mock.patch(
                'collector.app.socorro_app.ConfigurationManager') as cm:
            cm.return_value.context.return_value = mock.MagicMock()
            with mock.patch('collector.app.socorro_app.signal'):

                class SomeOtherApp(SocorroApp):
                    app_name = 'SomeOtherApp'
                    app_verision = '1.2.3'
                    app_description = 'a silly app'

                    def main(self):
                        ok_(self.config is cm.return_value.context.
                            return_value.__enter__.return_value)
                        return 17

                result = main(SomeOtherApp,
                              config_path='my/other/path',
                              values_source_list=[{
                                  "a": 1
                              }, {
                                  "b": 2
                              }])

                args = cm.call_args_list
                args, kwargs = args[0]
                ok_(isinstance(args[0], Namespace))
                eq_(kwargs['app_name'], SomeOtherApp.app_name)
                eq_(kwargs['app_version'], SomeOtherApp.app_version)
                eq_(kwargs['app_description'], SomeOtherApp.app_description)
                eq_(kwargs['config_pathname'], 'my/other/path')
                ok_(isinstance(kwargs['values_source_list'], list))
                ok_(
                    isinstance(kwargs['values_source_list'][0],
                               ApplicationDefaultsProxy))
                eq_(kwargs['values_source_list'][1], {"a": 1})
                eq_(kwargs['values_source_list'][2], {"b": 2})
                eq_(result, 17)
    def test_do_run_with_alternate_values_source_list(self):
        with mock.patch('collector.app.socorro_app.ConfigurationManager') as cm:
            cm.return_value.context.return_value = mock.MagicMock()
            with mock.patch('collector.app.socorro_app.signal'):
                class SomeOtherApp(SocorroApp):
                    app_name='SomeOtherApp'
                    app_verision='1.2.3'
                    app_description='a silly app'
                    def main(self):
                        ok_(
                            self.config
                            is cm.return_value.context.return_value.__enter__
                                 .return_value
                        )
                        return 17

                result = main(
                    SomeOtherApp,
                    config_path='my/other/path',
                    values_source_list=[{"a": 1}, {"b": 2}]
                )

                args = cm.call_args_list
                args, kwargs = args[0]
                ok_(isinstance(args[0], Namespace))
                eq_(kwargs['app_name'], SomeOtherApp.app_name)
                eq_(kwargs['app_version'], SomeOtherApp.app_version)
                eq_(kwargs['app_description'], SomeOtherApp.app_description)
                eq_(kwargs['config_pathname'], 'my/other/path')
                ok_(isinstance(kwargs['values_source_list'], list))
                ok_(isinstance(
                    kwargs['values_source_list'][0],
                    ApplicationDefaultsProxy
                ))
                eq_(kwargs['values_source_list'][1], {"a": 1})
                eq_(kwargs['values_source_list'][2], {"b": 2})
                eq_(result, 17)
Пример #5
0
    main
)
from collector.webapi.servers import WSGIServer
import collector.collector_app

from configman import (
    ConfigFileFutureProxy,
    environment
)

if os.path.isfile('/etc/socorro/collector.ini'):
    config_path = '/etc/socorro'
else:
    config_path = WSGIServer.get_socorro_config_path(__file__)

# invoke the generic main function to create the configman app class and which
# will then create the wsgi app object.
main(
    # we use the generic Socorro App class. We'll rely on configuration to set
    # the 'application' class object to the appropriate collector_app class
    # for example, it could be "CollectorApp" or "Collector2015App"
    SocorroWelcomeApp,
    config_path=config_path,
    values_source_list=[
        ConfigFileFutureProxy,
        environment
    ]
)

application = collector.collector_app.application
Пример #6
0
    #--------------------------------------------------------------------------
    def find_method(self, a_method_name):
        try:
            return getattr(self, a_method_name + '_command')
        except AttributeError:
            return partial(self.method_not_found, a_method_name)

    #--------------------------------------------------------------------------
    def main(self):
        self.crash_store = self.config.crashstorage_class(self.config)
        command = self.find_method(self.config.command)
        result = command()
        if result is not None:
            print result


commands = []
for a_symbol in dir(FetchApp):
    if a_symbol.endswith('_command'):
        commands.append(a_symbol.replace('_command', ''))

FetchApp.required_config.command.doc = (
    FetchApp.required_config.command.doc % ', '.join(commands)
)



if __name__ == '__main__':
    main(FetchApp)
Пример #7
0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
from collector.app.socorro_app import (SocorroWelcomeApp, main)
from collector.webapi.servers import WSGIServer
import collector.collector_app

from configman import (ConfigFileFutureProxy, environment)

if os.path.isfile('/etc/socorro/collector.ini'):
    config_path = '/etc/socorro'
else:
    config_path = WSGIServer.get_socorro_config_path(__file__)

# invoke the generic main function to create the configman app class and which
# will then create the wsgi app object.
main(
    # We use the generic Socorro App class. We'll rely on configuration to set
    # the 'application' class object to the appropriate collector_app class.
    # For example, it could be "CollectorApp".
    SocorroWelcomeApp,
    config_path=config_path,
    values_source_list=[ConfigFileFutureProxy, environment])

application = collector.collector_app.application
Пример #8
0
    #--------------------------------------------------------------------------
    def raw_dumps_as_files_command(self):
        return self.crash_store.get_raw_dumps_as_files(self.config.crash_id)

    #--------------------------------------------------------------------------
    def find_method(self, a_method_name):
        try:
            return getattr(self, a_method_name + '_command')
        except AttributeError:
            return partial(self.method_not_found, a_method_name)

    #--------------------------------------------------------------------------
    def main(self):
        self.crash_store = self.config.crashstorage_class(self.config)
        command = self.find_method(self.config.command)
        result = command()
        if result is not None:
            print result


commands = []
for a_symbol in dir(FetchApp):
    if a_symbol.endswith('_command'):
        commands.append(a_symbol.replace('_command', ''))

FetchApp.required_config.command.doc = (FetchApp.required_config.command.doc %
                                        ', '.join(commands))

if __name__ == '__main__':
    main(FetchApp)