def test_get_content_unit_resource_view_missing_content(self, mock_factory, mock_resp): """ Test ContentUnitResourceView when the requested unit is not found. """ mock_cqm = mock.MagicMock() mock_cqm.get_content_unit_by_id.side_effect = MissingResource() mock_factory.content_query_manager.return_value = mock_cqm request = mock.MagicMock() content_unit_resource_view = ContentUnitResourceView() response = content_unit_resource_view.get(request, 'mock_type', 'mock_unit') msg = _('No content unit resource: mock_unit') mock_resp.assert_called_once_with(msg, response_class=HttpResponseNotFound) self.assertTrue(response is mock_resp.return_value)
def test_get_content_unit_resource_view(self, mock_factory, mock_serializers, mock_resp): """ Test ContentUnitResourceView when the requested unit is found. """ mock_cqm = mock.MagicMock() mock_cqm.get_content_unit_by_id.return_value = {} mock_factory.content_query_manager.return_value = mock_cqm request = mock.MagicMock() mock_serializers.content_unit_obj.return_value = {} mock_serializers.content_unit_child_link_objs.return_value = {'child': 1} content_unit_resource_view = ContentUnitResourceView() response = content_unit_resource_view.get(request, 'mock_type', 'mock_unit') expected_content = {'children': {'child': 1}} mock_resp.assert_called_once_with(expected_content) self.assertTrue(response is mock_resp.return_value)