Passed
Pull Request — master (#3819)
by Alexander
01:36
created

test_checks.test_is_cce_value_valid()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
import os
2
3
import pytest
4
5
import ssg.checks
6
7
8
def test_get_oval_path():
9
    rule_obj = {
10
        'id': 'some_id',
11
        'dir': '/some/random/path/to/a/rule/called/some_id',
12
        'ovals': {
13
            'shared.xml': {}
14
        }
15
    }
16
    correct_path = os.path.join(rule_obj['dir'], "oval", "shared.xml")
17
18
    assert ssg.checks.get_oval_path(rule_obj, "shared") == correct_path
19
    assert ssg.checks.get_oval_path(rule_obj, "shared.xml") == correct_path
20
21
    with pytest.raises(ValueError):
22
        ssg.checks.get_oval_path(rule_obj, "missing")
23
24
    with pytest.raises(ValueError):
25
        ssg.checks.get_oval_path({'id': 'something'}, "missing_dir")
26
27
    with pytest.raises(ValueError):
28
        ssg.checks.get_oval_path({}, "missing_id")
29
30
    with pytest.raises(ValueError):
31
        ssg.checks.get_oval_path({'id': 'present', 'dir': '/'},
32
                                 "missing_ovals")
33
34
35
def test_is_cce_format_valid():
36
    icv = ssg.checks.is_cce_format_valid
37
    assert icv("CCE-27191-6")
38
    assert icv("CCE-7223-7")
39
40
    assert not icv("not-valid")
41
    assert not icv("1234-5")
42
    assert not icv("TBD")
43
    assert not icv("CCE-TBD")
44
    assert not icv("CCE-abcde-f")
45
46
47
def test_is_cce_value_valid():
48
    icv = ssg.checks.is_cce_value_valid
49
    assert icv("CCE-27191-6")
50
    assert icv("CCE-27223-7")
51
52
    assert not icv("1234-5")
53
    assert not icv("12345-6")
54
55