Dataiku API tests

Options
afostor
afostor Registered Posts: 6 ✭✭✭✭

Hi,

I would like to know if it is possible to write unit tests to a Dataiku API code (in Python) using the API Designer, in order to check if it works according to the desired functionality before the API is deployed.

Thanks


Operating system used: Windows

Tagged:

Best Answer

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,209 Dataiker
    edited July 17 Answer ✓
    Options

    Hi @afostor
    ,
    There is no specific way to do this in the API endpoint. Usually testing is done using the test queries in API Designer directly.

    If you want to perform additional test, you can write a unit test directly in the API endpoint code directly and only invoke this when using param perform_test= true.

    import unittest
    import traceback
    
    # Insert here initialization code
    class TestApiPyFunction(unittest.TestCase):
    
        def test_api_py_function(self):
            # Test case 1 pass
            result = api_py_function(2, 3, 4)
            self.assertEqual(result, 2 + 3 * 4)  # Expected: 2 + 3 * 4 = 14
    
            # Test case 2 (Intentional failure)
            result = api_py_function(0, 5, 10)
            self.assertEqual(result, 0 + 5 * 10 + 1)  # Expected: 0 + 5 * 10 + 1 = 51
    
     
            return "All tests passed successfully."
    
    def api_py_function(param1, param2, param3, perform_test=False):
        result = param1 + param2 * param3
        if perform_test:
            try:
                # Run the test cases if perform_test is True
                # The test cases are defined below in the TestApiPyFunction class
                test_result = TestApiPyFunction().test_api_py_function()
            except AssertionError as e:
                tb = traceback.format_exc()
                return result, tb
            return result, "All tests passed successfully."
        return result
    
    

Answers

  • afostor
    afostor Registered Posts: 6 ✭✭✭✭
    Options

    Thanks, I will try this way.

  • vaibhav
    vaibhav Registered Posts: 5
    Options

    Hello Team,

    We have created an endpoint URL and have exposed our model in Dataiku for API testing , now we are able to send one transaction at a time and fetch predictions accordingly , but when i pass multiple transactions or say 2 at a time it gives me error -errorType":"com.dataiku.common.server.DKUControllerBase$MalformedRequestException","message":"Could not parse a SinglePredictionQuery from request body , when i searched about it it tells me that Dataiku endpoint is expecting a single prediction query but is receiving multiple queries. How can this be addressed as we have a requiredment to pass bulk transactions with help of API at a time and model should predict accordingly.. Hope somebody helps out here..would be really helpful..

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,726 Neuron
    Options

    Please start a new thread. This conversation has been marked as Solved already and your problem is different than the initial post.

Setup Info
    Tags
      Help me…