From 8930e72cc390c9920b1a8dc4a06a1cec87948bbc Mon Sep 17 00:00:00 2001 From: Sam Cornwell <14048146+samcornwell@users.noreply.github.com> Date: Sun, 19 Nov 2017 22:11:44 -0500 Subject: [PATCH 1/3] added get_type_from_id function to utils --- stix2/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stix2/utils.py b/stix2/utils.py index f23dbe2..960b89e 100644 --- a/stix2/utils.py +++ b/stix2/utils.py @@ -255,3 +255,6 @@ def get_class_hierarchy_names(obj): for cls in obj.__class__.__mro__: names.append(cls.__name__) return names + +def get_type_from_id(stix_id): + return stix_id.split('--', 1)[0] From 78612530ffa06bc5a49e0c8f3201950de80cdeac Mon Sep 17 00:00:00 2001 From: Sam Cornwell <14048146+samcornwell@users.noreply.github.com> Date: Sun, 19 Nov 2017 22:27:31 -0500 Subject: [PATCH 2/3] added tests for get_type_from_id --- stix2/test/test_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stix2/test/test_utils.py b/stix2/test/test_utils.py index c73bcd2..cbe5b0f 100644 --- a/stix2/test/test_utils.py +++ b/stix2/test/test_utils.py @@ -74,3 +74,11 @@ def test_get_dict(data): def test_get_dict_invalid(data): with pytest.raises(ValueError): stix2.utils.get_dict(data) + + +@pytest.mark.parametrize('stix_id, typ', [ + ('malware--d69c8146-ab35-4d50-8382-6fc80e641d43', 'malware'), + ('intrusion-set--899ce53f-13a0-479b-a0e4-67d46e241542', 'intrusion-set') +]) +def test_get_type_from_id(stix_id, typ): + assert stix2.utils.get_type_from_id(stix_id) == typ From eff51a2bb8ad5f5dbe8c07ab314a70f809073c4b Mon Sep 17 00:00:00 2001 From: Sam Cornwell <14048146+samcornwell@users.noreply.github.com> Date: Sun, 19 Nov 2017 23:00:42 -0500 Subject: [PATCH 3/3] fixed pycodestyle failure --- stix2/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stix2/utils.py b/stix2/utils.py index 960b89e..541e6d8 100644 --- a/stix2/utils.py +++ b/stix2/utils.py @@ -256,5 +256,6 @@ def get_class_hierarchy_names(obj): names.append(cls.__name__) return names + def get_type_from_id(stix_id): return stix_id.split('--', 1)[0]