コード例 #1
0
    def test_notify_website_relation_with_different_sitenames(self):
        self.get_relation_ids.return_value = ("website:1", )
        self.get_hostname.return_value = "foo.local"
        self.relations_for_id.return_value = [{
            "service_name": "foo"
        }, {
            "service_name": "bar"
        }]
        self.config_get.return_value = {"services": ""}

        hooks.notify_relation("website")

        self.get_hostname.assert_called_once_with()
        self.get_relation_ids.assert_called_once_with("website")
        self.relations_for_id.assert_has_calls([
            call("website:1"),
        ])

        self.relation_set.assert_has_calls([
            call.relation_set(relation_id="website:1",
                              port="80",
                              hostname="foo.local",
                              all_services=""),
        ])
        self.log.assert_has_calls([
            call.log("Remote units requested more than a single service name."
                     "Falling back to default host/port."),
            call.log("No services configured, exiting."),
        ])
コード例 #2
0
  def testMessagesSentToLogSink(self):
    log_source = build_logging.LogSource(enums.Verbosity.VERBOSE)
    with patch('anvil.util.timer') as mock_timer:
      mock_timer.side_effect = [1, 2, 3, 4]
      log_source.log_debug('debug', 'bar')
      log_source.log_info('info', 'bar')
      log_source.log_warning('warning', 'foo')
      log_source.log_error('error', 'foo')
    log_sink = MagicMock()
    log_source.add_log_sink(log_sink)
    expected = [
      call.log(_message(enums.LogLevel.DEBUG, 1, 'bar', '[DEBUG] debug')),
      call.log(_message(enums.LogLevel.INFO, 2, 'bar', '[INFO] info')),
      call.log(_message(enums.LogLevel.WARNING, 3, 'foo', '[WARNING] warning')),
      call.log(_message(enums.LogLevel.ERROR, 4, 'foo', '[ERROR] error'))
    ]
    self.assertEquals(expected, log_sink.mock_calls)

    log_sink.mock_calls = []
    with patch('anvil.util.timer') as mock_timer:
      mock_timer.side_effect = [5]
      log_source.log_debug('debug', 'bar')
    expected = [
      call.log(_message(enums.LogLevel.DEBUG, 5, 'bar', '[DEBUG] debug'))
    ]
    self.assertEquals(expected, log_sink.mock_calls)
コード例 #3
0
    def testMessagesSentToLogSink(self):
        log_source = build_logging.LogSource(enums.Verbosity.VERBOSE)
        with patch('anvil.util.timer') as mock_timer:
            mock_timer.side_effect = [1, 2, 3, 4]
            log_source.log_debug('debug', 'bar')
            log_source.log_info('info', 'bar')
            log_source.log_warning('warning', 'foo')
            log_source.log_error('error', 'foo')
        log_sink = MagicMock()
        log_source.add_log_sink(log_sink)
        expected = [
            call.log((enums.LogLevel.DEBUG, 1, 'bar', '[DEBUG] debug')),
            call.log((enums.LogLevel.INFO, 2, 'bar', '[INFO] info')),
            call.log((enums.LogLevel.WARNING, 3, 'foo', '[WARNING] warning')),
            call.log((enums.LogLevel.ERROR, 4, 'foo', '[ERROR] error'))
        ]
        self.assertEquals(expected, log_sink.mock_calls)

        log_sink.mock_calls = []
        with patch('anvil.util.timer') as mock_timer:
            mock_timer.side_effect = [5]
            log_source.log_debug('debug', 'bar')
        expected = [
            call.log((enums.LogLevel.DEBUG, 5, 'bar', '[DEBUG] debug'))
        ]
        self.assertEquals(expected, log_sink.mock_calls)
コード例 #4
0
ファイル: test_website_hooks.py プロジェクト: mjs/juju
    def test_notify_website_relation_with_different_sitenames(self):
        self.get_relation_ids.return_value = ("website:1",)
        self.get_hostname.return_value = "foo.local"
        self.relations_for_id.return_value = [{"service_name": "foo"},
                                              {"service_name": "bar"}]
        self.config_get.return_value = {"services": ""}

        hooks.notify_relation("website")

        self.get_hostname.assert_called_once_with()
        self.get_relation_ids.assert_called_once_with("website")
        self.relations_for_id.assert_has_calls([
            call("website:1"),
            ])

        self.relation_set.assert_has_calls([
            call.relation_set(
                relation_id="website:1", port="80", hostname="foo.local",
                all_services=""),
            ])
        self.log.assert_has_calls([
            call.log(
                "Remote units requested more than a single service name."
                "Falling back to default host/port."),
            call.log("No services configured, exiting."),
            ])
コード例 #5
0
 def _get_debug_call(self, expected_log_msg):
     """Return a mock call object that captures the param values of the log() call"""
     debug_log_call = call.log(
         scalyr_logging.DEBUG_LEVEL_1,
         expected_log_msg,
         limit_once_per_x_secs=300,
         limit_key='query-api-log-resp-%s' % md5_hexdigest(self._path))
     return debug_log_call
コード例 #6
0
 def test_no_private_address_in_relation_data(self):
     self.get_config_services.return_value = {
         "service": {
             "service_name": "service",
             },
         }
     self.relations_of_type.return_value = [
         {"port": 4242,
          "__unit__": "foo/0"},
     ]
     self.assertIs(None, hooks.create_services())
     self.log.assert_has_calls([call.log(
         "No private-address in relation data for 'foo/0', skipping.")])
     self.write_service_config.assert_not_called()
コード例 #7
0
    def testChildMessagesDetected(self):
        child_source = build_logging.LogSource(enums.Verbosity.INHERIT)
        parent_source = build_logging.LogSource(enums.Verbosity.VERBOSE)
        log_sink = MagicMock()
        parent_source.add_log_sink(log_sink)
        parent_source.add_child(child_source)

        with patch('anvil.util.timer') as mock_timer:
            mock_timer.side_effect = [1]
            child_source.log_debug('debug', 'foo')
        expected = [
            call.log((enums.LogLevel.DEBUG, 1, 'foo', '[DEBUG] debug'))
        ]
        self.assertEquals(expected, log_sink.mock_calls)
コード例 #8
0
  def testChildMessagesDetected(self):
    child_source = build_logging.LogSource(enums.Verbosity.INHERIT)
    parent_source = build_logging.LogSource(enums.Verbosity.VERBOSE)
    log_sink = MagicMock()
    parent_source.add_log_sink(log_sink)
    parent_source.add_child(child_source)

    with patch('anvil.util.timer') as mock_timer:
      mock_timer.side_effect = [1]
      child_source.log_debug('debug', 'foo')
    expected = [
      call.log(_message(enums.LogLevel.DEBUG, 1, 'foo', '[DEBUG] debug'))
    ]
    self.assertEquals(expected, log_sink.mock_calls)
コード例 #9
0
 def test_no_port_in_relation_data(self):
     self.get_config_services.return_value = {
         "service": {
             "service_name": "service",
         },
     }
     self.relations_of_type.return_value = [
         {
             "private-address": "1.2.3.4",
             "__unit__": "foo/0"
         },
     ]
     self.assertIs(None, hooks.create_services())
     self.log.assert_has_calls(
         [call.log("No port in relation data for 'foo/0', skipping.")])
     self.write_service_config.assert_not_called()
コード例 #10
0
ファイル: test_git.py プロジェクト: tommyip/gitlint
    def test_get_latest_commit_merge_commit(self, sh):
        sample_sha = "d8ac47e9f2923c7f22d8668e3a1ed04eb4cdbca9"

        def git_log_side_effect(*_args, **_kwargs):
            return (
                u"test åuthor,test-emå[email protected],2016-12-03 15:28:15 01:00,åbc def\n"
                u"Merge \"foo bår commit\"")

        sh.git.side_effect = [sample_sha, u"file1.txt\npåth/to/file2.txt\n"]
        sh.git.log.side_effect = git_log_side_effect

        context = GitContext.from_local_repository(u"fåke/path")
        expected_sh_special_args = {'_tty_out': False, '_cwd': u"fåke/path"}
        # assert that commit info was read using git command
        expected_calls = [
            call("rev-list", "--max-count=1", "HEAD",
                 **expected_sh_special_args),
            call.log(sample_sha,
                     "-1",
                     "--pretty=%aN,%aE,%ai,%P%n%B",
                     _cwd=u"fåke/path",
                     _tty_out=False),
            call('diff-tree', '--no-commit-id', '--name-only', '-r',
                 sample_sha, **expected_sh_special_args)
        ]

        self.assertEqual(sh.git.mock_calls, expected_calls)

        last_commit = context.commits[-1]
        self.assertEqual(last_commit.message.title,
                         u"Merge \"foo bår commit\"")
        self.assertEqual(last_commit.message.body, [])
        self.assertEqual(last_commit.author_name, u"test åuthor")
        self.assertEqual(last_commit.author_email, u"test-emå[email protected]")
        self.assertEqual(
            last_commit.date,
            datetime.datetime(2016,
                              12,
                              3,
                              15,
                              28,
                              15,
                              tzinfo=dateutil.tz.tzoffset("+0100", 3600)))
        self.assertListEqual(last_commit.parents, [u"åbc", "def"])
        self.assertTrue(last_commit.is_merge_commit)
        self.assertListEqual(last_commit.changed_files,
                             ["file1.txt", u"påth/to/file2.txt"])
コード例 #11
0
 def test_relation_unknown_service(self):
     self.get_config_services.return_value = {
         "service": {
             "service_name": "service",
             },
         }
     self.relations_of_type.return_value = [
         {"port": 4242,
          "hostname": "backend.1",
          "service_name": "invalid",
          "private-address": "1.2.3.4",
          "__unit__": "foo/0"},
     ]
     self.assertIs(None, hooks.create_services())
     self.log.assert_has_calls([call.log(
         "Service 'invalid' does not exist.")])
     self.write_service_config.assert_not_called()
コード例 #12
0
 def test_relation_unknown_service(self):
     self.get_config_services.return_value = {
         "service": {
             "service_name": "service",
         },
     }
     self.relations_of_type.return_value = [
         {
             "port": 4242,
             "hostname": "backend.1",
             "service_name": "invalid",
             "private-address": "1.2.3.4",
             "__unit__": "foo/0"
         },
     ]
     self.assertIs(None, hooks.create_services())
     self.log.assert_has_calls(
         [call.log("Service 'invalid' does not exist.")])
     self.write_service_config.assert_not_called()