From 415c53066f99d2d063d5f7d21ec717bd1c223f87 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Mon, 28 Aug 2017 15:19:55 -0400 Subject: [PATCH] Code coverage changes, fix some tests. Add stix2-validator dependency. --- setup.py | 1 + stix2/__init__.py | 7 +++---- stix2/properties.py | 1 - stix2/sources/__init__.py | 1 - stix2/sources/memory.py | 3 ++- stix2/test/test_custom.py | 22 +--------------------- stix2/test/test_data_sources.py | 10 +++++++++- stix2/test/test_markings.py | 13 +++++++++---- 8 files changed, 25 insertions(+), 33 deletions(-) diff --git a/setup.py b/setup.py index d9b1edc..3687e57 100644 --- a/setup.py +++ b/setup.py @@ -54,6 +54,7 @@ setup( 'simplejson', 'six', 'stix2-patterns', + 'stix2-validator', 'taxii2-client', ], ) diff --git a/stix2/__init__.py b/stix2/__init__.py index 76ca696..6e89531 100644 --- a/stix2/__init__.py +++ b/stix2/__init__.py @@ -3,10 +3,9 @@ # flake8: noqa from . import exceptions -from .common import (TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, - CustomMarking, ExternalReference, GranularMarking, - KillChainPhase, MarkingDefinition, StatementMarking, - TLPMarking) +from .common import (TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomMarking, + ExternalReference, GranularMarking, KillChainPhase, + MarkingDefinition, StatementMarking, TLPMarking) from .core import Bundle, _register_type, parse from .environment import ObjectFactory from .observables import (URL, AlternateDataStream, ArchiveExt, Artifact, diff --git a/stix2/properties.py b/stix2/properties.py index a04294e..6406ad4 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -6,7 +6,6 @@ import re import uuid from six import string_types, text_type - from stix2patterns.validator import run_validator from .base import _STIXBase diff --git a/stix2/sources/__init__.py b/stix2/sources/__init__.py index 87ff913..424fc3a 100644 --- a/stix2/sources/__init__.py +++ b/stix2/sources/__init__.py @@ -17,7 +17,6 @@ Notes: """ import collections -import copy import uuid from six import iteritems diff --git a/stix2/sources/memory.py b/stix2/sources/memory.py index 6460ce3..28d929d 100644 --- a/stix2/sources/memory.py +++ b/stix2/sources/memory.py @@ -21,9 +21,10 @@ Notes: import json import os +from stix2validator import validate_string + from stix2 import Bundle from stix2.sources import DataSink, DataSource, DataStore, Filter -from stix2validator import validate_string class MemoryStore(DataStore): diff --git a/stix2/test/test_custom.py b/stix2/test/test_custom.py index 2b08883..0ca6fbd 100644 --- a/stix2/test/test_custom.py +++ b/stix2/test/test_custom.py @@ -135,32 +135,12 @@ def test_custom_no_properties_raises_exception(): class NewObject1(object): pass - NewObject1() - - @stix2.sdo.CustomObject('x-new-object-type', ("a", 0)) - class NewObject2(object): - pass - - NewObject2() - - @stix2.observables.CustomObservable('x-new-object-type') - class NewObject3(object): - pass - - NewObject3() + with pytest.raises(ValueError): @stix2.observables.CustomObservable('x-new-object-type', (("prop", stix2.properties.BooleanProperty()))) class NewObject4(object): pass - NewObject4() - - @stix2.common.CustomMarking('x-new-marking-type') - class NewObject5(object): - pass - - NewObject5() - def test_parse_custom_observable_object(): nt_string = """{ diff --git a/stix2/test/test_data_sources.py b/stix2/test/test_data_sources.py index df70878..10e4cc7 100644 --- a/stix2/test/test_data_sources.py +++ b/stix2/test/test_data_sources.py @@ -1,7 +1,8 @@ import pytest from taxii2client import Collection -from stix2.sources import CompositeDataSource, DataSink, DataSource, DataStore, Filter, make_id, taxii +from stix2.sources import (CompositeDataSource, DataSink, DataSource, + DataStore, Filter, make_id, taxii) from stix2.sources.memory import MemorySource COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/' @@ -24,8 +25,14 @@ def test_ds_smoke(): with pytest.raises(NotImplementedError): ds3.add(None) + + with pytest.raises(NotImplementedError): ds3.all_versions("malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111") + + with pytest.raises(NotImplementedError): ds3.get("malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111") + + with pytest.raises(NotImplementedError): ds3.query([Filter("id", "=", "malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111")]) @@ -170,6 +177,7 @@ def test_apply_common_filters(): resp = ds.apply_common_filters(stix_objs, [filters[2]]) assert resp[0]['id'] == stix_objs[0]['id'] + STIX_OBJS1 = [ { "created": "2017-01-27T13:49:53.935Z", diff --git a/stix2/test/test_markings.py b/stix2/test/test_markings.py index 4e39c54..c9d9273 100644 --- a/stix2/test/test_markings.py +++ b/stix2/test/test_markings.py @@ -187,8 +187,7 @@ def test_parse_marking_definition(data): ]) class NewMarking(object): def __init__(self, property2=None, **kwargs): - if property2 and property2 < 10: - raise ValueError("'property2' is too small.") + return def test_registered_custom_marking(): @@ -217,8 +216,7 @@ def test_not_registered_marking_raises_exception(): ]) class NewObject2(object): def __init__(self, property2=None, **kwargs): - if property2 and property2 < 10: - raise ValueError("'property2' is too small.") + return no = NewObject2(property1='something', property2=55) @@ -230,4 +228,11 @@ def test_not_registered_marking_raises_exception(): ) +def test_bad_marking_construction(): + with pytest.raises(ValueError): + @stix2.sdo.CustomObject('x-new-marking-type2', ("a", "b")) + class NewObject3(object): + pass + + # TODO: Add other examples