MCPcopy
hub / github.com/docker/docker-py / test_lifecycle

Method test_lifecycle

tests/integration/context_api_test.py:14–47  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

12
13class ContextLifecycleTest(BaseAPIIntegrationTest):
14 def test_lifecycle(self):
15 assert ContextAPI.get_context().Name == "default"
16 assert not ContextAPI.get_context("test")
17 assert ContextAPI.get_current_context().Name == "default"
18
19 dirpath = tempfile.mkdtemp()
20 ca = tempfile.NamedTemporaryFile(
21 prefix=os.path.join(dirpath, "ca.pem"), mode="r")
22 cert = tempfile.NamedTemporaryFile(
23 prefix=os.path.join(dirpath, "cert.pem"), mode="r")
24 key = tempfile.NamedTemporaryFile(
25 prefix=os.path.join(dirpath, "key.pem"), mode="r")
26
27 # create context 'test
28 docker_tls = TLSConfig(
29 client_cert=(cert.name, key.name),
30 ca_cert=ca.name)
31 ContextAPI.create_context(
32 "test", tls_cfg=docker_tls)
33
34 # check for a context 'test' in the context store
35 assert any(ctx.Name == "test" for ctx in ContextAPI.contexts())
36 # retrieve a context object for 'test'
37 assert ContextAPI.get_context("test")
38 # remove context
39 ContextAPI.remove_context("test")
40 with pytest.raises(errors.ContextNotFound):
41 ContextAPI.inspect_context("test")
42 # check there is no 'test' context in store
43 assert not ContextAPI.get_context("test")
44
45 ca.close()
46 key.close()
47 cert.close()
48
49 def test_context_remove(self):
50 ContextAPI.create_context("test")

Callers

nothing calls this directly

Calls 9

TLSConfigClass · 0.90
get_contextMethod · 0.80
get_current_contextMethod · 0.80
joinMethod · 0.80
create_contextMethod · 0.80
contextsMethod · 0.80
remove_contextMethod · 0.80
inspect_contextMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected