Completed
Push — master ( 185d69...37094f )
by
unknown
18s
created

tests.test_gmp_create_task   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A GMPCreateTaskCommandTestCase.test_single_alert_correct_cmd() 0 15 1
A GMPCreateTaskCommandTestCase.test_without_alert_correct_cmd() 0 14 1
A GMPCreateTaskCommandTestCase.setUp() 0 2 1
A GMPCreateTaskCommandTestCase.test_multiple_alerts_correct_cmd() 0 20 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
# Copyright (C) 2018 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
import unittest
20
21
from gmp.xml import GmpCommandFactory
22
23
24
class GMPCreateTaskCommandTestCase(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
25
26
    TASK_NAME = "important task"
27
    CONFIG_ID = "cd0641e7-40b8-4e2c-811e-6b39d6d4b904"
28
    TARGET_ID = '267a3405-e84a-47da-97b2-5fa0d2e8995e'
29
    SCANNER_ID = 'b64c81b2-b9de-11e3-a2e9-406186ea4fc5'
30
    ALERT_ID = '3ab38c6a-30ac-407a-98db-ad6e74c98b9a'
31
    COMMENT = 'this task has been created for test purposes'
32
33
    def setUp(self):
34
        self.gmp = GmpCommandFactory()
35
36
    def test_without_alert_correct_cmd(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
37
        cmd = self.gmp.create_task_command(
38
            self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID,
39
            comment=self.COMMENT)
40
41
        self.assertEqual(
42
            '<create_task>'
43
            '<name>{0}</name>'
44
            '<comment>{1}</comment>'
45
            '<config id="{2}"/><target id="{3}"/><scanner id="{4}"/>'
46
            '</create_task>'.format(self.TASK_NAME, self.COMMENT,
47
                                    self.CONFIG_ID, self.TARGET_ID,
48
                                    self.SCANNER_ID),
49
            cmd)
50
51
    def test_single_alert_correct_cmd(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
52
        cmd = self.gmp.create_task_command(
53
            self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID,
54
            self.ALERT_ID, self.COMMENT)
55
56
        self.assertEqual(
57
            '<create_task>'
58
            '<name>{0}</name>'
59
            '<comment>{1}</comment>'
60
            '<config id="{2}"/><target id="{3}"/><scanner id="{4}"/>'
61
            '<alert id="{5}"/>'
62
            '</create_task>'.format(self.TASK_NAME, self.COMMENT,
63
                                    self.CONFIG_ID, self.TARGET_ID,
64
                                    self.SCANNER_ID, self.ALERT_ID),
65
            cmd)
66
67
    def test_multiple_alerts_correct_cmd(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_multiple_alerts_correct_cmd does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
68
        alert_id2 = 'fb3d6f82-d706-4f99-9e53-d7d85257e25f'
69
        alert_id3 = 'a33864a9-d3fd-44b3-8717-972bfb01dfcf'
70
        alert_ids = [self.ALERT_ID, alert_id2, alert_id3]
71
72
        cmd = self.gmp.create_task_command(
73
            self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID,
74
            alert_ids, self.COMMENT)
75
76
        self.assertEqual(
77
            '<create_task>'
78
            '<name>{0}</name>'
79
            '<comment>{1}</comment>'
80
            '<config id="{2}"/><target id="{3}"/><scanner id="{4}"/>'
81
            '<alert id="{5}"/><alert id="{6}"/><alert id="{7}"/>'
82
            '</create_task>'.format(self.TASK_NAME, self.COMMENT,
83
                                    self.CONFIG_ID, self.TARGET_ID,
84
                                    self.SCANNER_ID, self.ALERT_ID,
85
                                    alert_id2, alert_id3),
86
            cmd)
87
88
89
if __name__ == '__main__':
90
    unittest.main()
91