Repository: oasis-open/cti-python-stix2

Issue:
make_constant() should check if value is already a constant
``` python
>>> from stix2.patterns import StringConstant
>>> from stix2.patterns import make_constant
>>> a = StringConstant('foo')
>>> make_constant(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lu/Projects/cti-python-stix2/stix2/patterns.py", line 166, in make_constant
    raise ValueError("Unable to create a constant from %s" % value)
ValueError: Unable to create a constant from 'foo'
```

Discussion:

Patch:
diff --git a/stix2/patterns.py b/stix2/patterns.py
index 23ce71b..3f9cbd9 100644
--- a/stix2/patterns.py
+++ b/stix2/patterns.py
@@ -147,6 +147,9 @@ class ListConstant(_Constant):
 
 
 def make_constant(value):
+    if isinstance(value, _Constant):
+        return value
+
     try:
         return parse_into_datetime(value)
     except ValueError:


Test patch:
diff --git a/stix2/test/test_pattern_expressions.py b/stix2/test/test_pattern_expressions.py
index 74a7d0f..14e3774 100644
--- a/stix2/test/test_pattern_expressions.py
+++ b/stix2/test/test_pattern_expressions.py
@@ -372,3 +372,9 @@ def test_invalid_startstop_qualifier():
         stix2.StartStopQualifier(datetime.date(2016, 6, 1),
                                  'foo')
     assert 'is not a valid argument for a Start/Stop Qualifier' in str(excinfo)
+
+
+def test_make_constant_already_a_constant():
+    str_const = stix2.StringConstant('Foo')
+    result = stix2.patterns.make_constant(str_const)
+    assert result is str_const