예제 #1
0
 def test_import_error(self):
     """Module import errors are logged. No handler added to C{pdata}."""
     with mock.patch("cloudinit.importer.import_module", side_effect=ImportError) as mockobj:
         handlers.walker_handle_handler(self.data, self.ctype, self.filename, self.payload)
         mockobj.assert_called_once_with(self.expected_module_name)
     self.write_file_mock.assert_called_once_with(self.expected_file_fullname, self.payload, 0o600)
     self.assertEqual(self.data["handlercount"], 0)
예제 #2
0
 def test_no_errors(self):
     """Payload gets written to file and added to C{pdata}."""
     with mock.patch("cloudinit.importer.import_module", return_value=self.module_fake) as mockobj:
         handlers.walker_handle_handler(self.data, self.ctype, self.filename, self.payload)
         mockobj.assert_called_once_with(self.expected_module_name)
     self.write_file_mock.assert_called_once_with(self.expected_file_fullname, self.payload, 0o600)
     self.assertEqual(self.data["handlercount"], 1)
예제 #3
0
 def test_import_error(self):
     """Module import errors are logged. No handler added to C{pdata}."""
     with mock.patch('cloudinit.importer.import_module',
                     side_effect=ImportError) as mockobj:
         handlers.walker_handle_handler(self.data, self.ctype,
                                        self.filename, self.payload)
         mockobj.assert_called_once_with(self.expected_module_name)
     self.write_file_mock.assert_called_once_with(
         self.expected_file_fullname, self.payload, 0o600)
     self.assertEqual(self.data['handlercount'], 0)
예제 #4
0
 def test_no_errors(self):
     """Payload gets written to file and added to C{pdata}."""
     with mock.patch('cloudinit.importer.import_module',
                     return_value=self.module_fake) as mockobj:
         handlers.walker_handle_handler(self.data, self.ctype,
                                        self.filename, self.payload)
         mockobj.assert_called_once_with(self.expected_module_name)
     self.write_file_mock.assert_called_once_with(
         self.expected_file_fullname, self.payload, 0o600)
     self.assertEqual(self.data['handlercount'], 1)
예제 #5
0
    def test_import_error(self):
        """Module import errors are logged. No handler added to C{pdata}."""
        import_mock = self.mocker.replace(importer.import_module, passthrough=False)
        import_mock(self.expected_module_name)
        self.mocker.throw(ImportError())
        self.mocker.replay()

        handlers.walker_handle_handler(self.data, self.ctype, self.filename, self.payload)

        self.assertEqual(0, self.data["handlercount"])
예제 #6
0
    def test_no_errors(self):
        """Payload gets written to file and added to C{pdata}."""
        import_mock = self.mocker.replace(importer.import_module, passthrough=False)
        import_mock(self.expected_module_name)
        self.mocker.result(self.module_fake)
        self.mocker.replay()

        handlers.walker_handle_handler(self.data, self.ctype, self.filename, self.payload)

        self.assertEqual(1, self.data["handlercount"])
예제 #7
0
 def test_attribute_error(self):
     """Attribute errors are logged. No handler added to C{pdata}."""
     with mock.patch('cloudinit.importer.import_module',
                     side_effect=AttributeError,
                     return_value=self.module_fake) as mockobj:
         handlers.walker_handle_handler(self.data, self.ctype,
                                        self.filename, self.payload)
         mockobj.assert_called_with_once(self.expected_module_name)
     self.write_file_mock.assert_called_with_once(
         self.expected_file_fullname, self.payload, 0o600)
     self.assertEqual(self.data['handlercount'], 0)
예제 #8
0
 def test_attribute_error(self):
     """Attribute errors are logged. No handler added to C{pdata}."""
     with mock.patch('cloudinit.importer.import_module',
                     side_effect=AttributeError,
                     return_value=self.module_fake) as mockobj:
         handlers.walker_handle_handler(self.data, self.ctype,
                                        self.filename, self.payload)
         mockobj.assert_called_with_once(self.expected_module_name)
     self.write_file_mock.assert_called_with_once(
         self.expected_file_fullname, self.payload, 0o600)
     self.assertEqual(self.data['handlercount'], 0)
    def test_import_error(self):
        """Module import errors are logged. No handler added to C{pdata}."""
        import_mock = self.mocker.replace(importer.import_module,
                                          passthrough=False)
        import_mock(self.expected_module_name)
        self.mocker.throw(ImportError())
        self.mocker.replay()

        handlers.walker_handle_handler(self.data, self.ctype, self.filename,
                                       self.payload)

        self.assertEqual(0, self.data["handlercount"])
    def test_no_errors(self):
        """Payload gets written to file and added to C{pdata}."""
        import_mock = self.mocker.replace(importer.import_module,
                                          passthrough=False)
        import_mock(self.expected_module_name)
        self.mocker.result(self.module_fake)
        self.mocker.replay()

        handlers.walker_handle_handler(self.data, self.ctype, self.filename,
                                       self.payload)

        self.assertEqual(1, self.data["handlercount"])