diff options
-rw-r--r-- | test/apiv2/rest_api/test_rest_v2_0_0.py | 49 | ||||
-rw-r--r-- | test/python/__init__.py | 0 | ||||
-rw-r--r-- | test/python/docker/__init__.py | 14 | ||||
-rw-r--r-- | test/python/docker/compat/README.md (renamed from test/python/docker/README.md) | 12 | ||||
-rw-r--r-- | test/python/docker/compat/__init__.py | 0 | ||||
-rw-r--r-- | test/python/docker/compat/common.py (renamed from test/python/docker/common.py) | 6 | ||||
-rw-r--r-- | test/python/docker/compat/constant.py (renamed from test/python/docker/constant.py) | 0 | ||||
-rw-r--r-- | test/python/docker/compat/test_containers.py (renamed from test/python/docker/test_containers.py) | 11 | ||||
-rw-r--r-- | test/python/docker/compat/test_images.py (renamed from test/python/docker/test_images.py) | 9 | ||||
-rw-r--r-- | test/python/docker/compat/test_system.py (renamed from test/python/docker/test_system.py) | 3 | ||||
-rw-r--r-- | test/python/requirements.txt | 6 |
11 files changed, 77 insertions, 33 deletions
diff --git a/test/apiv2/rest_api/test_rest_v2_0_0.py b/test/apiv2/rest_api/test_rest_v2_0_0.py index 05c24f2ea..8a78f5185 100644 --- a/test/apiv2/rest_api/test_rest_v2_0_0.py +++ b/test/apiv2/rest_api/test_rest_v2_0_0.py @@ -64,7 +64,9 @@ class TestApi(unittest.TestCase): super().setUpClass() TestApi.podman = Podman() - TestApi.service = TestApi.podman.open("system", "service", "tcp:localhost:8080", "--time=0") + TestApi.service = TestApi.podman.open( + "system", "service", "tcp:localhost:8080", "--time=0" + ) # give the service some time to be ready... time.sleep(2) @@ -241,7 +243,9 @@ class TestApi(unittest.TestCase): def test_post_create_compat(self): """Create network and connect container during create""" - net = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": "TestNetwork"}) + net = requests.post( + PODMAN_URL + "/v1.40/networks/create", json={"Name": "TestNetwork"} + ) self.assertEqual(net.status_code, 201, net.text) create = requests.post( @@ -450,11 +454,15 @@ class TestApi(unittest.TestCase): self.assertIn(k, o) def test_network_compat(self): - name = "Network_" + "".join(random.choice(string.ascii_letters) for i in range(10)) + name = "Network_" + "".join( + random.choice(string.ascii_letters) for i in range(10) + ) # Cannot test for 0 existing networks because default "podman" network always exists - create = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": name}) + create = requests.post( + PODMAN_URL + "/v1.40/networks/create", json={"Name": name} + ) self.assertEqual(create.status_code, 201, create.content) obj = json.loads(create.content) self.assertIn(type(obj), (dict,)) @@ -484,8 +492,12 @@ class TestApi(unittest.TestCase): self.assertEqual(inspect.status_code, 404, inspect.content) # network prune - prune_name = "Network_" + "".join(random.choice(string.ascii_letters) for i in range(10)) - prune_create = requests.post(PODMAN_URL + "/v1.40/networks/create", json={"Name": prune_name}) + prune_name = "Network_" + "".join( + random.choice(string.ascii_letters) for i in range(10) + ) + prune_create = requests.post( + PODMAN_URL + "/v1.40/networks/create", json={"Name": prune_name} + ) self.assertEqual(create.status_code, 201, prune_create.content) prune = requests.post(PODMAN_URL + "/v1.40/networks/prune") @@ -493,9 +505,10 @@ class TestApi(unittest.TestCase): obj = json.loads(prune.content) self.assertTrue(prune_name in obj["NetworksDeleted"]) - def test_volumes_compat(self): - name = "Volume_" + "".join(random.choice(string.ascii_letters) for i in range(10)) + name = "Volume_" + "".join( + random.choice(string.ascii_letters) for i in range(10) + ) ls = requests.get(PODMAN_URL + "/v1.40/volumes") self.assertEqual(ls.status_code, 200, ls.content) @@ -511,7 +524,9 @@ class TestApi(unittest.TestCase): for k in required_keys: self.assertIn(k, obj) - create = requests.post(PODMAN_URL + "/v1.40/volumes/create", json={"Name": name}) + create = requests.post( + PODMAN_URL + "/v1.40/volumes/create", json={"Name": name} + ) self.assertEqual(create.status_code, 201, create.content) # See https://docs.docker.com/engine/api/v1.40/#operation/VolumeCreate @@ -688,15 +703,21 @@ class TestApi(unittest.TestCase): """Verify issue #8865""" pod_name = list() - pod_name.append("Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10))) - pod_name.append("Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10))) + pod_name.append( + "Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10)) + ) + pod_name.append( + "Pod_" + "".join(random.choice(string.ascii_letters) for i in range(10)) + ) r = requests.post( _url("/pods/create"), json={ "name": pod_name[0], "no_infra": False, - "portmappings": [{"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89}], + "portmappings": [ + {"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89} + ], }, ) self.assertEqual(r.status_code, 201, r.text) @@ -715,7 +736,9 @@ class TestApi(unittest.TestCase): json={ "name": pod_name[1], "no_infra": False, - "portmappings": [{"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89}], + "portmappings": [ + {"host_ip": "127.0.0.1", "host_port": 8889, "container_port": 89} + ], }, ) self.assertEqual(r.status_code, 201, r.text) diff --git a/test/python/__init__.py b/test/python/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test/python/__init__.py diff --git a/test/python/docker/__init__.py b/test/python/docker/__init__.py index 351834316..da5630eac 100644 --- a/test/python/docker/__init__.py +++ b/test/python/docker/__init__.py @@ -8,7 +8,7 @@ import tempfile from docker import DockerClient -from test.python.docker import constant +from .compat import constant class Podman(object): @@ -39,7 +39,9 @@ class Podman(object): self.cmd.append("--root=" + os.path.join(self.anchor_directory, "crio")) self.cmd.append("--runroot=" + os.path.join(self.anchor_directory, "crio-run")) - os.environ["REGISTRIES_CONFIG_PATH"] = os.path.join(self.anchor_directory, "registry.conf") + os.environ["REGISTRIES_CONFIG_PATH"] = os.path.join( + self.anchor_directory, "registry.conf" + ) p = configparser.ConfigParser() p.read_dict( { @@ -51,10 +53,14 @@ class Podman(object): with open(os.environ["REGISTRIES_CONFIG_PATH"], "w") as w: p.write(w) - os.environ["CNI_CONFIG_PATH"] = os.path.join(self.anchor_directory, "cni", "net.d") + os.environ["CNI_CONFIG_PATH"] = os.path.join( + self.anchor_directory, "cni", "net.d" + ) os.makedirs(os.environ["CNI_CONFIG_PATH"], exist_ok=True) self.cmd.append("--cni-config-dir=" + os.environ["CNI_CONFIG_PATH"]) - cni_cfg = os.path.join(os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist") + cni_cfg = os.path.join( + os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist" + ) # json decoded and encoded to ensure legal json buf = json.loads( """ diff --git a/test/python/docker/README.md b/test/python/docker/compat/README.md index c10fd636d..50796d66b 100644 --- a/test/python/docker/README.md +++ b/test/python/docker/compat/README.md @@ -13,26 +13,26 @@ To run the tests locally in your sandbox (Fedora 32,33): ### Run the entire test suite +All commands are run from the root of the repository. + ```shell -# python3 -m unittest discover test/python/docker +# python3 -m unittest discover -s test/python/docker ``` Passing the -v option to your test script will instruct unittest.main() to enable a higher level of verbosity, and produce detailed output: ```shell -# python3 -m unittest -v discover test/python/docker +# python3 -m unittest -v discover -s test/python/docker ``` ### Run a specific test class ```shell -# cd test/python/docker -# python3 -m unittest -v tests.test_images +# python3 -m unittest -v test.python.docker.compat.test_images.TestImages ``` ### Run a specific test within the test class ```shell -# cd test/python/docker -# python3 -m unittest tests.test_images.TestImages.test_import_image +# python3 -m unittest test.python.docker.compat.test_images.TestImages.test_tag_valid_image ``` diff --git a/test/python/docker/compat/__init__.py b/test/python/docker/compat/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test/python/docker/compat/__init__.py diff --git a/test/python/docker/common.py b/test/python/docker/compat/common.py index 11f512495..bdc67c287 100644 --- a/test/python/docker/common.py +++ b/test/python/docker/compat/common.py @@ -1,10 +1,12 @@ from docker import DockerClient -from test.python.docker import constant +from test.python.docker.compat import constant def run_top_container(client: DockerClient): - c = client.containers.create(constant.ALPINE, command="top", detach=True, tty=True, name="top") + c = client.containers.create( + constant.ALPINE, command="top", detach=True, tty=True, name="top" + ) c.start() return c.id diff --git a/test/python/docker/constant.py b/test/python/docker/compat/constant.py index 892293c97..892293c97 100644 --- a/test/python/docker/constant.py +++ b/test/python/docker/compat/constant.py diff --git a/test/python/docker/test_containers.py b/test/python/docker/compat/test_containers.py index 337cacd5c..be70efa67 100644 --- a/test/python/docker/test_containers.py +++ b/test/python/docker/compat/test_containers.py @@ -5,7 +5,8 @@ import unittest from docker import DockerClient, errors -from test.python.docker import Podman, common, constant +from test.python.docker import Podman +from test.python.docker.compat import common, constant class TestContainers(unittest.TestCase): @@ -87,9 +88,11 @@ class TestContainers(unittest.TestCase): self.assertEqual(len(containers), 2) def test_start_container_with_random_port_bind(self): - container = self.client.containers.create(image=constant.ALPINE, - name="containerWithRandomBind", - ports={'1234/tcp': None}) + container = self.client.containers.create( + image=constant.ALPINE, + name="containerWithRandomBind", + ports={"1234/tcp": None}, + ) containers = self.client.containers.list(all=True) self.assertTrue(container in containers) diff --git a/test/python/docker/test_images.py b/test/python/docker/compat/test_images.py index f2b6a5190..842e38f31 100644 --- a/test/python/docker/test_images.py +++ b/test/python/docker/compat/test_images.py @@ -7,7 +7,8 @@ import unittest from docker import DockerClient, errors -from test.python.docker import Podman, common, constant +from test.python.docker import Podman +from test.python.docker.compat import common, constant class TestImages(unittest.TestCase): @@ -78,7 +79,9 @@ class TestImages(unittest.TestCase): self.assertEqual(len(self.client.images.list()), 2) # List images with filter - self.assertEqual(len(self.client.images.list(filters={"reference": "alpine"})), 1) + self.assertEqual( + len(self.client.images.list(filters={"reference": "alpine"})), 1 + ) def test_search_image(self): """Search for image""" @@ -91,7 +94,7 @@ class TestImages(unittest.TestCase): r = self.client.images.search("bogus/bogus") except: return - self.assertTrue(len(r)==0) + self.assertTrue(len(r) == 0) def test_remove_image(self): """Remove image""" diff --git a/test/python/docker/test_system.py b/test/python/docker/compat/test_system.py index 46b90e5f6..131b18991 100644 --- a/test/python/docker/test_system.py +++ b/test/python/docker/compat/test_system.py @@ -5,7 +5,8 @@ import unittest from docker import DockerClient -from test.python.docker import Podman, common, constant +from test.python.docker import Podman, constant +from test.python.docker.compat import common class TestSystem(unittest.TestCase): diff --git a/test/python/requirements.txt b/test/python/requirements.txt new file mode 100644 index 000000000..ee85bf1d1 --- /dev/null +++ b/test/python/requirements.txt @@ -0,0 +1,6 @@ +docker~=4.4.3 + +requests~=2.20.0 +setuptools~=50.3.2 +python-dateutil~=2.8.1 +PyYAML~=5.4.1 |