turbaszek commented on pull request #9950: URL: https://github.com/apache/airflow/pull/9950#issuecomment-663113258
Sure no, problem! Here are existing tests for WasbHook: https://github.com/apache/airflow/blob/master/tests/providers/microsoft/azure/hooks/test_wasb.py and that is the place where you should add your test. Now, let's consider this existing test: https://github.com/apache/airflow/blob/ef98edf4da2d9b74d5cf5b21e81577b3151edb79/tests/providers/microsoft/azure/hooks/test_wasb.py#L119-L127 First of all we are using [mock library](https://docs.python.org/3/library/unittest.mock.html) to mock the behaviour of `BlockBlobService`. By doing this we assume that `BlockBlobService` works right (it's Azure stuff not ours) and all we have to check is that we use it right. By that it mostly means that we properly pass arguments. In this line: https://github.com/apache/airflow/blob/ef98edf4da2d9b74d5cf5b21e81577b3151edb79/tests/providers/microsoft/azure/hooks/test_wasb.py#L122 we create mocked instance of `BlockBlobService` (think about `return_value` as a result of calling `BlockBlobService()`). Next we create hook instance and we call the method: https://github.com/apache/airflow/blob/ef98edf4da2d9b74d5cf5b21e81577b3151edb79/tests/providers/microsoft/azure/hooks/test_wasb.py#L123-L124 No magic here, just simple invocation 👌 Then we call this magic thing: https://github.com/apache/airflow/blob/ef98edf4da2d9b74d5cf5b21e81577b3151edb79/tests/providers/microsoft/azure/hooks/test_wasb.py#L125-L127 In this way we asserts that `BlockBlobService().get_blob_to_path` method was called with those arguments: `'container', 'blob', 'path', max_connections=1`. As you can see, those are same as the one used in ` hook.get_file('path', 'container', 'blob', max_connections=1)` And that's it, we checked that arguments of `WasbHook.get_file` are properly passed to `BlockBlobService.get_blob_to_path`. You have to create similar test. I encourage you to take a look at the mock package to better understand how it works - it will help you in future 💪 Feel free to ask in case of any questions 👌 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
