Skip to content

Commit 3d97879

Browse files
committed
Convert additional classes to EntityTestCase.
1 parent 8b6168e commit 3d97879

12 files changed

+704
-761
lines changed

cybox/test/common/byterun_test.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55

66
from cybox.common import ByteRun, ByteRuns, Hash
77
import cybox.test
8-
9-
10-
class TestByteRun(unittest.TestCase):
11-
12-
def test_round_trip(self):
13-
byterun_dict = {
14-
'offset': 1000,
15-
'file_system_offset': 1024,
16-
'image_offset': 512,
17-
'length': 10,
18-
'hashes': [{'type': Hash.TYPE_MD5,
19-
'simple_hash_value':
20-
'0123456789abcdef0123456789abcdef'}],
21-
'byte_run_data': "helloworld",
22-
}
23-
byterun_dict2 = cybox.test.round_trip_dict(ByteRun, byterun_dict)
24-
self.assertEqual(byterun_dict, byterun_dict2)
8+
from cybox.test import EntityTestCase
9+
10+
11+
class TestByteRun(EntityTestCase, unittest.TestCase):
12+
klass = ByteRun
13+
14+
_full_dict = {
15+
'offset': 1000,
16+
'file_system_offset': 1024,
17+
'image_offset': 512,
18+
'length': 10,
19+
'hashes': [{'type': Hash.TYPE_MD5,
20+
'simple_hash_value':
21+
'0123456789abcdef0123456789abcdef'}],
22+
'byte_run_data': "helloworld",
23+
}
2524

2625

2726
class TestByteRuns(unittest.TestCase):

cybox/test/common/contributor_test.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44
import unittest
55

66
from cybox.common import Contributor
7-
import cybox.test
7+
from cybox.test import EntityTestCase
88

99

10-
class TestContributor(unittest.TestCase):
10+
class TestContributor(EntityTestCase, unittest.TestCase):
11+
klass = Contributor
1112

12-
def test_round_trip(self):
13-
contrib_dict = {
14-
'role': "Lead Tester",
15-
'name': "Marty McFly",
16-
'email': "marty@mcfly.com",
17-
'phone': "(123) 456-7890",
18-
'organization': "Doc Brown Enterprises(tm)",
19-
'date': {
20-
'start_date': "1955-11-05",
21-
'end_date': "1985-11-05",
22-
},
23-
'contribution_location': "Hill Valley, CA",
24-
}
25-
contrib_dict2 = cybox.test.round_trip_dict(Contributor, contrib_dict)
26-
self.assertEqual(contrib_dict, contrib_dict2)
13+
_full_dict = {
14+
'role': "Lead Tester",
15+
'name': "Marty McFly",
16+
'email': "marty@mcfly.com",
17+
'phone': "(123) 456-7890",
18+
'organization': "Doc Brown Enterprises(tm)",
19+
'date': {
20+
'start_date': "1955-11-05",
21+
'end_date': "1985-11-05",
22+
},
23+
'contribution_location': "Hill Valley, CA",
24+
}
2725

2826

2927
if __name__ == "__main__":

cybox/test/common/digital_signature_test.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55

66
from cybox.common import DigitalSignature, DigitalSignatureList
77
import cybox.test
8+
from cybox.test import EntityTestCase
89

910

10-
class TestDigitalSignature(unittest.TestCase):
11+
class TestDigitalSignature(EntityTestCase, unittest.TestCase):
12+
klass = DigitalSignature
1113

12-
def test_round_trip(self):
13-
sig_dict = {
14-
'signature_exists': True,
15-
'signature_verified': False,
16-
'certificate_issuer': "SomeIssuer",
17-
'certificate_subject': "The Subject",
18-
'signature_description': "A Fake Signature",
19-
}
20-
sig_dict2 = cybox.test.round_trip_dict(DigitalSignature, sig_dict)
21-
self.assertEqual(sig_dict, sig_dict2)
14+
_full_dict = {
15+
'signature_exists': True,
16+
'signature_verified': False,
17+
'certificate_issuer': "SomeIssuer",
18+
'certificate_subject': "The Subject",
19+
'signature_description': "A Fake Signature",
20+
}
2221

2322

2423
class TestDigitalSignatureList(unittest.TestCase):

cybox/test/common/measuresource_test.py

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,40 @@
44
import unittest
55

66
from cybox.common import MeasureSource
7-
import cybox.test
7+
from cybox.test import EntityTestCase
88

99

10-
class TestMeasureSource(unittest.TestCase):
10+
class TestMeasureSource(EntityTestCase, unittest.TestCase):
11+
klass = MeasureSource
1112

12-
def test_round_trip(self):
13-
ms_dict = {
14-
'class': "Software",
15-
'source_type': "Information Source",
16-
'name': "ASource",
17-
'information_source_type': u"Web Logs",
18-
'tool_type': u"Vulnerability Scanner",
19-
'description': u"A description of the source",
20-
'contributors': [
21-
{
22-
'name': u"An amazing dude",
23-
'email': u"amazing@dude.com",
24-
},
25-
{
26-
'name': u"Another amazing dude",
27-
'role': u"President of Amazing",
28-
'organization': u"AmazingCo.",
29-
},
30-
],
31-
'time': {
32-
'start_time': "2013-02-14T11:28:42-05:00",
33-
'end_time': "2014-03-11T06:22:17-05:00",
34-
},
35-
'tools': [
36-
{'name': u"AmazingTool (TM)"}
37-
],
38-
'platform': {'description': u"The best platform"},
39-
#TODO: Add System and Instance
40-
}
41-
ms_dict2 = cybox.test.round_trip_dict(MeasureSource, ms_dict)
42-
print MeasureSource.from_dict(ms_dict).to_xml()
43-
self.maxDiff = None
44-
self.assertEqual(ms_dict, ms_dict2)
13+
_full_dict = {
14+
'class': "Software",
15+
'source_type': "Information Source",
16+
'name': "ASource",
17+
'information_source_type': u"Web Logs",
18+
'tool_type': u"Vulnerability Scanner",
19+
'description': u"A description of the source",
20+
'contributors': [
21+
{
22+
'name': u"An amazing dude",
23+
'email': u"amazing@dude.com",
24+
},
25+
{
26+
'name': u"Another amazing dude",
27+
'role': u"President of Amazing",
28+
'organization': u"AmazingCo.",
29+
},
30+
],
31+
'time': {
32+
'start_time': "2013-02-14T11:28:42-05:00",
33+
'end_time': "2014-03-11T06:22:17-05:00",
34+
},
35+
'tools': [
36+
{'name': u"AmazingTool (TM)"}
37+
],
38+
'platform': {'description': u"The best platform"},
39+
#TODO: Add System and Instance
40+
}
4541

4642

4743
if __name__ == "__main__":

cybox/test/common/object_properties_test.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55

66
from cybox.common import ObjectProperties
77
from cybox.objects.address_object import Address
8-
import cybox.test
8+
from cybox.test import EntityTestCase
99

1010

11-
class TestObjectProperties(unittest.TestCase):
11+
class TestObjectProperties(EntityTestCase, unittest.TestCase):
12+
klass = Address
13+
14+
_full_dict = {
15+
'object_reference': "cybox:address-1",
16+
'category': Address.CAT_IPV4,
17+
'xsi:type': Address._XSI_TYPE,
18+
}
1219

1320
def test_empty_dict(self):
1421
self.assertEqual(None, ObjectProperties.from_dict({}))
@@ -27,16 +34,6 @@ def test_detect_address(self):
2734
self.assertTrue(isinstance(obj, ObjectProperties))
2835
self.assertTrue(isinstance(obj, Address))
2936

30-
def test_object_reference(self):
31-
d = {'object_reference': "cybox:address-1",
32-
'category': Address.CAT_IPV4}
33-
34-
d2 = cybox.test.round_trip_dict(Address, d)
35-
print d2
36-
37-
self.assertNotEqual(d, d2)
38-
cybox.test.assert_equal_ignore(d, d2, ['xsi:type'])
39-
4037

4138
if __name__ == "__main__":
4239
unittest.main()

cybox/test/common/tools_test.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@
55

66
from cybox.common import Hash, ToolInformation, ToolInformationList
77
import cybox.test
8+
from cybox.test import EntityTestCase
89
from cybox.test.common.hash_test import EMPTY_MD5
910

1011

11-
class TestToolInformation(unittest.TestCase):
12+
class TestToolInformation(EntityTestCase, unittest.TestCase):
13+
klass = ToolInformation
1214

13-
def test_round_trip(self):
14-
info_dict = {
15-
'id': "example:Tool-A1",
16-
'idref': "example:Tool-A1-ref",
17-
'name': "AwesomeTool(tm)",
18-
'type': ['NIDS', 'HIPS'],
19-
'description': {'structuring_format': 'HTML',
20-
'value': '<p>An awesome tool!</p>'},
15+
_full_dict = {
16+
'id': "example:Tool-A1",
17+
'idref': "example:Tool-A1-ref",
18+
'name': "AwesomeTool(tm)",
19+
'type': ['NIDS', 'HIPS'],
20+
'description': {'structuring_format': 'HTML',
21+
'value': '<p>An awesome tool!</p>'},
2122

22-
'vendor': "Awesome Co.",
23-
'version': "1.0.0",
24-
'service_pack': 'N/A',
23+
'vendor': "Awesome Co.",
24+
'version': "1.0.0",
25+
'service_pack': 'N/A',
2526

26-
'tool_hashes': [{'simple_hash_value': EMPTY_MD5,
27-
'type': Hash.TYPE_MD5}],
28-
}
29-
info_dict2 = cybox.test.round_trip_dict(ToolInformation, info_dict)
30-
self.assertEqual(info_dict, info_dict2)
27+
'tool_hashes': [{'simple_hash_value': EMPTY_MD5,
28+
'type': Hash.TYPE_MD5}],
29+
}
3130

3231

3332
class TestHashList(unittest.TestCase):
@@ -37,7 +36,7 @@ def test_round_trip(self):
3736
{'id': "example:Tool-A1", 'name': "Tool 1"},
3837
{'id': "example:Tool-A2", 'name': "Tool 2"},
3938
]
40-
toolinfolist_list2= cybox.test.round_trip_list(ToolInformationList,
39+
toolinfolist_list2 = cybox.test.round_trip_list(ToolInformationList,
4140
toolinfolist_list)
4241
self.assertEqual(toolinfolist_list, toolinfolist_list2)
4342

cybox/test/objects/dns_query_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
import uuid
66

77
from cybox.objects.dns_query_object import DNSQuestion
8-
import cybox.test
8+
from cybox.test import EntityTestCase
99

1010

11-
class TestQuestion(unittest.TestCase):
11+
class TestQuestion(EntityTestCase, unittest.TestCase):
12+
klass = DNSQuestion
1213

13-
def test_round_trip(self):
14-
question_dict = {
15-
'qname': {'value': "www.example.com"},
16-
'qtype': "A",
17-
'qclass': "IN",
18-
}
19-
20-
question_dict2 = cybox.test.round_trip_dict(DNSQuestion, question_dict)
21-
cybox.test.assert_equal_ignore(question_dict, question_dict2, ['xsi:type'])
14+
_full_dict = {
15+
'qname': {
16+
'value': "www.example.com",
17+
'xsi:type': "URIObjectType",
18+
},
19+
'qtype': "A",
20+
'qclass': "IN",
21+
}
2222

2323

2424
if __name__ == "__main__":

0 commit comments

Comments
 (0)