def test_should_not_include_files_outside_config_directory(self):

        mock_svn_service = Mock(SvnService)
        mock_svn_service.config_url = "svn://url/for/configuration/repository"
        mock_svn_service.path_to_config = "/config"
        mock_svn_service.client = Mock()
        mock_info = Mock()

        mock_path_object_1 = Mock()
        mock_path_object_1.path = "/config/foo"
        mock_path_object_1.action = "A"

        mock_path_object_2 = Mock()
        mock_path_object_2.path = "/XXXXXX/bar"
        mock_path_object_2.action = "A"

        mock_path_object_3 = Mock()
        mock_path_object_3.path = "/XXX/foobar"
        mock_path_object_3.action = "A"

        mock_info.changed_paths = [mock_path_object_1, mock_path_object_2, mock_path_object_3]
        mock_svn_service.get_logs_for_revision.return_value = [mock_info]

        actual = SvnService.get_changed_paths_with_action(mock_svn_service, "1980")

        self.assertEqual([("foo", "A")], actual)
Example #2
0
 def test_exec_config_with_set_workspaces(self):
     """Test exec config with set workspaces subcommand."""
     args = Mock()
     args.action = "set"
     args.key = "workspaces"
     args.value = False
     self.assertFalse(self.subcommand.execute(args))
Example #3
0
 def test_cover_no_match(self):
     m_result = Mock(spec=etcd.EtcdResult)
     m_result.key = "/a"
     m_result.action = "unknown"
     self.dispatcher.handle_event(m_result)
     for handlers in self.handlers.itervalues():
         for key, handler in handlers.iteritems():
             self.assertFalse(handler.called, msg="Unexpected handler called: %s" % key)
Example #4
0
 def test_exec_config_with_set(self):
     """Test exec config with set subcommand."""
     args = Mock()
     args.action = "set"
     args.key = "logfile"
     args.value = "/tmp/yoda.log"
     self.subcommand.execute(args)
     self.assertEqual("/tmp/yoda.log", self.config["logfile"])
Example #5
0
 def dispatch(self, key, action, value=None):
     """
     Send an EtcdResult to the watcher's dispatcher.
     """
     m_response = Mock(spec=EtcdResult)
     m_response.key = key
     m_response.action = action
     m_response.value = value
     self.watcher.dispatcher.handle_event(m_response)
    def test_should_return_list_with_directory_name_and_action_for_path_to_file_when_a_file_has_been_added(self):

        mock_svn_service = Mock(SvnService)
        mock_svn_service.config_url = "svn://url/for/configuration/repository"
        mock_svn_service.path_to_config = "/config"
        mock_svn_service.client = Mock()
        mock_info = Mock()
        mock_path_object_1 = Mock()
        mock_path_object_1.path = "/config/"
        mock_path_object_1.action = "A"
        mock_info.changed_paths = [mock_path_object_1]
        mock_path_object_2 = Mock()
        mock_path_object_2.path = "/config/spam.egg"
        mock_path_object_2.action = "A"
        mock_info.changed_paths = [mock_path_object_1, mock_path_object_2]
        mock_svn_service.get_logs_for_revision.return_value = [mock_info]

        actual = SvnService.get_changed_paths_with_action(mock_svn_service, "1980")

        self.assertEqual([("", "A"), ("spam.egg", "A")], actual)
Example #7
0
 def test_receive_device(self, monitor):
     """
     Test that Monitor.receive_device is deprecated and calls out to
     _receive_device(), which in turn is tested by test_poll.
     """
     with patch.object(monitor, "_receive_device") as receive_device:
         device = Mock(name="device")
         device.action = "spam"
         receive_device.return_value = device
         event = pytest.deprecated_call(monitor.receive_device)
         assert event[0] == "spam"
         assert event[1] is device
Example #8
0
def test_validation():
    args = Mock()
    args.action = "edit"
    args.input_title = "test app"
    args.input_scopes = ["login:avatar"]

    yom = Yom(args)

    with pytest.raises(YomValidationError):
        yom._run()

    with pytest.raises(YomValidationError):
        yom.args.title = None
        Yom(args)._run()
    def test_should_return_list_with_tuples_including_one_tuple_which_has_a_delete_action(self):

        mock_svn_service = Mock(SvnService)
        mock_svn_service.config_url = "svn://url/for/configuration/repository"
        mock_svn_service.path_to_config = "/config"
        mock_svn_service.client = Mock()
        mock_info = Mock()
        mock_path_object_1 = Mock()
        mock_path_object_1.path = "/config/"
        mock_path_object_1.action = "A"
        mock_info.changed_paths = [mock_path_object_1]
        mock_path_object_2 = Mock()
        mock_path_object_2.path = "/config/spam.egg"
        mock_path_object_2.action = "A"
        mock_path_object_3 = Mock()
        mock_path_object_3.path = "/config/foo.bar"
        mock_path_object_3.action = "D"
        mock_info.changed_paths = [mock_path_object_1, mock_path_object_2, mock_path_object_3]
        mock_svn_service.get_logs_for_revision.return_value = [mock_info]

        actual = SvnService.get_changed_paths_with_action(mock_svn_service, "1980")

        self.assertEqual([("", "A"), ("spam.egg", "A"), ("foo.bar", "D")], actual)
Example #10
0
def test_controller(init_crawler_mock, prepare_view_mock):
    init_crawler_mock.return_value = None
    prepare_view_mock.return_value = lambda **kw: {
        "header": "ok",
        "table": [["param1", "value1"], ["param2", "value2"]],
    }

    args = Mock()
    args.action = "edit"
    args.app_hash = "1" * 32
    args.input_title = "test app"
    args.input_scopes = ["login:avatar"]

    context = Yom(args)._run()
    assert "header" in context
    assert "table" in context
    assert context["header"] in "ok"
    def test_should_return_list_with_empty_string_and_action_string_when_configuration_directory_has_been_created_in_commit(
        self
    ):

        mock_svn_service = Mock(SvnService)
        mock_svn_service.config_url = "svn://url/for/configuration/repository"
        mock_svn_service.path_to_config = "/config"
        mock_info = Mock()
        mock_path_object = Mock()
        mock_path_object.path = "/config/"
        mock_path_object.action = "A"
        mock_info.changed_paths = [mock_path_object]
        mock_svn_service.get_logs_for_revision.return_value = [mock_info]

        actual = SvnService.get_changed_paths_with_action(mock_svn_service, "1980")

        self.assertEqual([("", "A")], actual)
Example #12
0
 def assert_handled(self, key, exp_handler=SAME_AS_KEY, **exp_captures):
     if exp_handler is SAME_AS_KEY:
         exp_handler = key
     if isinstance(exp_handler, types.StringTypes):
         exp_handler = exp_handler.strip("/")
     m_response = Mock(spec=etcd.EtcdResult)
     m_response.key = key
     m_response.action = self.action
     self.dispatcher.handle_event(m_response)
     exp_handlers = self.handlers[self.expected_handlers]
     for handler_key, handler in exp_handlers.iteritems():
         assert isinstance(handler, Mock)
         if handler_key == exp_handler:
             continue
         self.assertFalse(handler.called, "Unexpected set handler %s was called for " "key %s" % (handler_key, key))
     unexp_handlers = self.handlers[self.unexpected_handlers]
     for handler_key, handler in unexp_handlers.iteritems():
         assert isinstance(handler, Mock)
         self.assertFalse(handler.called, "Unexpected del handler %s was called for " "key %s" % (handler_key, key))
     if exp_handler is not None:
         exp_handlers[exp_handler].assert_called_once_with(m_response, **exp_captures)
Example #13
0
 def test_exec_config_with_get(self):
     """Test exec config with get subcommand."""
     args = Mock()
     args.action = "get"
     args.key = "logfile"
     self.assertFalse(self.subcommand.execute(args))
Example #14
0
 def test_exec_config_with_undefined_action(self):
     """Test exec config with undefined subcommand."""
     args = Mock()
     args.action = "yoda"
     self.subcommand.execute(args)