Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ env:
- TOXENV=rhel6

install:
# Cache Wheels for faster tests
- pip install -U pip wheel
- pip install -r requirements.txt

- pip install tox

cache:
directories:
- $HOME/.cache/pip

script:
- tox

Expand Down
17 changes: 9 additions & 8 deletions cybox/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
# See LICENSE.txt for complete terms.

import json
import logging
import unittest

from mixbox.binding_utils import ExternalEncoding
from mixbox.vendor import six

from cybox import Entity, EntityList, TypedField
import cybox.bindings.cybox_core as core_binding
from cybox.core import Observables
import cybox.utils

logger = logging.getLogger(__name__)


def assert_equal_ignore(item1, item2, ignore_keys=None):
"""Recursively compare two dictionaries, ignoring differences in some keys.
Expand Down Expand Up @@ -54,8 +55,8 @@ def round_trip(o, output=False, list_=False):

klass = o.__class__
if output:
print("Class: ", klass)
print("-" * 40)
logger.debug("Class: {0}".format(klass))
logger.debug("-" * 40)

# 1. cybox.Entity -> dict/list
if list_:
Expand All @@ -67,8 +68,8 @@ def round_trip(o, output=False, list_=False):
json_string = json.dumps(d)

if output:
print(json_string)
print("-" * 40)
logger.debug(json_string)
logger.debug("-" * 40)

# Before parsing the JSON, make sure the cache is clear
cybox.utils.cache_clear()
Expand All @@ -94,8 +95,8 @@ def round_trip(o, output=False, list_=False):
xml_string = xml_string.decode(ExternalEncoding)

if output:
print(xml_string)
print("-" * 40)
logger.debug(xml_string)
logger.debug("-" * 40)

# Before parsing the XML, make sure the cache is clear
cybox.utils.cache_clear()
Expand Down
7 changes: 5 additions & 2 deletions cybox/test/common/hash_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import logging
import unittest

from mixbox.vendor.six import u

from cybox.common import Hash, HashList, HashName, HexBinary
import cybox.test

logger = logging.getLogger(__name__)

EMPTY_MD5 = u("d41d8cd98f00b204e9800998ecf8427e")
EMPTY_SHA1 = u("da39a3ee5e6b4b0d3255bfef95601890afd80709")
EMPTY_SHA224 = u("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f")
Expand Down Expand Up @@ -174,10 +177,10 @@ def test_namespace_count(self):
h.append(EMPTY_SHA256)
h.append(EMPTY_SHA384)
h.append(EMPTY_SHA512)
print(h.to_xml())
logger.info(h.to_xml())

ns_list = cybox.test.round_trip(h, list_=True)._get_namespaces()
print(ns_list)
logger.info(ns_list)

# Only "common" and "vocabs" should be here. "xsi" is only added later
self.assertEqual(2, len(ns_list))
Expand Down
4 changes: 2 additions & 2 deletions cybox/test/common/structured_test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import unittest

from mixbox.vendor.six import u
from mixbox.vendor.six import text_type, u

from cybox.common import StructuredText
import cybox.test
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_plain(self):
def test_unicode(self):
text = self.klass.from_dict(self._full_dict)
# This should not raise any errors
print(text)
self.assertTrue(b"WARNING" in text_type(text).encode('utf-8'))


if __name__ == "__main__":
Expand Down
7 changes: 5 additions & 2 deletions cybox/test/core/action_reference_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import logging
import unittest

from mixbox.vendor.six import u

from cybox.core import ActionReference
from cybox.test import EntityTestCase

logger = logging.getLogger(__name__)


class TestActionReference(EntityTestCase, unittest.TestCase):
klass = ActionReference
Expand All @@ -17,8 +20,8 @@ class TestActionReference(EntityTestCase, unittest.TestCase):

def test_construction(self):
aref = ActionReference(action_id="example:Action-1")
print(aref.to_xml())
print(aref.to_dict())
logger.info(aref.to_xml())
logger.info(aref.to_dict())
self.assertTrue(b"example:Action-1" in aref.to_xml())
self.assertTrue("example:Action-1" in aref.to_json())

Expand Down
8 changes: 5 additions & 3 deletions cybox/test/core/object_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import logging
import unittest

from mixbox.vendor.six import u

from cybox.core import Object, Observables, RelatedObject, Relationship
from cybox.core import Object, Observables, RelatedObject
from cybox.objects.address_object import Address
from cybox.objects.email_message_object import EmailMessage
from cybox.objects.uri_object import URI
from cybox.test import EntityTestCase, round_trip, round_trip_dict
from cybox.utils import CacheMiss, set_id_method

logger = logging.getLogger(__name__)


class ObjectTest(EntityTestCase, unittest.TestCase):
klass = Object
Expand Down Expand Up @@ -152,7 +154,7 @@ def test_relationship_vocabnameref(self):

def _test_round_trip(self, observables):
self.maxDiff = None
print(observables.to_xml())
logger.info(observables.to_xml())
observables2 = round_trip(observables)
self.assertEqual(observables.to_dict(), observables2.to_dict())

Expand Down
5 changes: 4 additions & 1 deletion cybox/test/core/observable_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import logging
import unittest

from mixbox.vendor.six import u
Expand All @@ -12,6 +13,8 @@
from cybox.objects.address_object import Address
from cybox.test import EntityTestCase, round_trip

logger = logging.getLogger(__name__)


class TestObservable(EntityTestCase, unittest.TestCase):
klass = Observable
Expand Down Expand Up @@ -44,7 +47,7 @@ def test_keywords(self):

self.assertTrue(b"eyword" not in o.to_xml())
o.add_keyword("Foo")
print(o.to_xml())
logger.info(o.to_xml())
self.assertTrue(b"<cybox:Keyword>Foo</cybox:Keyword>" in o.to_xml())

o2 = round_trip(o)
Expand Down
7 changes: 5 additions & 2 deletions cybox/test/objects/email_message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See LICENSE.txt for complete terms.

import datetime
import logging
import unittest

from mixbox.vendor.six import u
Expand All @@ -17,6 +18,8 @@
from cybox.test import EntityTestCase
from cybox.test.objects import ObjectTestCase

logger = logging.getLogger(__name__)


class TestLinks(EntityTestCase, unittest.TestCase):
klass = LinkReference
Expand Down Expand Up @@ -301,10 +304,10 @@ def test_get_namespaces(self):
m.links.append(u.parent.id_)

o = Observables([u, m])
print(o.to_xml())
logger.info(o.to_xml())
actual_namespaces = o._get_namespaces()

print("\n".join([str(x) for x in actual_namespaces]))
logger.info("\n".join([str(x) for x in actual_namespaces]))

self.assertEqual(5, len(actual_namespaces))

Expand Down