Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stat_object method #21

Closed
ediboc opened this issue Apr 22, 2024 · 5 comments
Closed

Add stat_object method #21

ediboc opened this issue Apr 22, 2024 · 5 comments

Comments

@ediboc
Copy link

ediboc commented Apr 22, 2024

I am using pytest-minio-mock in a project where I need to delete a document but I need to return an error if the document does not exist and for that I use the "stat_object" function. Could this function be added? or how could I do the test?

@oussjarrousse
Copy link
Owner

Hello @ediboc. Yes, stat_object is not implemented yet. However, @cottephi was interested in adding it and I am looking forward for the PR. If I didn't receive a PR by the end of the week. I will start working on it myself or maybe you want to contribute?

@cottephi
Copy link
Contributor

I implemented it in my forked repo, which I changed quite a lot in the mean time. I do not think you will like to review all the changes at once, I am not even sure you would want to have them. I suggest you look at what I did for stat_object, and cherry pick the code. It is line 257 in https://github.com/cottephi/pytest-minio-mock/blob/master/pytest_minio_mock/plugin.py

@ediboc
Copy link
Author

ediboc commented Apr 26, 2024

In the end I did what you can see in the code below, so that it simulates an error in the event that the object is not in the bucket:

def stat_object_side_effect(bucket_name, object_name):  # noqa: ARG001
        if object_name == "missing_id":
            error_code = "NoSuchKey"
            error_message = "The specified key does not exist."
            raise S3Error(error_code, error_message, None, None, None, None)

minio_moc.stat_object = Mock(side_effect=stat_object_side_effect)

@oussjarrousse
Copy link
Owner

oussjarrousse commented Apr 26, 2024

Ok I just finished implementing and adding tests for stat_object()
Check the PR: #28
I am going to publish it later as soon as I am done testing

@oussjarrousse
Copy link
Owner

published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants