Beispiel #1
0
    def test_handle_erratum_with_link(self, mock_link):
        # Setup
        unit_key = {'id': 'test-erratum'}
        metadata = {'a': 'a'}
        config = PluginCallConfiguration({}, {})
        mock_repo = mock.MagicMock()

        mock_conduit = mock.MagicMock()
        inited_unit = Unit(models.Errata.TYPE, unit_key, metadata, None)
        saved_unit = Unit(models.Errata.TYPE, unit_key, metadata, None)
        saved_unit.id = 'ihaveanidnow'
        mock_conduit.init_unit.return_value = inited_unit
        mock_conduit.save_unit.return_value = saved_unit

        # Test
        upload._handle_erratum(mock_repo, models.Errata.TYPE, unit_key, metadata, None,
                               mock_conduit, config)

        # Verify
        mock_conduit.init_unit.assert_called_once_with(models.Errata.TYPE, unit_key,
                                                       metadata, None)
        mock_conduit.save_unit.assert_called_once_with(inited_unit)

        mock_link.assert_called_once()
        self.assertEqual(mock_link.call_args[0][0], mock_conduit)
        self.assertTrue(isinstance(mock_link.call_args[0][1], models.Errata))
        # it is very important that this is the saved_unit, and not the inited_unit,
        # because the underlying link logic requires it to have an "id".
        self.assertTrue(mock_link.call_args[0][2] is saved_unit)
Beispiel #2
0
    def test_handle_erratum_with_link(self, mock_link):
        # Setup
        unit_key = {'id' : 'test-erratum'}
        metadata = {'a' : 'a'}
        config = PluginCallConfiguration({}, {})

        mock_conduit = mock.MagicMock()
        inited_unit = Unit(models.Errata.TYPE, unit_key, metadata, None)
        mock_conduit.init_unit.return_value = inited_unit

        # Test
        upload._handle_erratum(models.Errata.TYPE, unit_key, metadata, None,
                               mock_conduit, config)

        # Verify
        mock_conduit.init_unit.assert_called_once_with(models.Errata.TYPE, unit_key,
                                                       metadata, None)
        mock_conduit.save_unit.assert_called_once()
        saved_unit = mock_conduit.save_unit.call_args[0][0]
        self.assertEqual(inited_unit, saved_unit)

        mock_link.assert_called_once()
        self.assertEqual(mock_link.call_args[0][0], mock_conduit)
        self.assertTrue(isinstance(mock_link.call_args[0][1], models.Errata))
        self.assertEqual(mock_link.call_args[0][2], saved_unit)
Beispiel #3
0
    def test_handle_erratum_no_link(self, mock_link):
        # Setup
        unit_key = {"id": "test-erratum"}
        metadata = {"a": "a"}
        config = PluginCallConfiguration({}, {}, override_config={upload.CONFIG_SKIP_ERRATUM_LINK: True})
        mock_conduit = mock.MagicMock()

        # Test
        upload._handle_erratum(models.Errata.TYPE, unit_key, metadata, None, mock_conduit, config)

        # Verify
        self.assertEqual(0, mock_link.call_count)
Beispiel #4
0
 def test_handle_with_no_link(self, m_update, m_model_by_id, m_repo_ctrl):
     """
     Ensure that erratum uploaded with the skip erratum link flag are not associated.
     """
     unit_key = {'id': 'test-erratum'}
     metadata = {'a': 'a'}
     mock_repo = mock.MagicMock()
     mock_conduit = mock.MagicMock()
     config = PluginCallConfiguration(
         {}, {}, override_config={upload.CONFIG_SKIP_ERRATUM_LINK: True})
     upload._handle_erratum(mock_repo, 'm_type', unit_key, metadata, None,
                            mock_conduit, config)
     self.assertFalse(m_repo_ctrl.associate_single_unit.called)
Beispiel #5
0
    def test_handle_erratum_no_link(self, mock_link):
        # Setup
        unit_key = {'id': 'test-erratum'}
        metadata = {'a': 'a'}
        config = PluginCallConfiguration({}, {},
                                         override_config={upload.CONFIG_SKIP_ERRATUM_LINK: True})
        mock_conduit = mock.MagicMock()

        # Test
        upload._handle_erratum(models.Errata.TYPE, unit_key, metadata, None,
                               mock_conduit, config)

        # Verify
        self.assertEqual(0, mock_link.call_count)
Beispiel #6
0
    def test_handle_with_link(self, m_update, m_model_by_id, m_repo_ctrl):
        """
        Ensure that erratum uploaded without the skip erratum link flag are associated.
        """
        unit_key = {'id': 'test-erratum'}
        metadata = {'a': 'a'}
        mock_repo = mock.MagicMock()
        mock_conduit = mock.MagicMock()
        config = PluginCallConfiguration({}, {})
        m_unit = m_model_by_id().return_value

        upload._handle_erratum(mock_repo, 'm_type', unit_key, metadata, None,
                               mock_conduit, config)
        m_repo_ctrl.associate_single_unit.assert_called_once_with(mock_repo, m_unit)
Beispiel #7
0
    def test_handle_erratum_same_id(self, m_update, m_model_by_id, m_repo_ctrl):
        """
        Ensure that the merge of errata is initiated if the erratum with the same id already exists.
        """
        unit_key = {'id': 'test-erratum'}
        metadata = {'a': 'a'}
        mock_repo = mock.MagicMock()
        mock_conduit = mock.MagicMock()
        config = PluginCallConfiguration({}, {})
        m_unit = m_model_by_id.return_value.objects.filter.return_value.first.return_value

        upload._handle_erratum(mock_repo, 'm_type', unit_key, metadata, None,
                               mock_conduit, config)
        self.assertEqual(m_unit.merge_errata.call_count, 1)
        m_repo_ctrl.associate_single_unit.assert_called_once_with(mock_repo, m_unit)
Beispiel #8
0
    def test_handle_with_link(self, m_update, m_model_by_id, m_repo_ctrl):
        """
        Ensure that erratum uploaded without the skip erratum link flag are associated.
        """
        unit_key = {'id': 'test-erratum'}
        metadata = {'a': 'a'}
        mock_repo = mock.MagicMock()
        mock_conduit = mock.MagicMock()
        config = PluginCallConfiguration({}, {})
        m_model_by_id.return_value.objects.filter.return_value.first.return_value = None
        m_unit = m_model_by_id().return_value

        upload._handle_erratum(mock_repo, 'm_type', unit_key, metadata, None,
                               mock_conduit, config)
        m_repo_ctrl.associate_single_unit.assert_called_once_with(mock_repo, m_unit)