Attempting to mock docker pull
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
I'm trying to write a unit test for pulling a docker image.
Currently, the code must be written with the client performing the pull, like so:
mock_client = mock.Mock(spec=docker.APIClient)
mock_client.pull.side_effect = ImageNotFound('404')
However, this doesn't emulate the way to access the API
Incorrect
client = docker.from_env()
client.pull() # results in Attribute Error
Correct
client = docker.from_env()
client.images.pull('ubuntu:latest')
Am I missing something from the mock_client to arrive at the same call mock_client.images.pull
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the mocking examples in the issue, comparing a mocked docker.APIClient with the docker.from_env() client and its images.pull entry point. Determine how the nested pull call should be represented in a unit test; the issue is complete when the test can exercise the ImageNotFound case through the same access path as the public client.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100