File: test_node.py

package info (click to toggle)
python-jenkinsapi 0.3.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,500 kB
  • sloc: python: 10,001; xml: 50; makefile: 31; sh: 26
file content (132 lines) | stat: -rw-r--r-- 4,014 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import pytest
from jenkinsapi.node import Node


DATA = {
    "actions": [],
    "displayName": "bobnit",
    "executors": [{}],
    "icon": "computer.png",
    "idle": True,
    "jnlpAgent": False,
    "launchSupported": True,
    "loadStatistics": {},
    "manualLaunchAllowed": True,
    "monitorData": {
        "hudson.node_monitors.SwapSpaceMonitor": {
            "availablePhysicalMemory": 7681417216,
            "availableSwapSpace": 12195983360,
            "totalPhysicalMemory": 8374497280,
            "totalSwapSpace": 12195983360,
        },
        "hudson.node_monitors.ArchitectureMonitor": "Linux (amd64)",
        "hudson.node_monitors.ResponseTimeMonitor": {"average": 64},
        "hudson.node_monitors.TemporarySpaceMonitor": {
            "path": "/tmp",
            "size": 250172776448,
        },
        "hudson.node_monitors.DiskSpaceMonitor": {
            "path": "/home/sal/jenkins",
            "size": 170472026112,
        },
        "hudson.node_monitors.ClockMonitor": {"diff": 6736},
    },
    "numExecutors": 1,
    "offline": False,
    "offlineCause": None,
    "oneOffExecutors": [],
    "temporarilyOffline": False,
}


@pytest.fixture(scope="function")
def node(monkeypatch, mocker):
    def fake_poll(cls, tree=None):  # pylint: disable=unused-argument
        return DATA

    monkeypatch.setattr(Node, "_poll", fake_poll)
    jenkins = mocker.MagicMock()

    return Node(jenkins, "http://foo:8080", "bobnit", {})


def test_repr(node):
    # Can we produce a repr string for this object
    repr(node)


def test_name(node):
    with pytest.raises(AttributeError):
        node.id()
    assert node.name == "bobnit"


def test_online(node):
    assert node.is_online() is True


def test_available_physical_memory(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.SwapSpaceMonitor"]
    expected_value = monitor["availablePhysicalMemory"]
    assert node.get_available_physical_memory() == expected_value


def test_available_swap_space(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.SwapSpaceMonitor"]
    expected_value = monitor["availableSwapSpace"]
    assert node.get_available_swap_space() == expected_value


def test_total_physical_memory(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.SwapSpaceMonitor"]
    expected_value = monitor["totalPhysicalMemory"]
    assert node.get_total_physical_memory() == expected_value


def test_total_swap_space(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.SwapSpaceMonitor"]
    expected_value = monitor["totalSwapSpace"]
    assert node.get_total_swap_space() == expected_value


def test_workspace_path(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.DiskSpaceMonitor"]
    expected_value = monitor["path"]
    assert node.get_workspace_path() == expected_value


def test_workspace_size(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.DiskSpaceMonitor"]
    expected_value = monitor["size"]
    assert node.get_workspace_size() == expected_value


def test_temp_path(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.TemporarySpaceMonitor"]
    expected_value = monitor["path"]
    assert node.get_temp_path() == expected_value


def test_temp_size(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.TemporarySpaceMonitor"]
    expected_value = monitor["size"]
    assert node.get_temp_size() == expected_value


def test_architecture(node):
    expected_value = DATA["monitorData"][
        "hudson.node_monitors.ArchitectureMonitor"
    ]
    assert node.get_architecture() == expected_value


def test_response_time(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.ResponseTimeMonitor"]
    expected_value = monitor["average"]
    assert node.get_response_time() == expected_value


def test_clock_difference(node):
    monitor = DATA["monitorData"]["hudson.node_monitors.ClockMonitor"]
    expected_value = monitor["diff"]
    assert node.get_clock_difference() == expected_value