2017-07-20 21:36:54 +02:00
|
|
|
import pytest
|
|
|
|
|
2018-03-01 15:04:42 +01:00
|
|
|
from stix2.datastore import (CompositeDataSource, DataSink, DataSource,
|
2018-04-06 20:23:48 +02:00
|
|
|
DataStoreMixin)
|
|
|
|
from stix2.datastore.filters import Filter
|
|
|
|
from stix2.test.constants import CAMPAIGN_MORE_KWARGS
|
|
|
|
|
|
|
|
|
|
|
|
def test_datasource_abstract_class_raises_error():
|
2017-11-03 02:31:56 +01:00
|
|
|
with pytest.raises(TypeError):
|
|
|
|
DataSource()
|
2017-08-28 21:19:55 +02:00
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
|
|
|
|
def test_datasink_abstract_class_raises_error():
|
2017-11-03 02:31:56 +01:00
|
|
|
with pytest.raises(TypeError):
|
|
|
|
DataSink()
|
2017-08-28 20:33:12 +02:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_smoke():
|
|
|
|
assert DataStoreMixin() is not None
|
2017-07-20 21:36:54 +02:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_get_raises():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
DataStoreMixin().get("indicator--00000000-0000-4000-8000-000000000001")
|
2018-04-06 20:23:48 +02:00
|
|
|
assert "DataStoreMixin has no data source to query" == str(excinfo.value)
|
2017-05-31 15:58:14 +02:00
|
|
|
|
2017-05-31 15:47:36 +02:00
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_all_versions_raises():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
DataStoreMixin().all_versions("indicator--00000000-0000-4000-8000-000000000001")
|
2018-04-06 20:23:48 +02:00
|
|
|
assert "DataStoreMixin has no data source to query" == str(excinfo.value)
|
2017-05-31 15:47:36 +02:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_query_raises():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
|
|
|
DataStoreMixin().query([Filter("type", "=", "indicator")])
|
|
|
|
assert "DataStoreMixin has no data source to query" == str(excinfo.value)
|
2017-05-31 15:47:36 +02:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_creator_of_raises():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
|
|
|
DataStoreMixin().creator_of(CAMPAIGN_MORE_KWARGS)
|
|
|
|
assert "DataStoreMixin has no data source to query" == str(excinfo.value)
|
2017-07-19 23:30:29 +02:00
|
|
|
|
2017-05-31 15:47:36 +02:00
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_relationships_raises():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
DataStoreMixin().relationships(obj="indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:23:48 +02:00
|
|
|
target_only=True)
|
|
|
|
assert "DataStoreMixin has no data source to query" == str(excinfo.value)
|
2017-05-31 15:47:36 +02:00
|
|
|
|
2017-05-31 17:44:24 +02:00
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_related_to_raises():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
DataStoreMixin().related_to(obj="indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:23:48 +02:00
|
|
|
target_only=True)
|
|
|
|
assert "DataStoreMixin has no data source to query" == str(excinfo.value)
|
2017-05-31 17:44:24 +02:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_datastore_add_raises():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
|
|
|
DataStoreMixin().add(CAMPAIGN_MORE_KWARGS)
|
|
|
|
assert "DataStoreMixin has no data sink to put objects in" == str(excinfo.value)
|
2017-05-31 17:44:24 +02:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_composite_datastore_get_raises_error():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
CompositeDataSource().get("indicator--00000000-0000-4000-8000-000000000001")
|
2018-04-06 20:23:48 +02:00
|
|
|
assert "CompositeDataSource has no data sources" == str(excinfo.value)
|
2017-05-31 17:44:24 +02:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_composite_datastore_all_versions_raises_error():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
CompositeDataSource().all_versions("indicator--00000000-0000-4000-8000-000000000001")
|
2018-04-06 20:23:48 +02:00
|
|
|
assert "CompositeDataSource has no data sources" == str(excinfo.value)
|
2017-08-28 20:33:12 +02:00
|
|
|
|
2017-07-19 23:30:29 +02:00
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_composite_datastore_query_raises_error():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
|
|
|
CompositeDataSource().query([Filter("type", "=", "indicator")])
|
|
|
|
assert "CompositeDataSource has no data sources" == str(excinfo.value)
|
2018-03-22 15:59:07 +01:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_composite_datastore_relationships_raises_error():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
CompositeDataSource().relationships(obj="indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:23:48 +02:00
|
|
|
target_only=True)
|
|
|
|
assert "CompositeDataSource has no data sources" == str(excinfo.value)
|
2018-03-22 15:59:07 +01:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_composite_datastore_related_to_raises_error():
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
CompositeDataSource().related_to(obj="indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:23:48 +02:00
|
|
|
target_only=True)
|
|
|
|
assert "CompositeDataSource has no data sources" == str(excinfo.value)
|
2018-03-22 15:59:07 +01:00
|
|
|
|
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_composite_datastore_add_data_source_raises_error():
|
2018-03-22 15:59:07 +01:00
|
|
|
with pytest.raises(TypeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
ind = "indicator--00000000-0000-4000-8000-000000000001"
|
2018-04-06 20:23:48 +02:00
|
|
|
CompositeDataSource().add_data_source(ind)
|
|
|
|
assert "DataSource (to be added) is not of type stix2.DataSource. DataSource type is '{}'".format(type(ind)) == str(excinfo.value)
|
2018-03-22 15:59:07 +01:00
|
|
|
|
2017-08-28 20:33:12 +02:00
|
|
|
|
2018-04-06 20:23:48 +02:00
|
|
|
def test_composite_datastore_add_data_sources_raises_error():
|
2017-09-29 17:24:19 +02:00
|
|
|
with pytest.raises(TypeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
ind = "indicator--00000000-0000-4000-8000-000000000001"
|
2018-04-06 20:23:48 +02:00
|
|
|
CompositeDataSource().add_data_sources(ind)
|
|
|
|
assert "DataSource (to be added) is not of type stix2.DataSource. DataSource type is '{}'".format(type(ind)) == str(excinfo.value)
|
2018-04-23 20:14:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_composite_datastore_no_datasource():
|
|
|
|
cds = CompositeDataSource()
|
|
|
|
with pytest.raises(AttributeError) as excinfo:
|
2018-06-27 18:34:49 +02:00
|
|
|
cds.get("indicator--00000000-0000-4000-8000-000000000001")
|
2018-04-23 20:14:16 +02:00
|
|
|
assert 'CompositeDataSource has no data source' in str(excinfo.value)
|