Completed
Push — master ( 05d15c...6774c8 )
by
unknown
15s queued 10s
created

tests.transforms.test_check_command_transform   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A CheckCommandTransformTestCase.test_no_status_transform() 0 5 2
A CheckCommandTransformTestCase.test_success_response() 0 9 1
A CheckCommandTransformTestCase.test_no_success_status_transform() 0 11 2
1
# -*- coding: utf-8 -*-
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 lxml import etree
22
23
from gvm.errors import GvmError
24
from gvm.transforms import CheckCommandTransform
25
26
27
class CheckCommandTransformTestCase(unittest.TestCase):
28
29
    def test_no_status_transform(self):
30
        transform = CheckCommandTransform()
31
32
        with self.assertRaises(GvmError):
33
            transform('<foo/')
34
35
    def test_no_success_status_transform(self):
36
        transform = CheckCommandTransform()
37
38
        root = etree.Element('foo_response')
39
        root.set('status', '400')
40
        root.set('status_text', 'Foo error')
41
42
        response = etree.tostring(root).decode('utf-8')
43
44
        with self.assertRaises(GvmError):
45
            transform(response)
46
47
    def test_success_response(self):
48
        transform = CheckCommandTransform()
49
50
        root = etree.Element('foo_response')
51
        root.set('status', '200')
52
53
        response = etree.tostring(root).decode('utf-8')
54
55
        self.assertEqual(transform(response), '<foo_response status="200"/>')
56