Use pytest fixtures
parent
022f7c9166
commit
e23d265d20
|
@ -21,6 +21,29 @@ def test_timestamp_formatting(dt, timestamp):
|
|||
assert stix2.format_datetime(dt) == timestamp
|
||||
|
||||
|
||||
# Minimum required args for an Indicator instance
|
||||
INDICATOR_KWARGS = dict(
|
||||
labels=['malicious-activity'],
|
||||
pattern="[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
|
||||
)
|
||||
|
||||
# Minimum required args for a Malware instance
|
||||
MALWARE_KWARGS = dict(
|
||||
labels=['ransomware'],
|
||||
name="Cryptolocker",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def indicator():
|
||||
return stix2.Indicator(**INDICATOR_KWARGS)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def malware():
|
||||
return stix2.Malware(**MALWARE_KWARGS)
|
||||
|
||||
|
||||
EXPECTED_INDICATOR = """{
|
||||
"created": "2017-01-01T00:00:00Z",
|
||||
"id": "indicator--01234567-89ab-cdef-0123-456789abcdef",
|
||||
|
@ -51,15 +74,7 @@ def test_indicator_with_all_required_fields():
|
|||
assert str(indicator) == EXPECTED_INDICATOR
|
||||
|
||||
|
||||
# Minimum required args for an Indicator instance
|
||||
INDICATOR_KWARGS = dict(
|
||||
labels=['malicious-activity'],
|
||||
pattern="[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
|
||||
)
|
||||
|
||||
|
||||
def test_indicator_autogenerated_fields():
|
||||
indicator = stix2.Indicator(**INDICATOR_KWARGS)
|
||||
def test_indicator_autogenerated_fields(indicator):
|
||||
assert indicator.type == 'indicator'
|
||||
assert indicator.id.startswith('indicator--')
|
||||
assert indicator.created is not None
|
||||
|
@ -104,9 +119,7 @@ def test_indicator_required_field_pattern():
|
|||
assert "Missing required field for Indicator: 'pattern'." in str(excinfo)
|
||||
|
||||
|
||||
def test_cannot_assign_to_attributes():
|
||||
indicator = stix2.Indicator(**INDICATOR_KWARGS)
|
||||
|
||||
def test_cannot_assign_to_attributes(indicator):
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
indicator.valid_from = datetime.datetime.now()
|
||||
|
||||
|
@ -146,15 +159,7 @@ def test_malware_with_all_required_fields():
|
|||
assert str(malware) == EXPECTED_MALWARE
|
||||
|
||||
|
||||
# Minimum required args for a Malware instance
|
||||
MALWARE_KWARGS = dict(
|
||||
labels=['ransomware'],
|
||||
name="Cryptolocker",
|
||||
)
|
||||
|
||||
|
||||
def test_malware_autogenerated_fields():
|
||||
malware = stix2.Malware(**MALWARE_KWARGS)
|
||||
def test_malware_autogenerated_fields(malware):
|
||||
assert malware.type == 'malware'
|
||||
assert malware.id.startswith('malware--')
|
||||
assert malware.created is not None
|
||||
|
@ -197,9 +202,7 @@ def test_malware_required_field_name():
|
|||
assert "Missing required field for Malware: 'name'." in str(excinfo)
|
||||
|
||||
|
||||
def test_cannot_assign_to_attributes():
|
||||
malware = stix2.Malware(**MALWARE_KWARGS)
|
||||
|
||||
def test_cannot_assign_to_attributes(malware):
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
malware.name = "Cryptolocker II"
|
||||
|
||||
|
|
Loading…
Reference in New Issue