From b06bc1afc128a3f08c2208c229abac3dd2ebe8cc Mon Sep 17 00:00:00 2001 From: "Desai, Kartikey H" Date: Fri, 20 Mar 2020 17:32:18 -0400 Subject: [PATCH] Fix import issues --- stix2/core.py | 2 +- stix2/exceptions.py | 7 +++++++ stix2/test/v20/test_custom.py | 6 +++--- stix2/test/v21/test_custom.py | 6 +++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/stix2/core.py b/stix2/core.py index bb583ba..ffe77f2 100644 --- a/stix2/core.py +++ b/stix2/core.py @@ -8,7 +8,7 @@ import re import stix2 from .base import _Observable, _STIXBase -from .exceptions import ParseError +from .exceptions import DuplicateObjectRegistrationError, ParseError from .markings import _MarkingsMixin from .utils import SCO21_EXT_REGEX, TYPE_REGEX, _get_dict diff --git a/stix2/exceptions.py b/stix2/exceptions.py index d2ec3fc..f65f48b 100644 --- a/stix2/exceptions.py +++ b/stix2/exceptions.py @@ -233,3 +233,10 @@ class STIXDeprecationWarning(DeprecationWarning): Represents usage of a deprecated component of a STIX specification. """ pass + + +class DuplicateObjectRegistrationError(STIXError): + """An object (or observable) with the same type as an existing object (or observable) is being registered""" + + def __init__(self, msg): + super(DuplicateObjectRegistrationError, self).__init__(msg) diff --git a/stix2/test/v20/test_custom.py b/stix2/test/v20/test_custom.py index f3fa59a..19cb28a 100644 --- a/stix2/test/v20/test_custom.py +++ b/stix2/test/v20/test_custom.py @@ -4,7 +4,7 @@ import stix2 from stix2 import core import stix2.v20 -from ...exceptions import InvalidValueError +from ...exceptions import DuplicateObjectRegistrationError, InvalidValueError from .constants import FAKE_TIME, IDENTITY_ID, MARKING_DEFINITION_ID IDENTITY_CUSTOM_PROP = stix2.v20.Identity( @@ -1040,7 +1040,7 @@ def test_register_custom_object_with_version(): def test_register_duplicate_object_with_version(): - with pytest.raises(stix2.exceptions.DuplicateObjectRegistrationError) as excinfo: + with pytest.raises(DuplicateObjectRegistrationError) as excinfo: @stix2.v20.CustomObject( 'x-new-type-2', [ ('property1', stix2.properties.StringProperty()), @@ -1069,7 +1069,7 @@ def test_register_observable_with_version(): def test_register_duplicate_observable_with_version(): - with pytest.raises(stix2.exceptions.DuplicateObjectRegistrationError) as excinfo: + with pytest.raises(DuplicateObjectRegistrationError) as excinfo: @stix2.v20.CustomObservable( 'x-new-observable-2', [ ('property1', stix2.properties.StringProperty()), diff --git a/stix2/test/v21/test_custom.py b/stix2/test/v21/test_custom.py index e2b7f22..92cacf3 100644 --- a/stix2/test/v21/test_custom.py +++ b/stix2/test/v21/test_custom.py @@ -6,7 +6,7 @@ import stix2 import stix2.base import stix2.v21 -from ...exceptions import InvalidValueError +from ...exceptions import DuplicateObjectRegistrationError, InvalidValueError from .constants import FAKE_TIME, IDENTITY_ID, MARKING_DEFINITION_ID IDENTITY_CUSTOM_PROP = stix2.v21.Identity( @@ -1092,7 +1092,7 @@ def test_register_custom_object_with_version(): def test_register_duplicate_object_with_version(): - with pytest.raises(stix2.exceptions.DuplicateObjectRegistrationError) as excinfo: + with pytest.raises(DuplicateObjectRegistrationError) as excinfo: @stix2.v21.CustomObject( 'x-new-type-2', [ ('property1', stix2.properties.StringProperty()), @@ -1121,7 +1121,7 @@ def test_register_observable_with_version(): def test_register_duplicate_observable_with_version(): - with pytest.raises(stix2.exceptions.DuplicateObjectRegistrationError) as excinfo: + with pytest.raises(DuplicateObjectRegistrationError) as excinfo: @stix2.v21.CustomObservable( 'x-new-observable-2', [ ('property1', stix2.properties.StringProperty()),