File: test_secrets.py

package info (click to toggle)
python-podman 5.4.0.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 1,140 kB
  • sloc: python: 7,532; makefile: 82; sh: 75
file content (52 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Secrets integration tests."""

import random
import unittest
import uuid

from podman import PodmanClient
from podman.errors import NotFound
from podman.tests.integration import base


class SecretsIntegrationTest(base.IntegrationTest):
    """Secrets call integration test"""

    def setUp(self):
        super().setUp()

        self.client = PodmanClient(base_url=self.socket_uri)
        self.addCleanup(self.client.close)

    def test_secret_crud(self):
        """Test Secret CRUD."""

        random_string = f"{random.getrandbits(160):x}"
        secret_payload = uuid.uuid4().bytes

        with self.subTest("Create"):
            secret = self.client.secrets.create(f"secret_{random_string}", secret_payload)
            self.assertGreater(len(secret.id), 0)
            self.assertGreater(len(secret.name), 0)
            self.assertTrue(self.client.secrets.exists(secret.id))

        with self.subTest("Inspect"):
            actual = self.client.secrets.get(secret.id)
            self.assertEqual(secret.id, actual.id)

        self.assertTrue(self.client.secrets.exists(secret.name))

        with self.subTest("List"):
            report = self.client.secrets.list()
            ids = [i.id for i in report]
            self.assertIn(secret.id, ids)

        with self.subTest("Delete"):
            actual.remove()

            with self.assertRaises(NotFound):
                self.client.secrets.get(secret.id)


if __name__ == '__main__':
    unittest.main()