Completed
Push — master ( 486e1a...9be8a7 )
by Jaspar
02:33 queued 36s
created

GmpCreateUserTestMixin.test_create_user_with_ifaces()   A

Complexity

Conditions 1

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nop 1
dl 0
loc 25
rs 9.85
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2018-2021 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
from gvm.errors import RequiredArgument
20
21
22
class GmpCreateUserTestMixin:
23
    def test_create_user_missing_name(self):
24
        with self.assertRaises(RequiredArgument):
25
            self.gmp.create_user(name=None)
26
27
        with self.assertRaises(RequiredArgument):
28
            self.gmp.create_user(name='')
29
30
    def test_create_user(self):
31
        self.gmp.create_user(name='foo')
32
33
        self.connection.send.has_been_called_with(
34
            '<create_user>' '<name>foo</name>' '</create_user>'
35
        )
36
37
    def test_create_user_with_password(self):
38
        self.gmp.create_user(name='foo', password='bar')
39
40
        self.connection.send.has_been_called_with(
41
            '<create_user>'
42
            '<name>foo</name>'
43
            '<password>bar</password>'
44
            '</create_user>'
45
        )
46
47
    def test_create_user_with_hosts(self):
48
        self.gmp.create_user(name='foo', hosts=['h1', 'h2'], hosts_allow=True)
49
50
        self.connection.send.has_been_called_with(
51
            '<create_user>'
52
            '<name>foo</name>'
53
            '<hosts allow="1">h1,h2</hosts>'
54
            '</create_user>'
55
        )
56
57
        self.gmp.create_user(name='foo', hosts=['h1', 'h2'])
58
59
        self.connection.send.has_been_called_with(
60
            '<create_user>'
61
            '<name>foo</name>'
62
            '<hosts allow="0">h1,h2</hosts>'
63
            '</create_user>'
64
        )
65
66
        self.gmp.create_user(name='foo', hosts=['h1', 'h2'], hosts_allow=False)
67
68
        self.connection.send.has_been_called_with(
69
            '<create_user>'
70
            '<name>foo</name>'
71
            '<hosts allow="0">h1,h2</hosts>'
72
            '</create_user>'
73
        )
74
75
    def test_create_user_with_ifaces(self):
76
        self.gmp.create_user(name='foo', ifaces=['h1', 'h2'], ifaces_allow=True)
77
78
        self.connection.send.has_been_called_with(
79
            '<create_user>'
80
            '<name>foo</name>'
81
            '<ifaces allow="1">h1,h2</ifaces>'
82
            '</create_user>'
83
        )
84
85
        self.gmp.create_user(name='foo', ifaces=['h1', 'h2'])
86
87
        self.connection.send.has_been_called_with(
88
            '<create_user>'
89
            '<name>foo</name>'
90
            '<ifaces allow="0">h1,h2</ifaces>'
91
            '</create_user>'
92
        )
93
94
        self.gmp.create_user(
95
            name='foo', ifaces=['h1', 'h2'], ifaces_allow=False
96
        )
97
98
        self.connection.send.has_been_called_with(
99
            '<create_user>'
100
            '<name>foo</name>'
101
            '<ifaces allow="0">h1,h2</ifaces>'
102
            '</create_user>'
103
        )
104
105
    def test_create_user_with_role_ids(self):
106
        self.gmp.create_user(name='foo', role_ids=['r1', 'r2'])
107
108
        self.connection.send.has_been_called_with(
109
            '<create_user>'
110
            '<name>foo</name>'
111
            '<role id="r1"/>'
112
            '<role id="r2"/>'
113
            '</create_user>'
114
        )
115