Python 3.7. I'm trying to unit test the function below:
def is_json_clean():
# function for is_json_clean here, returns bool
def json_function(blob, raw_bucket, lake_bucket):
data_string = blob.download_as_bytes()
data = json.loads(data_string)
if is_json_clean(data) is True:
raw_bucket.copy_blob(blob, lake_bucket)
I'm pretty new to mock patches, and could use an example here! How could I use mock.patch or something similar to get that if statement with my is_json_clean()
function to return True so that I can assert that the copy_blob function was called? I thought I could make a patch like:
@mock.patch.object(imported_module, "is_json_clean", return_value=True)
def test_json_function(mock):
# rest of the test function
# including assert statement for the copy_blob function
but how then would I insert this into my test to assert my copy_blob function? I know that quite a few unit test-related questions are out there, but I haven't found exactly the answer to my question yet (like I said, I'm pretty new). Any help is appreciated. Thank you!