Exemple #1
0
 def setUp(self):
     self.working_dir = tempfile.mkdtemp()
     self.tag = 'metadata'
     self.attributes = {'packages': '30'}
     self.context = XmlFileContext(
         os.path.join(self.working_dir, 'test.xml'), self.tag,
         self.attributes)
Exemple #2
0
class XmlFileContextTests(unittest.TestCase):
    def setUp(self):
        self.working_dir = tempfile.mkdtemp()
        self.tag = 'metadata'
        self.attributes = {'packages': '30'}
        self.context = XmlFileContext(
            os.path.join(self.working_dir, 'test.xml'), self.tag,
            self.attributes)

    def tearDown(self):
        shutil.rmtree(self.working_dir)

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_init_with_arguments(self, mock_generator):
        self.assertEquals(self.context.root_attributes, self.attributes)
        self.assertEquals(self.context.root_tag, 'metadata')

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_init_with_no_properties(self, mock_generator):
        self.context = XmlFileContext(
            os.path.join(self.working_dir, 'test.xml'), self.tag)
        self.assertEquals(self.context.root_attributes, {})
        self.assertEquals(self.context.root_tag, 'metadata')

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_open_metadata_file_handle(self, mock_generator):
        self.context._open_metadata_file_handle()
        mock_generator.assert_called_once_with(
            self.context.metadata_file_handle, 'UTF-8')

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_write_file_header(self, mock_generator):
        self.context._open_metadata_file_handle()
        self.context._write_file_header()
        mock_generator.return_value.startDocument.assert_called_once()
        mock_generator.return_value.startElement.assert_called_once_with(
            self.tag, self.attributes)

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_write_file_footer(self, mock_generator):
        self.context._open_metadata_file_handle()
        self.context._write_file_footer()
        mock_generator.return_value.endElement.assert_called_once_with(
            self.tag)
        mock_generator.return_value.endDocument.assert_called_once()
class XmlFileContextTests(unittest.TestCase):

    def setUp(self):
        self.working_dir = tempfile.mkdtemp()
        self.tag = 'metadata'
        self.attributes = {'packages': '30'}
        self.context = XmlFileContext(os.path.join(self.working_dir, 'test.xml'),
                                      self.tag, self.attributes)

    def tearDown(self):
        shutil.rmtree(self.working_dir)

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_init_with_arguments(self, mock_generator):
        self.assertEquals(self.context.root_attributes, self.attributes)
        self.assertEquals(self.context.root_tag, 'metadata')

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_init_with_no_properties(self, mock_generator):
        self.context = XmlFileContext(os.path.join(self.working_dir, 'test.xml'),
                                      self.tag)
        self.assertEquals(self.context.root_attributes, {})
        self.assertEquals(self.context.root_tag, 'metadata')

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_open_metadata_file_handle(self, mock_generator):
        self.context._open_metadata_file_handle()
        mock_generator.assert_called_once_with(self.context.metadata_file_handle, 'UTF-8')

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_write_file_header(self, mock_generator):
        self.context._open_metadata_file_handle()
        self.context._write_file_header()
        mock_generator.return_value.startDocument.assert_called_once()
        mock_generator.return_value.startElement.assert_called_once_with(self.tag, self.attributes)

    @patch('pulp.plugins.util.metadata_writer.XMLGenerator')
    def test_write_file_footer(self, mock_generator):
        self.context._open_metadata_file_handle()
        self.context._write_file_footer()
        mock_generator.return_value.endElement.assert_called_once_with(self.tag)
        mock_generator.return_value.endDocument.assert_called_once()
Exemple #4
0
 def test_init_with_no_properties(self, mock_generator):
     self.context = XmlFileContext(
         os.path.join(self.working_dir, 'test.xml'), self.tag)
     self.assertEquals(self.context.root_attributes, {})
     self.assertEquals(self.context.root_tag, 'metadata')
 def test_init_with_no_properties(self, mock_generator):
     self.context = XmlFileContext(os.path.join(self.working_dir, 'test.xml'),
                                   self.tag)
     self.assertEquals(self.context.root_attributes, {})
     self.assertEquals(self.context.root_tag, 'metadata')
 def setUp(self):
     self.working_dir = tempfile.mkdtemp()
     self.tag = 'metadata'
     self.attributes = {'packages': '30'}
     self.context = XmlFileContext(os.path.join(self.working_dir, 'test.xml'),
                                   self.tag, self.attributes)