Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22484

Mock output binding Azure function python

$
0
0

I want to create a unit test for my Azure Functions in Python using unittest. I am following the example in https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#unit-testing , but I have added a blob output binding to my Http Trigger function, which I do not know how to mock when manually calling my function.

This is my function.json:

{"scriptFile": "__init__.py","bindings": [    {"authLevel": "function","type": "httpTrigger","direction": "in","name": "req","methods": ["post"      ],"route" : "normalize"    },    {"type": "http","direction": "out","name": "$return"    },    {"name": "todb","type": "blob","direction": "out","path": "carga-db/web_{rand-guid}.csv","connection": "bbdstorage_STORAGE"    }  ]}

And this is my TestCase class:

import unittestimport azure.functions as funcfrom web_api import mainclass TestFunction(unittest.TestCase):    def test_my_function(self):        # Construct a mock HTTP request.        req = func.HttpRequest(            method='POST',            body=None,            url='/api/normalize')        # Call the function.        resp = main(req, #what to put here?)        # Check the output.        self.assertEqual(            resp.get_body(),            b'Hello Test',        )

Viewing all articles
Browse latest Browse all 22484

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>