def test_get_orphan_type_subcollection(self, mock_factory, mock_resp, mock_reverse): """ OrphanTypeSubCollection should return a response from a list of dicts, one for each orphan. """ mock_orphan_manager = mock.MagicMock() mock_orphan_manager.generate_orphans_by_type_with_unit_keys.return_value = [ { '_id': 'orphan1' }, { '_id': 'orphan2' } ] mock_factory.content_orphan_manager.return_value = mock_orphan_manager request = mock.MagicMock() mock_reverse.return_value = '/mock/path/' orphan_type_subcollection = OrphanTypeSubCollectionView() response = orphan_type_subcollection.get(request, 'mock_type') expected_content = [{ '_id': 'orphan1', '_href': '/mock/path/' }, { '_id': 'orphan2', '_href': '/mock/path/' }] mock_resp.assert_called_once_with(expected_content) self.assertTrue(response is mock_resp.return_value)
def test_delete_unknown_type(self, mock_get_unit_key_fields): mock_get_unit_key_fields.side_effect = ValueError request = mock.MagicMock() orphan_type_subcollection = OrphanTypeSubCollectionView() self.assertRaises(MissingResource, orphan_type_subcollection.delete, request, 'mock_type')
def test_delete_orphan_type_subcollection(self, mock_orphan_manager): """ Delete orphans should be called with the correct arguments and OperationPostponed is raised. """ request = mock.MagicMock() orphan_type_subcollection = OrphanTypeSubCollectionView() self.assertRaises(OperationPostponed, orphan_type_subcollection.delete, request, 'mock_type') mock_orphan_manager.delete_orphans_by_type.apply_async.assert_called_once_with( ('mock_type', ), tags=['pulp:content_unit:orphans'])
def test_get_orphan_type_subcollection_with_empty_list(self, mock_factory, mock_resp): """ View should return a response with an empty list when there are no orphans of the type. """ mock_orphan_manager = mock.MagicMock() mock_orphan_manager.generate_orphans_by_type_with_unit_keys.return_value = [] mock_factory.content_orphan_manager.return_value = mock_orphan_manager request = mock.MagicMock() orphan_type_subcollection = OrphanTypeSubCollectionView() response = orphan_type_subcollection.get(request, 'mock_type') expected_content = [] mock_resp.assert_called_once_with(expected_content) self.assertTrue(response is mock_resp.return_value)