def test_get_type_resource_view_nonexistent_type(self, mock_factory): """ Type Resource should raise a MissingResource if the specified type does not exist. """ mock_manager = mock.MagicMock() mock_manager.types.return_value = [{'id': 'mock_type_1'}, {'id': 'mock_type_2'}] mock_factory.plugin_manager.return_value = mock_manager request = mock.MagicMock() type_resource = TypeResourceView() try: type_resource.get(request, 'nonexistent_type') except MissingResource, response: pass
def test_get_type_resource_view_existing_type(self, mock_factory, mock_resp): """ Type Resource should call the seralizer with the appropriate object. """ mock_manager = mock.MagicMock() mock_manager.types.return_value = [{'id': 'mock_type_1'}, {'id': 'mock_type_2'}] mock_factory.plugin_manager.return_value = mock_manager request = mock.MagicMock() request.get_full_path.return_value = '/mock/path/' type_resource = TypeResourceView() type_resource.get(request, 'mock_type_2') expected_content = {'id': 'mock_type_2', '_href': '/mock/path/'} mock_resp.assert_called_once_with(expected_content)
def test_get_type_resource_view_nonexistent_type(self, mock_factory): """ Type Resource should raise a MissingResource if the specified type does not exist. """ mock_manager = mock.MagicMock() mock_manager.types.return_value = [{ 'id': 'mock_type_1' }, { 'id': 'mock_type_2' }] mock_factory.plugin_manager.return_value = mock_manager request = mock.MagicMock() type_resource = TypeResourceView() try: type_resource.get(request, 'nonexistent_type') except MissingResource, response: pass
def test_get_type_resource_view_existing_type(self, mock_factory, mock_resp): """ Type Resource should call the seralizer with the appropriate object. """ mock_manager = mock.MagicMock() mock_manager.types.return_value = [{ 'id': 'mock_type_1' }, { 'id': 'mock_type_2' }] mock_factory.plugin_manager.return_value = mock_manager request = mock.MagicMock() request.get_full_path.return_value = '/mock/path/' type_resource = TypeResourceView() type_resource.get(request, 'mock_type_2') expected_content = {'id': 'mock_type_2', '_href': '/mock/path/'} mock_resp.assert_called_once_with(expected_content)