Code: Select all
@pytest.fixture()
def mock_dataiku(mocker):
# Mock Dataiku client and project
mock_client = MagicMock()
mock_project = MagicMock()
mocker.patch('dataiku.api_client', return_value=mock_client)
mock_client.get_project.return_value = mock_project
return mock_project
def test_cleanse_existing_variable(mock_dataiku):
# Set up project variables
mock_dataiku.get_variables.return_value = {
"local": {"var1": "old_value", "comment": "some_comment"}
}
cleanse(["var1", "comment"])
# Check if variables were set to the default value
expected_variables = {"local": {"var1": "-1", "comment": ""} }
mock_dataiku.set_variables.assert_called_with(expected_variables)
class test_cleanse(unittest.TestCase):
Code: Select all
def __init__(self):
# Mock Dataiku client and project
mock_client = MagicMock()
mock_project = MagicMock()
mocker.patch('dataiku.api_client', return_value=mock_client)
mock_client.get_project.return_value = mock_project
#return mock_project
self.mocker=mock.project