Improve Environment tests
parent
f0331f8b9b
commit
cfa18bfd0d
|
@ -547,3 +547,11 @@ def test_composite_datasource_operations():
|
||||||
# nothing returns the same as cds1.query(query1) (the associated query is query2)
|
# nothing returns the same as cds1.query(query1) (the associated query is query2)
|
||||||
results = cds1.query([])
|
results = cds1.query([])
|
||||||
assert len(results) == 3
|
assert len(results) == 3
|
||||||
|
|
||||||
|
|
||||||
|
def test_composite_datastore_no_datasource():
|
||||||
|
cds = CompositeDataSource()
|
||||||
|
|
||||||
|
with pytest.raises(AttributeError) as excinfo:
|
||||||
|
cds.get("indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f")
|
||||||
|
assert 'CompositeDataSource has no data source' in str(excinfo.value)
|
||||||
|
|
|
@ -164,6 +164,14 @@ def test_environment_no_datastore():
|
||||||
env.query(INDICATOR_ID)
|
env.query(INDICATOR_ID)
|
||||||
assert 'Environment has no data source' in str(excinfo.value)
|
assert 'Environment has no data source' in str(excinfo.value)
|
||||||
|
|
||||||
|
with pytest.raises(AttributeError) as excinfo:
|
||||||
|
env.relationships(INDICATOR_ID)
|
||||||
|
assert 'Environment has no data source' in str(excinfo.value)
|
||||||
|
|
||||||
|
with pytest.raises(AttributeError) as excinfo:
|
||||||
|
env.related_to(INDICATOR_ID)
|
||||||
|
assert 'Environment has no data source' in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_environment_add_filters():
|
def test_environment_add_filters():
|
||||||
env = stix2.Environment(factory=stix2.ObjectFactory())
|
env = stix2.Environment(factory=stix2.ObjectFactory())
|
||||||
|
@ -200,7 +208,7 @@ def test_parse_malware():
|
||||||
assert mal.name == "Cryptolocker"
|
assert mal.name == "Cryptolocker"
|
||||||
|
|
||||||
|
|
||||||
def test_created_by():
|
def test_creator_of():
|
||||||
identity = stix2.Identity(**IDENTITY_KWARGS)
|
identity = stix2.Identity(**IDENTITY_KWARGS)
|
||||||
factory = stix2.ObjectFactory(created_by_ref=identity.id)
|
factory = stix2.ObjectFactory(created_by_ref=identity.id)
|
||||||
env = stix2.Environment(store=stix2.MemoryStore(), factory=factory)
|
env = stix2.Environment(store=stix2.MemoryStore(), factory=factory)
|
||||||
|
@ -211,7 +219,7 @@ def test_created_by():
|
||||||
assert creator is identity
|
assert creator is identity
|
||||||
|
|
||||||
|
|
||||||
def test_created_by_no_datasource():
|
def test_creator_of_no_datasource():
|
||||||
identity = stix2.Identity(**IDENTITY_KWARGS)
|
identity = stix2.Identity(**IDENTITY_KWARGS)
|
||||||
factory = stix2.ObjectFactory(created_by_ref=identity.id)
|
factory = stix2.ObjectFactory(created_by_ref=identity.id)
|
||||||
env = stix2.Environment(factory=factory)
|
env = stix2.Environment(factory=factory)
|
||||||
|
@ -222,7 +230,7 @@ def test_created_by_no_datasource():
|
||||||
assert 'Environment has no data source' in str(excinfo.value)
|
assert 'Environment has no data source' in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_created_by_not_found():
|
def test_creator_of_not_found():
|
||||||
identity = stix2.Identity(**IDENTITY_KWARGS)
|
identity = stix2.Identity(**IDENTITY_KWARGS)
|
||||||
factory = stix2.ObjectFactory(created_by_ref=identity.id)
|
factory = stix2.ObjectFactory(created_by_ref=identity.id)
|
||||||
env = stix2.Environment(store=stix2.MemoryStore(), factory=factory)
|
env = stix2.Environment(store=stix2.MemoryStore(), factory=factory)
|
||||||
|
@ -232,6 +240,13 @@ def test_created_by_not_found():
|
||||||
assert creator is None
|
assert creator is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_creator_of_no_created_by_ref():
|
||||||
|
env = stix2.Environment(store=stix2.MemoryStore())
|
||||||
|
ind = env.create(stix2.Indicator, **INDICATOR_KWARGS)
|
||||||
|
creator = env.creator_of(ind)
|
||||||
|
assert creator is None
|
||||||
|
|
||||||
|
|
||||||
def test_relationships(ds):
|
def test_relationships(ds):
|
||||||
env = stix2.Environment(store=ds)
|
env = stix2.Environment(store=ds)
|
||||||
mal = env.get(MALWARE_ID)
|
mal = env.get(MALWARE_ID)
|
||||||
|
|
Loading…
Reference in New Issue