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_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)
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)
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)