コード例 #1
0
 def test_add_config(self):
     with self.assertRaises(BaseClient.ClientException):
         c = utils.create_base_client()
         c.add_config(1)
     with self.assertRaises(BaseClient.ClientException):
         c = utils.create_base_client()
         c.add_config('foo')
         c.add_config('foo')
     c = utils.create_base_client()
     c.add_config('bar')
コード例 #2
0
    def test_call_daemon(self):
        c = utils.create_base_client()
        # do it like this because it seems mock uses the
        # same instance across calls. so, for example, once start
        # is set it will stay set when we call 'call_daemon' again
        with patch('client.client.ClientDaemon') as mock_daemon:
            client.call_daemon(c, 'start')
            self.assertTrue(mock_daemon.called)
            self.assertTrue(mock_daemon.return_value.start.called)
            self.assertFalse(mock_daemon.return_value.restart.called)
            self.assertFalse(mock_daemon.return_value.stop.called)

        with patch('client.client.ClientDaemon') as mock_daemon:
            client.call_daemon(c, 'stop')
            self.assertTrue(mock_daemon.called)
            self.assertFalse(mock_daemon.return_value.start.called)
            self.assertFalse(mock_daemon.return_value.restart.called)
            self.assertTrue(mock_daemon.return_value.stop.called)

        with patch('client.client.ClientDaemon') as mock_daemon:
            client.call_daemon(c, 'restart')
            self.assertTrue(mock_daemon.called)
            self.assertFalse(mock_daemon.return_value.start.called)
            self.assertTrue(mock_daemon.return_value.restart.called)
            self.assertFalse(mock_daemon.return_value.stop.called)
コード例 #3
0
 def test_environment(self):
     c = utils.create_base_client()
     self.assertNotIn('FOO', c.get_environment())
     with self.assertRaises(BaseClient.ClientException):
         c.get_environment('FOO')
     c.set_environment('FOO', 'bar')
     self.assertEqual('bar', c.get_environment('FOO'))
     self.assertEqual(c.client_info['environment'], c.get_environment())
コード例 #4
0
    def test_set_client_info(self):
        c = utils.create_base_client()

        with self.assertRaises(BaseClient.ClientException):
            c.set_client_info('foo', None)

        c.set_client_info('client_name', 'foo')
        self.assertEqual(c.get_client_info('client_name'), 'foo')
コード例 #5
0
    def test_log_dir(self):
        c = utils.create_base_client()
        self.assertIn(c.client_info["client_name"], c.client_info["log_file"])
        # dir exists but can't write
        with self.assertRaises(BaseClient.ClientException):
            c.set_log_dir("/var")

        # dir does not exist
        with self.assertRaises(BaseClient.ClientException):
            c.set_log_dir("/var/aafafafaf")

        # not set, should just return
        c.set_log_dir("")

        # test it out from __init__
        with self.assertRaises(BaseClient.ClientException):
            c = utils.create_base_client(log_dir="/afafafafa/")

        # test it out from __init__
        with self.assertRaises(BaseClient.ClientException):
            c = utils.create_base_client(log_dir="", log_file="")
コード例 #6
0
 def create_client_and_job(self, recipe_dir, name, sleep=1):
     c = utils.create_base_client()
     os.environ["BUILD_ROOT"] = "/foo/bar"
     c.client_info["single_shot"] = True
     c.client_info["update_step_time"] = 1
     c.client_info["ssl_cert"] = False # not needed but will get another line of coverage
     c.client_info["server"] = self.live_server_url
     c.client_info["servers"] = [self.live_server_url]
     job = utils.create_client_job(recipe_dir, name=name, sleep=sleep)
     c.client_info["build_configs"] = [job.config.name]
     c.client_info["build_key"] = job.recipe.build_user.build_key
     return c, job
コード例 #7
0
    def test_log_file(self):
        c = utils.create_base_client(log_file="test_log")
        self.assertIn('test_log', c.client_info["log_file"])

        # can't write
        with self.assertRaises(BaseClient.ClientException):
            c.set_log_file("/var/foo")

        # can't write
        with self.assertRaises(BaseClient.ClientException):
            c.set_log_file("/aafafafaf/fo")

        # not set, should just return
        c.set_log_file("")
コード例 #8
0
 def create_client_and_job(self, recipe_dir, name, sleep=1):
     c = utils.create_base_client()
     c.set_environment('BUILD_ROOT', '/foo/bar')
     c.client_info["single_shot"] = True
     c.client_info["update_step_time"] = 1
     c.client_info[
         "ssl_cert"] = False  # not needed but will get another line of coverage
     c.client_info["server"] = self.live_server_url
     c.client_info["servers"] = [self.live_server_url]
     job = utils.create_client_job(recipe_dir, name=name, sleep=sleep)
     if job.config.name not in c.get_client_info("build_configs"):
         c.add_config(job.config.name)
     c.client_info["build_key"] = job.recipe.build_user.build_key
     return c, job