diff --git a/stix2/test/v20/test_attack_pattern.py b/stix2/test/v20/test_attack_pattern.py index cc24fa9..1f53450 100644 --- a/stix2/test/v20/test_attack_pattern.py +++ b/stix2/test/v20/test_attack_pattern.py @@ -37,7 +37,7 @@ def test_attack_pattern_example(): description="...", ) - assert str(ap) == EXPECTED + assert ap.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( @@ -111,6 +111,6 @@ def test_less_precise_timestamps(): description="...", ) - assert str(ap) == EXPECTED + assert ap.serialize(pretty=True) == EXPECTED # TODO: Add other examples diff --git a/stix2/test/v20/test_bundle.py b/stix2/test/v20/test_bundle.py index f53d0cb..3e09192 100644 --- a/stix2/test/v20/test_bundle.py +++ b/stix2/test/v20/test_bundle.py @@ -116,7 +116,7 @@ def test_bundle_id_must_start_with_bundle(): def test_create_bundle1(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 @@ -129,31 +129,31 @@ def test_create_bundle2(indicator, malware, relationship): def test_create_bundle_with_positional_args(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): 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): 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): 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): 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): diff --git a/stix2/test/v20/test_campaign.py b/stix2/test/v20/test_campaign.py index 0d4a202..13b47b0 100644 --- a/stix2/test/v20/test_campaign.py +++ b/stix2/test/v20/test_campaign.py @@ -21,7 +21,7 @@ EXPECTED = """{ def test_campaign_example(): campaign = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) - assert str(campaign) == EXPECTED + assert campaign.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_course_of_action.py b/stix2/test/v20/test_course_of_action.py index f648907..c778316 100644 --- a/stix2/test/v20/test_course_of_action.py +++ b/stix2/test/v20/test_course_of_action.py @@ -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 ...", ) - assert str(coa) == EXPECTED + assert coa.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_custom.py b/stix2/test/v20/test_custom.py index f5e7024..b5d86b5 100644 --- a/stix2/test/v20/test_custom.py +++ b/stix2/test/v20/test_custom.py @@ -778,7 +778,7 @@ def test_custom_extension_with_list_and_dict_properties_observable_type(data): pass example = SomeCustomExtension(keys=[{'test123': 123, 'test345': 'aaaa'}]) - assert data == str(example) + assert data == example.serialize(pretty=True) 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'}}, ) - assert data == str(example) + assert data == example.serialize(pretty=True) @stix2.v20.CustomObject( diff --git a/stix2/test/v20/test_external_reference.py b/stix2/test/v20/test_external_reference.py index 07cf42d..04821cd 100644 --- a/stix2/test/v20/test_external_reference.py +++ b/stix2/test/v20/test_external_reference.py @@ -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", ) - assert str(ref) == VERIS + assert ref.serialize(pretty=True) == VERIS CAPEC = """{ @@ -41,7 +41,7 @@ def test_external_reference_capec(): 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)) @@ -59,7 +59,7 @@ def test_external_reference_capec_url(): url="http://capec.mitre.org/data/definitions/550.html", ) - assert str(ref) == CAPEC_URL + assert ref.serialize(pretty=True) == CAPEC_URL THREAT_REPORT = """{ @@ -76,7 +76,7 @@ def test_external_reference_threat_report(): url="http://www.example.com/threat-report.pdf", ) - assert str(ref) == THREAT_REPORT + assert ref.serialize(pretty=True) == THREAT_REPORT BUGZILLA = """{ @@ -93,7 +93,7 @@ def test_external_reference_bugzilla(): url="https://www.example.com/bugs/1370", ) - assert str(ref) == BUGZILLA + assert ref.serialize(pretty=True) == BUGZILLA OFFLINE = """{ @@ -108,7 +108,7 @@ def test_external_reference_offline(): 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)) # Yikes! This works assert eval("stix2." + repr(ref)) == ref diff --git a/stix2/test/v20/test_identity.py b/stix2/test/v20/test_identity.py index 750c6f2..c62da46 100644 --- a/stix2/test/v20/test_identity.py +++ b/stix2/test/v20/test_identity.py @@ -26,7 +26,7 @@ def test_identity_example(): identity_class="individual", ) - assert str(identity) == EXPECTED + assert identity.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_indicator.py b/stix2/test/v20/test_indicator.py index 6f3bfea..47f4812 100644 --- a/stix2/test/v20/test_indicator.py +++ b/stix2/test/v20/test_indicator.py @@ -48,7 +48,7 @@ def test_indicator_with_all_required_properties(): ) 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)) assert rep == EXPECTED_INDICATOR_REPR diff --git a/stix2/test/v20/test_intrusion_set.py b/stix2/test/v20/test_intrusion_set.py index 69b336e..59a9905 100644 --- a/stix2/test/v20/test_intrusion_set.py +++ b/stix2/test/v20/test_intrusion_set.py @@ -38,7 +38,7 @@ def test_intrusion_set_example(): goals=["acquisition-theft", "harassment", "damage"], ) - assert str(intrusion_set) == EXPECTED + assert intrusion_set.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_kill_chain_phases.py b/stix2/test/v20/test_kill_chain_phases.py index d150757..7f65f00 100644 --- a/stix2/test/v20/test_kill_chain_phases.py +++ b/stix2/test/v20/test_kill_chain_phases.py @@ -16,7 +16,7 @@ def test_lockheed_martin_cyber_kill_chain(): phase_name="reconnaissance", ) - assert str(recon) == LMCO_RECON + assert recon.serialize(pretty=True) == LMCO_RECON FOO_PRE_ATTACK = """{ @@ -31,7 +31,7 @@ def test_kill_chain_example(): phase_name="pre-attack", ) - assert str(preattack) == FOO_PRE_ATTACK + assert preattack.serialize(pretty=True) == FOO_PRE_ATTACK def test_kill_chain_required_properties(): diff --git a/stix2/test/v20/test_malware.py b/stix2/test/v20/test_malware.py index bd49007..974caf0 100644 --- a/stix2/test/v20/test_malware.py +++ b/stix2/test/v20/test_malware.py @@ -33,7 +33,7 @@ def test_malware_with_all_required_properties(): name="Cryptolocker", ) - assert str(mal) == EXPECTED_MALWARE + assert mal.serialize(pretty=True) == EXPECTED_MALWARE def test_malware_with_empty_optional_field(): @@ -49,7 +49,7 @@ def test_malware_with_empty_optional_field(): external_references=[], ) - assert str(mal) == EXPECTED_MALWARE + assert mal.serialize(pretty=True) == EXPECTED_MALWARE def test_malware_autogenerated_properties(malware): diff --git a/stix2/test/v20/test_markings.py b/stix2/test/v20/test_markings.py index 0753e86..f7d15fa 100644 --- a/stix2/test/v20/test_markings.py +++ b/stix2/test/v20/test_markings.py @@ -71,7 +71,7 @@ EXPECTED_CAMPAIGN_WITH_GRANULAR_MARKINGS = """{ 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(): @@ -82,7 +82,7 @@ def test_marking_def_example_with_statement_positional_argument(): 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(): @@ -94,7 +94,7 @@ def test_marking_def_example_with_kwargs_statement(): 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(): @@ -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.", 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(): @@ -127,7 +127,7 @@ def test_granular_example(): 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(): @@ -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( diff --git a/stix2/test/v20/test_observed_data.py b/stix2/test/v20/test_observed_data.py index bd60383..79ed6c4 100644 --- a/stix2/test/v20/test_observed_data.py +++ b/stix2/test/v20/test_observed_data.py @@ -47,7 +47,7 @@ def test_observed_data_example(): }, ) - assert str(observed_data) == EXPECTED + assert observed_data.serialize(pretty=True) == EXPECTED 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(): diff --git a/stix2/test/v20/test_relationship.py b/stix2/test/v20/test_relationship.py index a0fccf4..f8ad67e 100644 --- a/stix2/test/v20/test_relationship.py +++ b/stix2/test/v20/test_relationship.py @@ -32,7 +32,7 @@ def test_relationship_all_required_properties(): source_ref=INDICATOR_ID, target_ref=MALWARE_ID, ) - assert str(rel) == EXPECTED_RELATIONSHIP + assert rel.serialize(pretty=True) == EXPECTED_RELATIONSHIP def test_relationship_autogenerated_properties(relationship): diff --git a/stix2/test/v20/test_report.py b/stix2/test/v20/test_report.py index 53707ce..557a374 100644 --- a/stix2/test/v20/test_report.py +++ b/stix2/test/v20/test_report.py @@ -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(): @@ -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(): diff --git a/stix2/test/v20/test_sighting.py b/stix2/test/v20/test_sighting.py index 6bad63c..35cd1f1 100644 --- a/stix2/test/v20/test_sighting.py +++ b/stix2/test/v20/test_sighting.py @@ -33,7 +33,7 @@ BAD_SIGHTING = """{ def test_sighting_all_required_properties(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - s = stix2.v20.Sighting( + sighting = stix2.v20.Sighting( type='sighting', id=SIGHTING_ID, created=now, @@ -41,7 +41,7 @@ def test_sighting_all_required_properties(): sighting_of_ref=INDICATOR_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(): diff --git a/stix2/test/v20/test_threat_actor.py b/stix2/test/v20/test_threat_actor.py index 854e77a..0214f9b 100644 --- a/stix2/test/v20/test_threat_actor.py +++ b/stix2/test/v20/test_threat_actor.py @@ -32,7 +32,7 @@ def test_threat_actor_example(): name="Evil Org", ) - assert str(threat_actor) == EXPECTED + assert threat_actor.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_tool.py b/stix2/test/v20/test_tool.py index 435b85e..dcb94be 100644 --- a/stix2/test/v20/test_tool.py +++ b/stix2/test/v20/test_tool.py @@ -43,7 +43,7 @@ def test_tool_example(): name="VNC", ) - assert str(tool) == EXPECTED + assert tool.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_vulnerability.py b/stix2/test/v20/test_vulnerability.py index 5a69d82..b87152f 100644 --- a/stix2/test/v20/test_vulnerability.py +++ b/stix2/test/v20/test_vulnerability.py @@ -36,7 +36,7 @@ def test_vulnerability_example(): ], ) - assert str(vulnerability) == EXPECTED + assert vulnerability.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_attack_pattern.py b/stix2/test/v21/test_attack_pattern.py index 0beda64..96a2869 100644 --- a/stix2/test/v21/test_attack_pattern.py +++ b/stix2/test/v21/test_attack_pattern.py @@ -38,7 +38,7 @@ def test_attack_pattern_example(): description="...", ) - assert str(ap) == EXPECTED + assert ap.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( @@ -114,7 +114,7 @@ def test_less_precise_timestamps(): description="...", ) - assert str(ap) == EXPECTED + assert ap.serialize(pretty=True) == EXPECTED # TODO: Add other examples diff --git a/stix2/test/v21/test_bundle.py b/stix2/test/v21/test_bundle.py index 4e30c84..2eeaff4 100644 --- a/stix2/test/v21/test_bundle.py +++ b/stix2/test/v21/test_bundle.py @@ -126,7 +126,7 @@ def test_bundle_id_must_start_with_bundle(): def test_create_bundle1(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 @@ -139,31 +139,31 @@ def test_create_bundle2(indicator, malware, relationship): def test_create_bundle_with_positional_args(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): 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): 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): 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): 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): diff --git a/stix2/test/v21/test_campaign.py b/stix2/test/v21/test_campaign.py index 10f5d7b..edc7d77 100644 --- a/stix2/test/v21/test_campaign.py +++ b/stix2/test/v21/test_campaign.py @@ -24,7 +24,7 @@ def test_campaign_example(): **CAMPAIGN_MORE_KWARGS ) - assert str(campaign) == EXPECTED + assert campaign.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_course_of_action.py b/stix2/test/v21/test_course_of_action.py index 5eea908..964a556 100644 --- a/stix2/test/v21/test_course_of_action.py +++ b/stix2/test/v21/test_course_of_action.py @@ -42,7 +42,7 @@ COA_WITH_REF_DICT = json.loads(COA_WITH_REF_JSON) ) def test_course_of_action_example(sdo_json, sdo_dict): coa = stix2.v21.CourseOfAction(**sdo_dict) - assert str(coa) == sdo_json + assert coa.serialize(pretty=True) == sdo_json @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_custom.py b/stix2/test/v21/test_custom.py index 79a4d03..ac46d84 100644 --- a/stix2/test/v21/test_custom.py +++ b/stix2/test/v21/test_custom.py @@ -965,7 +965,7 @@ def test_custom_extension_with_list_and_dict_properties_observable_type(data): pass example = SomeCustomExtension(keys=[{'test123': 123, 'test345': 'aaaa'}]) - assert data == str(example) + assert data == example.serialize(pretty=True) 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'}}, ) - assert data == str(example) + assert data == example.serialize(pretty=True) @stix2.v21.CustomObject( diff --git a/stix2/test/v21/test_external_reference.py b/stix2/test/v21/test_external_reference.py index f347191..9316857 100644 --- a/stix2/test/v21/test_external_reference.py +++ b/stix2/test/v21/test_external_reference.py @@ -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", ) - assert str(ref) == VERIS + assert ref.serialize(pretty=True) == VERIS CAPEC = """{ @@ -41,7 +41,7 @@ def test_external_reference_capec(): 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)) @@ -59,7 +59,7 @@ def test_external_reference_capec_url(): url="http://capec.mitre.org/data/definitions/550.html", ) - assert str(ref) == CAPEC_URL + assert ref.serialize(pretty=True) == CAPEC_URL THREAT_REPORT = """{ @@ -76,7 +76,7 @@ def test_external_reference_threat_report(): url="http://www.example.com/threat-report.pdf", ) - assert str(ref) == THREAT_REPORT + assert ref.serialize(pretty=True) == THREAT_REPORT BUGZILLA = """{ @@ -93,7 +93,7 @@ def test_external_reference_bugzilla(): url="https://www.example.com/bugs/1370", ) - assert str(ref) == BUGZILLA + assert ref.serialize(pretty=True) == BUGZILLA OFFLINE = """{ @@ -108,7 +108,7 @@ def test_external_reference_offline(): 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)) # Yikes! This works assert eval("stix2." + repr(ref)) == ref diff --git a/stix2/test/v21/test_grouping.py b/stix2/test/v21/test_grouping.py index a92a180..e495888 100644 --- a/stix2/test/v21/test_grouping.py +++ b/stix2/test/v21/test_grouping.py @@ -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): diff --git a/stix2/test/v21/test_identity.py b/stix2/test/v21/test_identity.py index 9d17723..c235b4d 100644 --- a/stix2/test/v21/test_identity.py +++ b/stix2/test/v21/test_identity.py @@ -27,7 +27,7 @@ def test_identity_example(): identity_class="individual", ) - assert str(identity) == EXPECTED + assert identity.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_incident.py b/stix2/test/v21/test_incident.py index 7ee07b8..27bc254 100644 --- a/stix2/test/v21/test_incident.py +++ b/stix2/test/v21/test_incident.py @@ -27,7 +27,7 @@ def test_incident_example(): description="Intrusion into enterprise network", ) - assert str(incident) == EXPECTED + assert incident.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_indicator.py b/stix2/test/v21/test_indicator.py index 2b22418..c6220d7 100644 --- a/stix2/test/v21/test_indicator.py +++ b/stix2/test/v21/test_indicator.py @@ -50,7 +50,7 @@ def test_indicator_with_all_required_properties(): ) 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)) assert rep == EXPECTED_INDICATOR_REPR diff --git a/stix2/test/v21/test_infrastructure.py b/stix2/test/v21/test_infrastructure.py index 3e9feb7..2beb6aa 100644 --- a/stix2/test/v21/test_infrastructure.py +++ b/stix2/test/v21/test_infrastructure.py @@ -28,7 +28,7 @@ def test_infrastructure_with_all_required_properties(): name="Poison Ivy C2", ) - assert str(infra) == EXPECTED_INFRASTRUCTURE + assert infra.serialize(pretty=True) == EXPECTED_INFRASTRUCTURE def test_infrastructure_autogenerated_properties(infrastructure): diff --git a/stix2/test/v21/test_intrusion_set.py b/stix2/test/v21/test_intrusion_set.py index 778eda7..2b2dc0c 100644 --- a/stix2/test/v21/test_intrusion_set.py +++ b/stix2/test/v21/test_intrusion_set.py @@ -39,7 +39,7 @@ def test_intrusion_set_example(): goals=["acquisition-theft", "harassment", "damage"], ) - assert str(intrusion_set) == EXPECTED + assert intrusion_set.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_kill_chain_phases.py b/stix2/test/v21/test_kill_chain_phases.py index 0acc538..9e29e88 100644 --- a/stix2/test/v21/test_kill_chain_phases.py +++ b/stix2/test/v21/test_kill_chain_phases.py @@ -16,7 +16,7 @@ def test_lockheed_martin_cyber_kill_chain(): phase_name="reconnaissance", ) - assert str(recon) == LMCO_RECON + assert recon.serialize(pretty=True) == LMCO_RECON FOO_PRE_ATTACK = """{ @@ -31,7 +31,7 @@ def test_kill_chain_example(): phase_name="pre-attack", ) - assert str(preattack) == FOO_PRE_ATTACK + assert preattack.serialize(pretty=True) == FOO_PRE_ATTACK def test_kill_chain_required_properties(): diff --git a/stix2/test/v21/test_location.py b/stix2/test/v21/test_location.py index cf9c101..0fc5bcb 100644 --- a/stix2/test/v21/test_location.py +++ b/stix2/test/v21/test_location.py @@ -54,7 +54,7 @@ EXPECTED_LOCATION_2_REPR = "Location(" + " ".join( def test_location_with_some_required_properties(): now = dt.datetime(2016, 4, 6, 20, 3, 0, tzinfo=pytz.utc) - loc = stix2.v21.Location( + location = stix2.v21.Location( id=LOCATION_ID, created=now, modified=now, @@ -62,8 +62,8 @@ def test_location_with_some_required_properties(): longitude=2.3522, ) - assert str(loc) == EXPECTED_LOCATION_1 - rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(loc)) + assert location.serialize(pretty=True) == EXPECTED_LOCATION_1 + rep = re.sub(r"(\[|=| )u('|\"|\\\'|\\\")", r"\g<1>\g<2>", repr(location)) assert rep == EXPECTED_LOCATION_1_REPR diff --git a/stix2/test/v21/test_malware.py b/stix2/test/v21/test_malware.py index f111826..d71b273 100644 --- a/stix2/test/v21/test_malware.py +++ b/stix2/test/v21/test_malware.py @@ -23,7 +23,7 @@ EXPECTED_MALWARE = """{ def test_malware_with_all_required_properties(): now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc) - mal = stix2.v21.Malware( + malware = stix2.v21.Malware( type="malware", id=MALWARE_ID, created=now, @@ -32,7 +32,7 @@ def test_malware_with_all_required_properties(): is_family=False, ) - assert str(mal) == EXPECTED_MALWARE + assert malware.serialize(pretty=True) == EXPECTED_MALWARE def test_malware_autogenerated_properties(malware): diff --git a/stix2/test/v21/test_malware_analysis.py b/stix2/test/v21/test_malware_analysis.py index bf4bbe6..1390203 100644 --- a/stix2/test/v21/test_malware_analysis.py +++ b/stix2/test/v21/test_malware_analysis.py @@ -48,9 +48,9 @@ MALWARE_ANALYSIS_DICT = json.loads(MALWARE_ANALYSIS_JSON) 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( diff --git a/stix2/test/v21/test_markings.py b/stix2/test/v21/test_markings.py index b0a0d09..d3fd11b 100644 --- a/stix2/test/v21/test_markings.py +++ b/stix2/test/v21/test_markings.py @@ -99,7 +99,7 @@ EXPECTED_CAMPAIGN_WITH_GRANULAR_LANG_MARKINGS = u"""{ 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(): @@ -110,7 +110,7 @@ def test_marking_def_example_with_statement_positional_argument(): 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(): @@ -122,7 +122,7 @@ def test_marking_def_example_with_kwargs_statement(): 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(): @@ -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.", 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(): @@ -154,7 +154,7 @@ def test_granular_example(): 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(): @@ -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( diff --git a/stix2/test/v21/test_note.py b/stix2/test/v21/test_note.py index 47a191e..2f20c8d 100644 --- a/stix2/test/v21/test_note.py +++ b/stix2/test/v21/test_note.py @@ -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)) assert rep == EXPECTED_OPINION_REPR diff --git a/stix2/test/v21/test_observed_data.py b/stix2/test/v21/test_observed_data.py index c1cb38e..ccf9a70 100644 --- a/stix2/test/v21/test_observed_data.py +++ b/stix2/test/v21/test_observed_data.py @@ -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(): diff --git a/stix2/test/v21/test_opinion.py b/stix2/test/v21/test_opinion.py index 9634d6e..21c96d7 100644 --- a/stix2/test/v21/test_opinion.py +++ b/stix2/test/v21/test_opinion.py @@ -56,7 +56,7 @@ def test_opinion_with_required_properties(): 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)) assert rep == EXPECTED_OPINION_REPR diff --git a/stix2/test/v21/test_relationship.py b/stix2/test/v21/test_relationship.py index 386e24b..9f76d92 100644 --- a/stix2/test/v21/test_relationship.py +++ b/stix2/test/v21/test_relationship.py @@ -33,7 +33,7 @@ def test_relationship_all_required_properties(): source_ref=INDICATOR_ID, target_ref=MALWARE_ID, ) - assert str(rel) == EXPECTED_RELATIONSHIP + assert rel.serialize(pretty=True) == EXPECTED_RELATIONSHIP def test_relationship_autogenerated_properties(relationship): diff --git a/stix2/test/v21/test_report.py b/stix2/test/v21/test_report.py index e54e11d..87ac1c1 100644 --- a/stix2/test/v21/test_report.py +++ b/stix2/test/v21/test_report.py @@ -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(): @@ -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(): diff --git a/stix2/test/v21/test_sighting.py b/stix2/test/v21/test_sighting.py index 0ef5faa..e997d62 100644 --- a/stix2/test/v21/test_sighting.py +++ b/stix2/test/v21/test_sighting.py @@ -38,7 +38,7 @@ BAD_SIGHTING = """{ def test_sighting_all_required_properties(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - s = stix2.v21.Sighting( + sighting = stix2.v21.Sighting( type='sighting', id=SIGHTING_ID, created=now, @@ -46,7 +46,7 @@ def test_sighting_all_required_properties(): sighting_of_ref=INDICATOR_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(): diff --git a/stix2/test/v21/test_threat_actor.py b/stix2/test/v21/test_threat_actor.py index 6a782ef..94dea8e 100644 --- a/stix2/test/v21/test_threat_actor.py +++ b/stix2/test/v21/test_threat_actor.py @@ -34,7 +34,7 @@ def test_threat_actor_example(): threat_actor_types=["crime-syndicate"], ) - assert str(threat_actor) == EXPECTED + assert threat_actor.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_tool.py b/stix2/test/v21/test_tool.py index 6a7d89c..427f8de 100644 --- a/stix2/test/v21/test_tool.py +++ b/stix2/test/v21/test_tool.py @@ -45,7 +45,7 @@ def test_tool_example(): tool_types=["remote-access"], ) - assert str(tool) == EXPECTED + assert tool.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_vulnerability.py b/stix2/test/v21/test_vulnerability.py index ee63a0e..bcea913 100644 --- a/stix2/test/v21/test_vulnerability.py +++ b/stix2/test/v21/test_vulnerability.py @@ -37,7 +37,7 @@ def test_vulnerability_example(): ], ) - assert str(vulnerability) == EXPECTED + assert vulnerability.serialize(pretty=True) == EXPECTED @pytest.mark.parametrize(