File: testing.py

package info (click to toggle)
python-pylxd 2.2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 820 kB
  • sloc: python: 7,258; sh: 104; makefile: 21
file content (40 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download
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
import unittest

import mock_services

from pylxd.client import Client
from pylxd.tests import mock_lxd


def requires_ws4py(f):
    """Marks a test as requiring ws4py.

    As ws4py is an optional dependency, some tests should
    be skipped, as they won't run properly if ws4py is not
    installed.
    """
    try:
        import ws4py  # NOQA
        return f
    except ImportError:
        return unittest.skip('ws4py is not installed')(f)


class PyLXDTestCase(unittest.TestCase):
    """A test case for handling mocking of LXD services."""

    def setUp(self):
        mock_services.update_http_rules(mock_lxd.RULES)
        mock_services.start_http_mock()

        self.client = Client(endpoint='http://pylxd.test')

    def tearDown(self):
        mock_services.stop_http_mock()

    def add_rule(self, rule):
        """Add a rule to the mock LXD service."""
        mock_services.update_http_rules([rule])

    def add_rules(self, rules):
        mock_services.update_http_rules(rules)