-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_cwe.py
93 lines (58 loc) · 2.33 KB
/
test_cwe.py
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
from typing import List
from cwe import Database, CWECategory, Weakness
import unittest
class TestDatabase(unittest.TestCase):
def setUp(self):
self.db = Database()
def test_cwe_get_id(self):
cwe = self.db.get(15)
self.assertEqual(
cwe.name, "External Control of System or Configuration Setting"
)
def test_database_count(self):
count = self.db.count
self.assertEqual(count, 839)
def test_get_top_25(self):
top_25 = self.db.get_top_25()
self.assertEqual(len(top_25), 25)
def test_weakness_prop_name(self):
cwe = self.db.get(15)
self.assertEqual(
cwe.name, "External Control of System or Configuration Setting"
)
def test_weakness_repr(self):
cwe = self.db.get(15)
self.assertEqual(
str(cwe),
"Weakness(cwe_id=15, name=External Control of System or Configuration Setting)",
)
def test_weakness_get_prop(self):
cwe = self.db.get(15)
self.assertEqual(
cwe.get("name"), "External Control of System or Configuration Setting"
)
def test_weakness_get_prop_that_doesnt_exist(self):
cwe = self.db.get(15)
self.assertEqual(cwe.get("Foo"), None)
def test_weakness_get_prop_that_doesnt_exist_with_default_supplied(self):
cwe = self.db.get(15)
self.assertEqual(cwe.get("Foo", False), False)
def test_weakness_to_dict_returns_dict_type(self):
cwe = self.db.get(15)
self.assertIs(type(cwe.to_dict()), dict)
def test_weakness_to_dict_returns_dict_key(self):
cwe = self.db.get(15)
self.assertEqual(
cwe.to_dict()["name"], "External Control of System or Configuration Setting"
)
def test_cwe_get_category_with_bad_category(self):
with self.assertRaises(KeyError):
self.db.get_category("foo")
def test_cwe_get_software_development_category(self):
cwe: List[Weakness] = self.db.get_category(CWECategory.SOFTWARE_DEVELOPMENT.value)
self.assertEqual(type(cwe), list)
def test_cwe_get_hardware_design_category(self):
cwe: List[Weakness] = self.db.get_category(CWECategory.HARDWARE_DESIGN.value)
self.assertEqual(type(cwe), list)
def test_get_all(self):
data = self.db.get_all()