update test suite for use of .serialize(pretty=True)

pull/1/head
Emmanuelle Vargas-Gonzalez 2021-03-31 12:39:14 -04:00
parent 9cc2e5bd3a
commit 6d285c47ae
45 changed files with 91 additions and 91 deletions

View File

@ -37,7 +37,7 @@ def test_attack_pattern_example():
description="...", description="...",
) )
assert str(ap) == EXPECTED assert ap.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -111,6 +111,6 @@ def test_less_precise_timestamps():
description="...", description="...",
) )
assert str(ap) == EXPECTED assert ap.serialize(pretty=True) == EXPECTED
# TODO: Add other examples # TODO: Add other examples

View File

@ -116,7 +116,7 @@ def test_bundle_id_must_start_with_bundle():
def test_create_bundle1(indicator, malware, relationship): def test_create_bundle1(indicator, malware, relationship):
bundle = stix2.v20.Bundle(objects=[indicator, malware, relationship]) bundle = stix2.v20.Bundle(objects=[indicator, malware, relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
@ -129,31 +129,31 @@ def test_create_bundle2(indicator, malware, relationship):
def test_create_bundle_with_positional_args(indicator, malware, relationship): def test_create_bundle_with_positional_args(indicator, malware, relationship):
bundle = stix2.v20.Bundle(indicator, malware, relationship) bundle = stix2.v20.Bundle(indicator, malware, relationship)
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_positional_listarg(indicator, malware, relationship): def test_create_bundle_with_positional_listarg(indicator, malware, relationship):
bundle = stix2.v20.Bundle([indicator, malware, relationship]) bundle = stix2.v20.Bundle([indicator, malware, relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_listarg_and_positional_arg(indicator, malware, relationship): def test_create_bundle_with_listarg_and_positional_arg(indicator, malware, relationship):
bundle = stix2.v20.Bundle([indicator, malware], relationship) bundle = stix2.v20.Bundle([indicator, malware], relationship)
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_listarg_and_kwarg(indicator, malware, relationship): def test_create_bundle_with_listarg_and_kwarg(indicator, malware, relationship):
bundle = stix2.v20.Bundle([indicator, malware], objects=[relationship]) bundle = stix2.v20.Bundle([indicator, malware], objects=[relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_arg_listarg_and_kwarg(indicator, malware, relationship): def test_create_bundle_with_arg_listarg_and_kwarg(indicator, malware, relationship):
bundle = stix2.v20.Bundle([indicator], malware, objects=[relationship]) bundle = stix2.v20.Bundle([indicator], malware, objects=[relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_invalid(indicator, malware, relationship): def test_create_bundle_invalid(indicator, malware, relationship):

View File

@ -21,7 +21,7 @@ EXPECTED = """{
def test_campaign_example(): def test_campaign_example():
campaign = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) campaign = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS)
assert str(campaign) == EXPECTED assert campaign.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -28,7 +28,7 @@ def test_course_of_action_example():
description="This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ...", description="This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ...",
) )
assert str(coa) == EXPECTED assert coa.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -778,7 +778,7 @@ def test_custom_extension_with_list_and_dict_properties_observable_type(data):
pass pass
example = SomeCustomExtension(keys=[{'test123': 123, 'test345': 'aaaa'}]) example = SomeCustomExtension(keys=[{'test123': 123, 'test345': 'aaaa'}])
assert data == str(example) assert data == example.serialize(pretty=True)
def test_custom_extension_invalid_type_name(): def test_custom_extension_invalid_type_name():
@ -992,7 +992,7 @@ def test_custom_object_nested_dictionary(data):
dictionary={'key': {'key_b': 'value', 'key_a': 'value'}}, dictionary={'key': {'key_b': 'value', 'key_a': 'value'}},
) )
assert data == str(example) assert data == example.serialize(pretty=True)
@stix2.v20.CustomObject( @stix2.v20.CustomObject(

View File

@ -26,7 +26,7 @@ def test_external_reference_veris():
url="https://github.com/vz-risk/VCDB/blob/master/data/json/0001AA7F-C601-424A-B2B8-BE6C9F5164E7.json", url="https://github.com/vz-risk/VCDB/blob/master/data/json/0001AA7F-C601-424A-B2B8-BE6C9F5164E7.json",
) )
assert str(ref) == VERIS assert ref.serialize(pretty=True) == VERIS
CAPEC = """{ CAPEC = """{
@ -41,7 +41,7 @@ def test_external_reference_capec():
external_id="CAPEC-550", external_id="CAPEC-550",
) )
assert str(ref) == CAPEC assert ref.serialize(pretty=True) == CAPEC
assert re.match("ExternalReference\\(source_name=u?'capec', external_id=u?'CAPEC-550'\\)", repr(ref)) assert re.match("ExternalReference\\(source_name=u?'capec', external_id=u?'CAPEC-550'\\)", repr(ref))
@ -59,7 +59,7 @@ def test_external_reference_capec_url():
url="http://capec.mitre.org/data/definitions/550.html", url="http://capec.mitre.org/data/definitions/550.html",
) )
assert str(ref) == CAPEC_URL assert ref.serialize(pretty=True) == CAPEC_URL
THREAT_REPORT = """{ THREAT_REPORT = """{
@ -76,7 +76,7 @@ def test_external_reference_threat_report():
url="http://www.example.com/threat-report.pdf", url="http://www.example.com/threat-report.pdf",
) )
assert str(ref) == THREAT_REPORT assert ref.serialize(pretty=True) == THREAT_REPORT
BUGZILLA = """{ BUGZILLA = """{
@ -93,7 +93,7 @@ def test_external_reference_bugzilla():
url="https://www.example.com/bugs/1370", url="https://www.example.com/bugs/1370",
) )
assert str(ref) == BUGZILLA assert ref.serialize(pretty=True) == BUGZILLA
OFFLINE = """{ OFFLINE = """{
@ -108,7 +108,7 @@ def test_external_reference_offline():
description="Threat report", description="Threat report",
) )
assert str(ref) == OFFLINE assert ref.serialize(pretty=True) == OFFLINE
assert re.match("ExternalReference\\(source_name=u?'ACME Threat Intel', description=u?'Threat report'\\)", repr(ref)) assert re.match("ExternalReference\\(source_name=u?'ACME Threat Intel', description=u?'Threat report'\\)", repr(ref))
# Yikes! This works # Yikes! This works
assert eval("stix2." + repr(ref)) == ref assert eval("stix2." + repr(ref)) == ref

View File

@ -26,7 +26,7 @@ def test_identity_example():
identity_class="individual", identity_class="individual",
) )
assert str(identity) == EXPECTED assert identity.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -48,7 +48,7 @@ def test_indicator_with_all_required_properties():
) )
assert ind.revoked is False assert ind.revoked is False
assert str(ind) == EXPECTED_INDICATOR assert ind.serialize(pretty=True) == EXPECTED_INDICATOR
rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(ind)) rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(ind))
assert rep == EXPECTED_INDICATOR_REPR assert rep == EXPECTED_INDICATOR_REPR

View File

@ -38,7 +38,7 @@ def test_intrusion_set_example():
goals=["acquisition-theft", "harassment", "damage"], goals=["acquisition-theft", "harassment", "damage"],
) )
assert str(intrusion_set) == EXPECTED assert intrusion_set.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -16,7 +16,7 @@ def test_lockheed_martin_cyber_kill_chain():
phase_name="reconnaissance", phase_name="reconnaissance",
) )
assert str(recon) == LMCO_RECON assert recon.serialize(pretty=True) == LMCO_RECON
FOO_PRE_ATTACK = """{ FOO_PRE_ATTACK = """{
@ -31,7 +31,7 @@ def test_kill_chain_example():
phase_name="pre-attack", phase_name="pre-attack",
) )
assert str(preattack) == FOO_PRE_ATTACK assert preattack.serialize(pretty=True) == FOO_PRE_ATTACK
def test_kill_chain_required_properties(): def test_kill_chain_required_properties():

View File

@ -33,7 +33,7 @@ def test_malware_with_all_required_properties():
name="Cryptolocker", name="Cryptolocker",
) )
assert str(mal) == EXPECTED_MALWARE assert mal.serialize(pretty=True) == EXPECTED_MALWARE
def test_malware_with_empty_optional_field(): def test_malware_with_empty_optional_field():
@ -49,7 +49,7 @@ def test_malware_with_empty_optional_field():
external_references=[], external_references=[],
) )
assert str(mal) == EXPECTED_MALWARE assert mal.serialize(pretty=True) == EXPECTED_MALWARE
def test_malware_autogenerated_properties(malware): def test_malware_autogenerated_properties(malware):

View File

@ -71,7 +71,7 @@ EXPECTED_CAMPAIGN_WITH_GRANULAR_MARKINGS = """{
def test_marking_def_example_with_tlp(): def test_marking_def_example_with_tlp():
assert str(TLP_WHITE) == EXPECTED_TLP_MARKING_DEFINITION assert TLP_WHITE.serialize(pretty=True) == EXPECTED_TLP_MARKING_DEFINITION
def test_marking_def_example_with_statement_positional_argument(): def test_marking_def_example_with_statement_positional_argument():
@ -82,7 +82,7 @@ def test_marking_def_example_with_statement_positional_argument():
definition=stix2.v20.StatementMarking(statement="Copyright 2016, Example Corp"), definition=stix2.v20.StatementMarking(statement="Copyright 2016, Example Corp"),
) )
assert str(marking_definition) == EXPECTED_STATEMENT_MARKING_DEFINITION assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION
def test_marking_def_example_with_kwargs_statement(): def test_marking_def_example_with_kwargs_statement():
@ -94,7 +94,7 @@ def test_marking_def_example_with_kwargs_statement():
definition=stix2.v20.StatementMarking(**kwargs), definition=stix2.v20.StatementMarking(**kwargs),
) )
assert str(marking_definition) == EXPECTED_STATEMENT_MARKING_DEFINITION assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION
def test_marking_def_invalid_type(): def test_marking_def_invalid_type():
@ -118,7 +118,7 @@ def test_campaign_with_markings_example():
description="Campaign by Green Group against a series of targets in the financial services sector.", description="Campaign by Green Group against a series of targets in the financial services sector.",
object_marking_refs=TLP_WHITE, object_marking_refs=TLP_WHITE,
) )
assert str(campaign) == EXPECTED_CAMPAIGN_WITH_OBJECT_MARKING assert campaign.serialize(pretty=True) == EXPECTED_CAMPAIGN_WITH_OBJECT_MARKING
def test_granular_example(): def test_granular_example():
@ -127,7 +127,7 @@ def test_granular_example():
selectors=["abc", "abc.[23]", "abc.def", "abc.[2].efg"], selectors=["abc", "abc.[23]", "abc.def", "abc.[2].efg"],
) )
assert str(granular_marking) == EXPECTED_GRANULAR_MARKING assert granular_marking.serialize(pretty=True) == EXPECTED_GRANULAR_MARKING
def test_granular_example_with_bad_selector(): def test_granular_example_with_bad_selector():
@ -159,7 +159,7 @@ def test_campaign_with_granular_markings_example():
), ),
], ],
) )
assert str(campaign) == EXPECTED_CAMPAIGN_WITH_GRANULAR_MARKINGS assert campaign.serialize(pretty=True) == EXPECTED_CAMPAIGN_WITH_GRANULAR_MARKINGS
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -47,7 +47,7 @@ def test_observed_data_example():
}, },
) )
assert str(observed_data) == EXPECTED assert observed_data.serialize(pretty=True) == EXPECTED
EXPECTED_WITH_REF = """{ EXPECTED_WITH_REF = """{
@ -97,7 +97,7 @@ def test_observed_data_example_with_refs():
}, },
) )
assert str(observed_data) == EXPECTED_WITH_REF assert observed_data.serialize(pretty=True) == EXPECTED_WITH_REF
def test_observed_data_example_with_bad_refs(): def test_observed_data_example_with_bad_refs():

View File

@ -32,7 +32,7 @@ def test_relationship_all_required_properties():
source_ref=INDICATOR_ID, source_ref=INDICATOR_ID,
target_ref=MALWARE_ID, target_ref=MALWARE_ID,
) )
assert str(rel) == EXPECTED_RELATIONSHIP assert rel.serialize(pretty=True) == EXPECTED_RELATIONSHIP
def test_relationship_autogenerated_properties(relationship): def test_relationship_autogenerated_properties(relationship):

View File

@ -47,7 +47,7 @@ def test_report_example():
], ],
) )
assert str(report) == EXPECTED assert report.serialize(pretty=True) == EXPECTED
def test_report_example_objects_in_object_refs(): def test_report_example_objects_in_object_refs():
@ -67,7 +67,7 @@ def test_report_example_objects_in_object_refs():
], ],
) )
assert str(report) == EXPECTED assert report.serialize(pretty=True) == EXPECTED
def test_report_example_objects_in_object_refs_with_bad_id(): def test_report_example_objects_in_object_refs_with_bad_id():

View File

@ -33,7 +33,7 @@ BAD_SIGHTING = """{
def test_sighting_all_required_properties(): def test_sighting_all_required_properties():
now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc)
s = stix2.v20.Sighting( sighting = stix2.v20.Sighting(
type='sighting', type='sighting',
id=SIGHTING_ID, id=SIGHTING_ID,
created=now, created=now,
@ -41,7 +41,7 @@ def test_sighting_all_required_properties():
sighting_of_ref=INDICATOR_ID, sighting_of_ref=INDICATOR_ID,
where_sighted_refs=[IDENTITY_ID], where_sighted_refs=[IDENTITY_ID],
) )
assert str(s) == EXPECTED_SIGHTING assert sighting.serialize(pretty=True) == EXPECTED_SIGHTING
def test_sighting_bad_where_sighted_refs(): def test_sighting_bad_where_sighted_refs():

View File

@ -32,7 +32,7 @@ def test_threat_actor_example():
name="Evil Org", name="Evil Org",
) )
assert str(threat_actor) == EXPECTED assert threat_actor.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -43,7 +43,7 @@ def test_tool_example():
name="VNC", name="VNC",
) )
assert str(tool) == EXPECTED assert tool.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -36,7 +36,7 @@ def test_vulnerability_example():
], ],
) )
assert str(vulnerability) == EXPECTED assert vulnerability.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -38,7 +38,7 @@ def test_attack_pattern_example():
description="...", description="...",
) )
assert str(ap) == EXPECTED assert ap.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -114,7 +114,7 @@ def test_less_precise_timestamps():
description="...", description="...",
) )
assert str(ap) == EXPECTED assert ap.serialize(pretty=True) == EXPECTED
# TODO: Add other examples # TODO: Add other examples

View File

@ -126,7 +126,7 @@ def test_bundle_id_must_start_with_bundle():
def test_create_bundle1(indicator, malware, relationship): def test_create_bundle1(indicator, malware, relationship):
bundle = stix2.v21.Bundle(objects=[indicator, malware, relationship]) bundle = stix2.v21.Bundle(objects=[indicator, malware, relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
@ -139,31 +139,31 @@ def test_create_bundle2(indicator, malware, relationship):
def test_create_bundle_with_positional_args(indicator, malware, relationship): def test_create_bundle_with_positional_args(indicator, malware, relationship):
bundle = stix2.v21.Bundle(indicator, malware, relationship) bundle = stix2.v21.Bundle(indicator, malware, relationship)
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_positional_listarg(indicator, malware, relationship): def test_create_bundle_with_positional_listarg(indicator, malware, relationship):
bundle = stix2.v21.Bundle([indicator, malware, relationship]) bundle = stix2.v21.Bundle([indicator, malware, relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_listarg_and_positional_arg(indicator, malware, relationship): def test_create_bundle_with_listarg_and_positional_arg(indicator, malware, relationship):
bundle = stix2.v21.Bundle([indicator, malware], relationship) bundle = stix2.v21.Bundle([indicator, malware], relationship)
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_listarg_and_kwarg(indicator, malware, relationship): def test_create_bundle_with_listarg_and_kwarg(indicator, malware, relationship):
bundle = stix2.v21.Bundle([indicator, malware], objects=[relationship]) bundle = stix2.v21.Bundle([indicator, malware], objects=[relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_with_arg_listarg_and_kwarg(indicator, malware, relationship): def test_create_bundle_with_arg_listarg_and_kwarg(indicator, malware, relationship):
bundle = stix2.v21.Bundle([indicator], malware, objects=[relationship]) bundle = stix2.v21.Bundle([indicator], malware, objects=[relationship])
assert str(bundle) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE
def test_create_bundle_invalid(indicator, malware, relationship): def test_create_bundle_invalid(indicator, malware, relationship):

View File

@ -24,7 +24,7 @@ def test_campaign_example():
**CAMPAIGN_MORE_KWARGS **CAMPAIGN_MORE_KWARGS
) )
assert str(campaign) == EXPECTED assert campaign.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -42,7 +42,7 @@ COA_WITH_REF_DICT = json.loads(COA_WITH_REF_JSON)
) )
def test_course_of_action_example(sdo_json, sdo_dict): def test_course_of_action_example(sdo_json, sdo_dict):
coa = stix2.v21.CourseOfAction(**sdo_dict) coa = stix2.v21.CourseOfAction(**sdo_dict)
assert str(coa) == sdo_json assert coa.serialize(pretty=True) == sdo_json
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -965,7 +965,7 @@ def test_custom_extension_with_list_and_dict_properties_observable_type(data):
pass pass
example = SomeCustomExtension(keys=[{'test123': 123, 'test345': 'aaaa'}]) example = SomeCustomExtension(keys=[{'test123': 123, 'test345': 'aaaa'}])
assert data == str(example) assert data == example.serialize(pretty=True)
def test_custom_extension_invalid_type_name(): def test_custom_extension_invalid_type_name():
@ -1202,7 +1202,7 @@ def test_custom_object_nested_dictionary(data):
dictionary={'key': {'key_b': 'value', 'key_a': 'value'}}, dictionary={'key': {'key_b': 'value', 'key_a': 'value'}},
) )
assert data == str(example) assert data == example.serialize(pretty=True)
@stix2.v21.CustomObject( @stix2.v21.CustomObject(

View File

@ -26,7 +26,7 @@ def test_external_reference_veris():
url="https://github.com/vz-risk/VCDB/blob/master/data/json/0001AA7F-C601-424A-B2B8-BE6C9F5164E7.json", url="https://github.com/vz-risk/VCDB/blob/master/data/json/0001AA7F-C601-424A-B2B8-BE6C9F5164E7.json",
) )
assert str(ref) == VERIS assert ref.serialize(pretty=True) == VERIS
CAPEC = """{ CAPEC = """{
@ -41,7 +41,7 @@ def test_external_reference_capec():
external_id="CAPEC-550", external_id="CAPEC-550",
) )
assert str(ref) == CAPEC assert ref.serialize(pretty=True) == CAPEC
assert re.match("ExternalReference\\(source_name=u?'capec', external_id=u?'CAPEC-550'\\)", repr(ref)) assert re.match("ExternalReference\\(source_name=u?'capec', external_id=u?'CAPEC-550'\\)", repr(ref))
@ -59,7 +59,7 @@ def test_external_reference_capec_url():
url="http://capec.mitre.org/data/definitions/550.html", url="http://capec.mitre.org/data/definitions/550.html",
) )
assert str(ref) == CAPEC_URL assert ref.serialize(pretty=True) == CAPEC_URL
THREAT_REPORT = """{ THREAT_REPORT = """{
@ -76,7 +76,7 @@ def test_external_reference_threat_report():
url="http://www.example.com/threat-report.pdf", url="http://www.example.com/threat-report.pdf",
) )
assert str(ref) == THREAT_REPORT assert ref.serialize(pretty=True) == THREAT_REPORT
BUGZILLA = """{ BUGZILLA = """{
@ -93,7 +93,7 @@ def test_external_reference_bugzilla():
url="https://www.example.com/bugs/1370", url="https://www.example.com/bugs/1370",
) )
assert str(ref) == BUGZILLA assert ref.serialize(pretty=True) == BUGZILLA
OFFLINE = """{ OFFLINE = """{
@ -108,7 +108,7 @@ def test_external_reference_offline():
description="Threat report", description="Threat report",
) )
assert str(ref) == OFFLINE assert ref.serialize(pretty=True) == OFFLINE
assert re.match("ExternalReference\\(source_name=u?'ACME Threat Intel', description=u?'Threat report'\\)", repr(ref)) assert re.match("ExternalReference\\(source_name=u?'ACME Threat Intel', description=u?'Threat report'\\)", repr(ref))
# Yikes! This works # Yikes! This works
assert eval("stix2." + repr(ref)) == ref assert eval("stix2." + repr(ref)) == ref

View File

@ -38,7 +38,7 @@ def test_grouping_with_all_required_properties():
], ],
) )
assert str(grp) == EXPECTED_GROUPING assert grp.serialize(pretty=True) == EXPECTED_GROUPING
def test_grouping_autogenerated_properties(grouping): def test_grouping_autogenerated_properties(grouping):

View File

@ -27,7 +27,7 @@ def test_identity_example():
identity_class="individual", identity_class="individual",
) )
assert str(identity) == EXPECTED assert identity.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -27,7 +27,7 @@ def test_incident_example():
description="Intrusion into enterprise network", description="Intrusion into enterprise network",
) )
assert str(incident) == EXPECTED assert incident.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -50,7 +50,7 @@ def test_indicator_with_all_required_properties():
) )
assert ind.revoked is False assert ind.revoked is False
assert str(ind) == EXPECTED_INDICATOR assert ind.serialize(pretty=True) == EXPECTED_INDICATOR
rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(ind)) rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(ind))
assert rep == EXPECTED_INDICATOR_REPR assert rep == EXPECTED_INDICATOR_REPR

View File

@ -28,7 +28,7 @@ def test_infrastructure_with_all_required_properties():
name="Poison Ivy C2", name="Poison Ivy C2",
) )
assert str(infra) == EXPECTED_INFRASTRUCTURE assert infra.serialize(pretty=True) == EXPECTED_INFRASTRUCTURE
def test_infrastructure_autogenerated_properties(infrastructure): def test_infrastructure_autogenerated_properties(infrastructure):

View File

@ -39,7 +39,7 @@ def test_intrusion_set_example():
goals=["acquisition-theft", "harassment", "damage"], goals=["acquisition-theft", "harassment", "damage"],
) )
assert str(intrusion_set) == EXPECTED assert intrusion_set.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -16,7 +16,7 @@ def test_lockheed_martin_cyber_kill_chain():
phase_name="reconnaissance", phase_name="reconnaissance",
) )
assert str(recon) == LMCO_RECON assert recon.serialize(pretty=True) == LMCO_RECON
FOO_PRE_ATTACK = """{ FOO_PRE_ATTACK = """{
@ -31,7 +31,7 @@ def test_kill_chain_example():
phase_name="pre-attack", phase_name="pre-attack",
) )
assert str(preattack) == FOO_PRE_ATTACK assert preattack.serialize(pretty=True) == FOO_PRE_ATTACK
def test_kill_chain_required_properties(): def test_kill_chain_required_properties():

View File

@ -54,7 +54,7 @@ EXPECTED_LOCATION_2_REPR = "Location(" + " ".join(
def test_location_with_some_required_properties(): def test_location_with_some_required_properties():
now = dt.datetime(2016, 4, 6, 20, 3, 0, tzinfo=pytz.utc) now = dt.datetime(2016, 4, 6, 20, 3, 0, tzinfo=pytz.utc)
loc = stix2.v21.Location( location = stix2.v21.Location(
id=LOCATION_ID, id=LOCATION_ID,
created=now, created=now,
modified=now, modified=now,
@ -62,8 +62,8 @@ def test_location_with_some_required_properties():
longitude=2.3522, longitude=2.3522,
) )
assert str(loc) == EXPECTED_LOCATION_1 assert location.serialize(pretty=True) == EXPECTED_LOCATION_1
rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(loc)) rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(location))
assert rep == EXPECTED_LOCATION_1_REPR assert rep == EXPECTED_LOCATION_1_REPR

View File

@ -23,7 +23,7 @@ EXPECTED_MALWARE = """{
def test_malware_with_all_required_properties(): def test_malware_with_all_required_properties():
now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc) now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc)
mal = stix2.v21.Malware( malware = stix2.v21.Malware(
type="malware", type="malware",
id=MALWARE_ID, id=MALWARE_ID,
created=now, created=now,
@ -32,7 +32,7 @@ def test_malware_with_all_required_properties():
is_family=False, is_family=False,
) )
assert str(mal) == EXPECTED_MALWARE assert malware.serialize(pretty=True) == EXPECTED_MALWARE
def test_malware_autogenerated_properties(malware): def test_malware_autogenerated_properties(malware):

View File

@ -48,9 +48,9 @@ MALWARE_ANALYSIS_DICT = json.loads(MALWARE_ANALYSIS_JSON)
def test_malware_analysis_example(): def test_malware_analysis_example():
ma = stix2.v21.MalwareAnalysis(**MALWARE_ANALYSIS_DICT) malware_analysis = stix2.v21.MalwareAnalysis(**MALWARE_ANALYSIS_DICT)
assert str(ma) == MALWARE_ANALYSIS_JSON assert malware_analysis.serialize(pretty=True) == MALWARE_ANALYSIS_JSON
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -99,7 +99,7 @@ EXPECTED_CAMPAIGN_WITH_GRANULAR_LANG_MARKINGS = u"""{
def test_marking_def_example_with_tlp(): def test_marking_def_example_with_tlp():
assert str(TLP_WHITE) == EXPECTED_TLP_MARKING_DEFINITION assert TLP_WHITE.serialize(pretty=True) == EXPECTED_TLP_MARKING_DEFINITION
def test_marking_def_example_with_statement_positional_argument(): def test_marking_def_example_with_statement_positional_argument():
@ -110,7 +110,7 @@ def test_marking_def_example_with_statement_positional_argument():
definition=stix2.StatementMarking(statement="Copyright 2016, Example Corp"), definition=stix2.StatementMarking(statement="Copyright 2016, Example Corp"),
) )
assert str(marking_definition) == EXPECTED_STATEMENT_MARKING_DEFINITION assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION
def test_marking_def_example_with_kwargs_statement(): def test_marking_def_example_with_kwargs_statement():
@ -122,7 +122,7 @@ def test_marking_def_example_with_kwargs_statement():
definition=stix2.StatementMarking(**kwargs), definition=stix2.StatementMarking(**kwargs),
) )
assert str(marking_definition) == EXPECTED_STATEMENT_MARKING_DEFINITION assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION
def test_marking_def_invalid_type(): def test_marking_def_invalid_type():
@ -145,7 +145,7 @@ def test_campaign_with_markings_example():
description="Campaign by Green Group against a series of targets in the financial services sector.", description="Campaign by Green Group against a series of targets in the financial services sector.",
object_marking_refs=TLP_WHITE, object_marking_refs=TLP_WHITE,
) )
assert str(campaign) == EXPECTED_CAMPAIGN_WITH_OBJECT_MARKING assert campaign.serialize(pretty=True) == EXPECTED_CAMPAIGN_WITH_OBJECT_MARKING
def test_granular_example(): def test_granular_example():
@ -154,7 +154,7 @@ def test_granular_example():
selectors=["abc", "abc.[23]", "abc.def", "abc.[2].efg"], selectors=["abc", "abc.[23]", "abc.def", "abc.[2].efg"],
) )
assert str(granular_marking) == EXPECTED_GRANULAR_MARKING assert granular_marking.serialize(pretty=True) == EXPECTED_GRANULAR_MARKING
def test_granular_example_with_bad_selector(): def test_granular_example_with_bad_selector():
@ -185,7 +185,7 @@ def test_campaign_with_granular_markings_example():
), ),
], ],
) )
assert str(campaign) == EXPECTED_CAMPAIGN_WITH_GRANULAR_REF_MARKINGS assert campaign.serialize(pretty=True) == EXPECTED_CAMPAIGN_WITH_GRANULAR_REF_MARKINGS
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -73,7 +73,7 @@ def test_note_with_required_properties():
], ],
) )
assert str(note) == EXPECTED_NOTE assert note.serialize(pretty=True) == EXPECTED_NOTE
rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(note)) rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(note))
assert rep == EXPECTED_OPINION_REPR assert rep == EXPECTED_OPINION_REPR

View File

@ -155,7 +155,7 @@ def test_observed_data_example_with_object_refs():
], ],
) )
assert str(observed_data) == EXPECTED_OBJECT_REFS assert observed_data.serialize(pretty=True) == EXPECTED_OBJECT_REFS
def test_observed_data_object_constraint(): def test_observed_data_object_constraint():

View File

@ -56,7 +56,7 @@ def test_opinion_with_required_properties():
explanation=EXPLANATION, explanation=EXPLANATION,
) )
assert str(opi) == EXPECTED_OPINION assert opi.serialize(pretty=True) == EXPECTED_OPINION
rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(opi)) rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(opi))
assert rep == EXPECTED_OPINION_REPR assert rep == EXPECTED_OPINION_REPR

View File

@ -33,7 +33,7 @@ def test_relationship_all_required_properties():
source_ref=INDICATOR_ID, source_ref=INDICATOR_ID,
target_ref=MALWARE_ID, target_ref=MALWARE_ID,
) )
assert str(rel) == EXPECTED_RELATIONSHIP assert rel.serialize(pretty=True) == EXPECTED_RELATIONSHIP
def test_relationship_autogenerated_properties(relationship): def test_relationship_autogenerated_properties(relationship):

View File

@ -48,7 +48,7 @@ def test_report_example():
], ],
) )
assert str(report) == EXPECTED assert report.serialize(pretty=True) == EXPECTED
def test_report_example_objects_in_object_refs(): def test_report_example_objects_in_object_refs():
@ -68,7 +68,7 @@ def test_report_example_objects_in_object_refs():
], ],
) )
assert str(report) == EXPECTED assert report.serialize(pretty=True) == EXPECTED
def test_report_example_objects_in_object_refs_with_bad_id(): def test_report_example_objects_in_object_refs_with_bad_id():

View File

@ -38,7 +38,7 @@ BAD_SIGHTING = """{
def test_sighting_all_required_properties(): def test_sighting_all_required_properties():
now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc)
s = stix2.v21.Sighting( sighting = stix2.v21.Sighting(
type='sighting', type='sighting',
id=SIGHTING_ID, id=SIGHTING_ID,
created=now, created=now,
@ -46,7 +46,7 @@ def test_sighting_all_required_properties():
sighting_of_ref=INDICATOR_ID, sighting_of_ref=INDICATOR_ID,
where_sighted_refs=[IDENTITY_ID, LOCATION_ID], where_sighted_refs=[IDENTITY_ID, LOCATION_ID],
) )
assert str(s) == EXPECTED_SIGHTING assert sighting.serialize(pretty=True) == EXPECTED_SIGHTING
def test_sighting_bad_where_sighted_refs(): def test_sighting_bad_where_sighted_refs():

View File

@ -34,7 +34,7 @@ def test_threat_actor_example():
threat_actor_types=["crime-syndicate"], threat_actor_types=["crime-syndicate"],
) )
assert str(threat_actor) == EXPECTED assert threat_actor.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -45,7 +45,7 @@ def test_tool_example():
tool_types=["remote-access"], tool_types=["remote-access"],
) )
assert str(tool) == EXPECTED assert tool.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -37,7 +37,7 @@ def test_vulnerability_example():
], ],
) )
assert str(vulnerability) == EXPECTED assert vulnerability.serialize(pretty=True) == EXPECTED
@pytest.mark.parametrize( @pytest.mark.parametrize(