Ejemplo n.º 1
0
 def test_smoke(self):
     config = PlainBoxConfig()
     self.assertIs(config.secure_id, Unset)
     secure_id = "0123456789ABCDE"
     config.secure_id = secure_id
     self.assertEqual(config.secure_id, secure_id)
     with self.assertRaises(ValueError):
         config.secure_id = "bork"
     self.assertEqual(config.secure_id, secure_id)
     del config.secure_id
     self.assertIs(config.secure_id, Unset)
Ejemplo n.º 2
0
    def test_with_config_and_variables_not_in_environ(self):
        env = {"bar": "old-bar-value"}
        # Setup a configuration object with values for baz.
        # Note that baz is *not* declared in the job's environ line.
        from plainbox.impl.applogic import PlainBoxConfig

        config = PlainBoxConfig()
        config.environment = {"baz": "baz-value"}
        # Ask the job to modify the environment
        self.job.modify_execution_environment(env, self.session_dir, self.checkbox_data_dir, config)
        # bar from the old environment
        self.assertEqual(env["bar"], "old-bar-value")
        # baz from the config environment
        self.assertEqual(env["baz"], "baz-value")
Ejemplo n.º 3
0
 def test_with_config_and_variables_not_in_environ(self):
     env = {'bar': 'old-bar-value'}
     # Setup a configuration object with values for baz.
     # Note that baz is *not* declared in the job's environ line.
     from plainbox.impl.applogic import PlainBoxConfig
     config = PlainBoxConfig()
     config.environment = {'baz': 'baz-value'}
     # Ask the job to modify the environment
     self.job.modify_execution_environment(env, self.session_dir,
                                           self.checkbox_data_dir, config)
     # bar from the old environment
     self.assertEqual(env['bar'], 'old-bar-value')
     # baz from the config environment
     self.assertEqual(env['baz'], 'baz-value')
Ejemplo n.º 4
0
 def main(self, argv=None):
     # TODO: setup sane logging system that works just as well for Joe user
     # that runs checkbox from the CD as well as for checkbox developers and
     # custom debugging needs.  It would be perfect^Hdesirable not to create
     # another broken, never-rotated, uncapped logging crap that kills my
     # SSD by writing junk to ~/.cache/
     basicConfig(level="WARNING")
     config = PlainBoxConfig.get()
     parser = self._construct_parser(config)
     ns = parser.parse_args(argv)
     # Set the desired log level
     getLogger("").setLevel(ns.log_level)
     # Argh the horrror!
     #
     # Since CPython revision cab204a79e09 (landed for python3.3)
     # http://hg.python.org/cpython/diff/cab204a79e09/Lib/argparse.py
     # the argparse module behaves differently than it did in python3.2
     #
     # In practical terms subparsers are now optional in 3.3 so all of the
     # commands are no longer required parameters.
     #
     # To compensate, on python3.3 and beyond, when the user just runs
     # plainbox without specifying the command, we manually, explicitly do
     # what python3.2 did: call parser.error(_('too few arguments'))
     if (sys.version_info[:2] >= (3, 3)
             and getattr(ns, "command", None) is None):
         parser.error(argparse_gettext("too few arguments"))
     else:
         return ns.command.invoked(ns)
Ejemplo n.º 5
0
    def proxy_test(self, environment, proxies):
        test_environment = environment
        test_proxies = proxies
        test_config = PlainBoxConfig()
        test_config.environment = test_environment

        transport = SubmissionServiceTransport(
            self.valid_url, self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(dummy_data, config=test_config)
        self.assertTrue(result)
        requests.post.assert_called_with(
            self.valid_url, data=dummy_data,
            proxies=test_proxies)
Ejemplo n.º 6
0
    def proxy_test(self, environment, proxies):
        test_environment = environment
        test_proxies = proxies
        test_config = PlainBoxConfig()
        test_config.environment = test_environment

        transport = CertificationTransport(
            self.valid_url, self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(dummy_data, config=test_config)
        self.assertTrue(result)
        requests.post.assert_called_with(
            self.valid_url, files={'data': dummy_data},
            headers={'X_HARDWARE_ID': self.valid_secure_id},
            proxies=test_proxies)
Ejemplo n.º 7
0
    def test_with_config_and_environ_variables(self):
        env = {
            "PATH": "",
            # foo is not defined in the environment
            "bar": "old-bar-value"
            # froz is not defined in the environment
        }
        # Setup a configuration object with values for foo and bar
        from plainbox.impl.applogic import PlainBoxConfig

        config = PlainBoxConfig()
        config.environment = {"foo": "foo-value", "bar": "bar-value"}
        # Ask the job to modify the environment
        self.job.modify_execution_environment(env, self.session_dir, self.checkbox_data_dir, config)
        # foo got copied from the config
        self.assertEqual(env["foo"], "foo-value")
        # bar from the old environment
        self.assertEqual(env["bar"], "old-bar-value")
        # froz is still empty
        self.assertNotIn("froz", env)
Ejemplo n.º 8
0
 def test_with_config_and_environ_variables(self):
     env = {
         "PATH": "",
         # foo is not defined in the environment
         'bar': 'old-bar-value'
         # froz is not defined in the environment
     }
     # Setup a configuration object with values for foo and bar
     from plainbox.impl.applogic import PlainBoxConfig
     config = PlainBoxConfig()
     config.environment = {'foo': 'foo-value', 'bar': 'bar-value'}
     # Ask the job to modify the environment
     self.job.modify_execution_environment(env, self.session_dir,
                                           self.checkbox_data_dir, config)
     # foo got copied from the config
     self.assertEqual(env['foo'], 'foo-value')
     # bar from the old environment
     self.assertEqual(env['bar'], 'old-bar-value')
     # froz is still empty
     self.assertNotIn('froz', env)
Ejemplo n.º 9
0
 def test_with_config_and_environ_variables(self):
     env = {
         "PATH": "",
         # foo is not defined in the environment
         'bar': 'old-bar-value'
         # froz is not defined in the environment
     }
     # Setup a configuration object with values for foo and bar
     from plainbox.impl.applogic import PlainBoxConfig
     config = PlainBoxConfig()
     config.environment = {
         'foo': 'foo-value',
         'bar': 'bar-value'
     }
     # Ask the job to modify the environment
     self.job.modify_execution_environment(env, self.session_dir, config)
     # foo got copied from the config
     self.assertEqual(env['foo'], 'foo-value')
     # bar from the old environment
     self.assertEqual(env['bar'], 'old-bar-value')
     # froz is still empty
     self.assertNotIn('froz', env)
 def setUp(self):
     self.provider = mock.Mock(spec_set=IProvider1, name='provider')
     self.provider.namespace = "com.canonical.plainbox"
     self.provider.job_list = []
     self.provider.units_dir = None
     self.provider.jobs_dir = None
     self.provider.data_dir = None
     self.provider.executable_list = []
     self.provider.id_map = defaultdict(list)
     self.provider.extra_PYTHONPATH = None
     self.provider.CHECKBOX_SHARE = None
     self.provider_loader = lambda: [self.provider]
     self.config_loader = lambda: PlainBoxConfig()
Ejemplo n.º 11
0
    def proxy_test(self, environment, proxies):
        test_environment = environment
        test_proxies = proxies
        test_config = PlainBoxConfig()
        test_config.environment = test_environment

        transport = CertificationTransport(self.valid_url,
                                           self.valid_option_string,
                                           config=test_config)
        dummy_data = BytesIO(b"some data to send")

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(dummy_data)

        self.assertTrue(result)

        requests.post.assert_called_with(self.valid_url,
                                         files={'data': dummy_data},
                                         headers={'X_HARDWARE_ID':
                                         self.valid_secure_id},
                                         proxies=test_proxies)
Ejemplo n.º 12
0
 def setUp(self):
     self.provider = mock.Mock()
     self.config = PlainBoxConfig()
     self.job_name = mock.Mock()
Ejemplo n.º 13
0
 def setUp(self):
     self.provider_list = mock.Mock()
     self.config = PlainBoxConfig()
     self.job_id = mock.Mock()