docker / docker/docker-py

Attempting to mock docker pull

Open
#2,895 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.