File: test_plugins.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 (110 lines) | stat: -rw-r--r-- 3,277 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
"""
System tests for `jenkinsapi.plugins` module.
"""

import logging
import pytest
from jenkinsapi_tests.test_utils.random_strings import random_string
from jenkinsapi.plugin import Plugin

log = logging.getLogger(__name__)


def test_plugin_data(jenkins):
    # It takes time to get plugins json from remote
    timeout = jenkins.requester.timeout
    jenkins.requester.timeout = 60
    jenkins.plugins.check_updates_server()
    jenkins.requester.timeout = timeout

    assert "workflow-api" in jenkins.plugins


def test_get_missing_plugin(jenkins):
    plugins = jenkins.get_plugins()
    with pytest.raises(KeyError):
        plugins["lsdajdaslkjdlkasj"]  # this plugin surely does not exist!


def test_get_single_plugin(jenkins):
    plugins = jenkins.get_plugins()
    plugin_name, plugin = next(plugins.iteritems())

    assert isinstance(plugin_name, str)
    assert isinstance(plugin, Plugin)


def test_get_single_plugin_depth_2(jenkins):
    plugins = jenkins.get_plugins(depth=2)
    _, plugin = next(plugins.iteritems())

    assert isinstance(plugin, Plugin)


def test_delete_inexistant_plugin(jenkins):
    with pytest.raises(KeyError):
        del jenkins.plugins[random_string()]


#    def test_install_uninstall_plugin(jenkins):
#        plugin_name = "suppress-stack-trace"
#
#        plugin_dict = {
#            "shortName": plugin_name,
#            "version": "latest",
#        }
#        jenkins.plugins[plugin_name] = Plugin(plugin_dict)
#
#        assert plugin_name in jenkins.plugins
#
#        plugin = jenkins.get_plugins()[plugin_name]
#        assert isinstance(plugin, Plugin)
#        assert plugin.shortName == plugin_name
#
#        del jenkins.plugins[plugin_name]
#        assert jenkins.plugins[plugin_name].deleted
#
#
#    def test_install_multiple_plugins(jenkins):
#        plugin_one_name = "keyboard-shortcuts-plugin"
#        plugin_one_version = "latest"
#        plugin_one = "@".join((plugin_one_name, plugin_one_version))
#        plugin_two = Plugin(
#            {"shortName": "emotional-jenkins-plugin", "version": "latest"}
#        )
#
#        assert isinstance(plugin_two, Plugin)
#
#        plugin_list = [plugin_one, plugin_two]
#
#        jenkins.install_plugins(plugin_list)
#
#        assert plugin_one_name in jenkins.plugins
#        assert plugin_two.shortName in jenkins.plugins
#
#        del jenkins.plugins["keyboard-shortcuts-plugin"]
#        del jenkins.plugins["emotional-jenkins-plugin"]
#
#
#    def test_downgrade_plugin(jenkins):
#        plugin_name = "console-badge"
#        plugin_version = "latest"
#        plugin = Plugin({"shortName": plugin_name, "version": plugin_version})
#
#        assert isinstance(plugin, Plugin)
#
#        # Need to restart when not installing the latest version
#        jenkins.install_plugins([plugin])
#
#        installed_plugin = jenkins.plugins[plugin_name]
#
#        assert installed_plugin.version == "1.1"
#
#        older_plugin = Plugin({"shortName": plugin_name, "version": "1.0"})
#        jenkins.install_plugins(
#            [older_plugin], restart=True, wait_for_reboot=True)
#        installed_older_plugin = jenkins.plugins[plugin_name]
#
#        assert installed_older_plugin.version == "1.0"
#
#        del jenkins.plugins[plugin_name]