Code coverage changes, fix some tests. Add stix2-validator dependency.

stix2.1
Emmanuelle Vargas-Gonzalez 2017-08-28 15:19:55 -04:00
parent aea076103c
commit 415c53066f
8 changed files with 25 additions and 33 deletions

View File

@ -54,6 +54,7 @@ setup(
'simplejson', 'simplejson',
'six', 'six',
'stix2-patterns', 'stix2-patterns',
'stix2-validator',
'taxii2-client', 'taxii2-client',
], ],
) )

View File

@ -3,10 +3,9 @@
# flake8: noqa # flake8: noqa
from . import exceptions from . import exceptions
from .common import (TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, from .common import (TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomMarking,
CustomMarking, ExternalReference, GranularMarking, ExternalReference, GranularMarking, KillChainPhase,
KillChainPhase, MarkingDefinition, StatementMarking, MarkingDefinition, StatementMarking, TLPMarking)
TLPMarking)
from .core import Bundle, _register_type, parse from .core import Bundle, _register_type, parse
from .environment import ObjectFactory from .environment import ObjectFactory
from .observables import (URL, AlternateDataStream, ArchiveExt, Artifact, from .observables import (URL, AlternateDataStream, ArchiveExt, Artifact,

View File

@ -6,7 +6,6 @@ import re
import uuid import uuid
from six import string_types, text_type from six import string_types, text_type
from stix2patterns.validator import run_validator from stix2patterns.validator import run_validator
from .base import _STIXBase from .base import _STIXBase

View File

@ -17,7 +17,6 @@ Notes:
""" """
import collections import collections
import copy
import uuid import uuid
from six import iteritems from six import iteritems

View File

@ -21,9 +21,10 @@ Notes:
import json import json
import os import os
from stix2validator import validate_string
from stix2 import Bundle from stix2 import Bundle
from stix2.sources import DataSink, DataSource, DataStore, Filter from stix2.sources import DataSink, DataSource, DataStore, Filter
from stix2validator import validate_string
class MemoryStore(DataStore): class MemoryStore(DataStore):

View File

@ -135,32 +135,12 @@ def test_custom_no_properties_raises_exception():
class NewObject1(object): class NewObject1(object):
pass pass
NewObject1() with pytest.raises(ValueError):
@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()
@stix2.observables.CustomObservable('x-new-object-type', (("prop", stix2.properties.BooleanProperty()))) @stix2.observables.CustomObservable('x-new-object-type', (("prop", stix2.properties.BooleanProperty())))
class NewObject4(object): class NewObject4(object):
pass pass
NewObject4()
@stix2.common.CustomMarking('x-new-marking-type')
class NewObject5(object):
pass
NewObject5()
def test_parse_custom_observable_object(): def test_parse_custom_observable_object():
nt_string = """{ nt_string = """{

View File

@ -1,7 +1,8 @@
import pytest import pytest
from taxii2client import Collection 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 from stix2.sources.memory import MemorySource
COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/' COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/'
@ -24,8 +25,14 @@ def test_ds_smoke():
with pytest.raises(NotImplementedError): with pytest.raises(NotImplementedError):
ds3.add(None) ds3.add(None)
with pytest.raises(NotImplementedError):
ds3.all_versions("malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111") ds3.all_versions("malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111")
with pytest.raises(NotImplementedError):
ds3.get("malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111") ds3.get("malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111")
with pytest.raises(NotImplementedError):
ds3.query([Filter("id", "=", "malware--fdd60b30-b67c-11e3-b0b9-f01faf20d111")]) 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]]) resp = ds.apply_common_filters(stix_objs, [filters[2]])
assert resp[0]['id'] == stix_objs[0]['id'] assert resp[0]['id'] == stix_objs[0]['id']
STIX_OBJS1 = [ STIX_OBJS1 = [
{ {
"created": "2017-01-27T13:49:53.935Z", "created": "2017-01-27T13:49:53.935Z",

View File

@ -187,8 +187,7 @@ def test_parse_marking_definition(data):
]) ])
class NewMarking(object): class NewMarking(object):
def __init__(self, property2=None, **kwargs): def __init__(self, property2=None, **kwargs):
if property2 and property2 < 10: return
raise ValueError("'property2' is too small.")
def test_registered_custom_marking(): def test_registered_custom_marking():
@ -217,8 +216,7 @@ def test_not_registered_marking_raises_exception():
]) ])
class NewObject2(object): class NewObject2(object):
def __init__(self, property2=None, **kwargs): def __init__(self, property2=None, **kwargs):
if property2 and property2 < 10: return
raise ValueError("'property2' is too small.")
no = NewObject2(property1='something', property2=55) 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 # TODO: Add other examples