From d81b2b482bbe3af2bac4e4a19af56acab746bc74 Mon Sep 17 00:00:00 2001 From: gordon chung Date: Mon, 22 Jun 2015 17:35:19 -0400 Subject: ensure id is not empty when validating id, we should validate it's not just a string but that it's also not empty. Change-Id: I0d55803df5f2f8e6b35431a816e1390bcb3fe424 Closes-Bug: #1467670 --- pycadf/identifier.py | 2 ++ pycadf/tests/test_cadf_spec.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/pycadf/identifier.py b/pycadf/identifier.py index 8c74fb6..de9e8eb 100644 --- a/pycadf/identifier.py +++ b/pycadf/identifier.py @@ -49,4 +49,6 @@ def is_valid(value): """ if not isinstance(value, six.string_types): raise TypeError + elif not value: + return False return True diff --git a/pycadf/tests/test_cadf_spec.py b/pycadf/tests/test_cadf_spec.py index 9ba9676..afa1da1 100644 --- a/pycadf/tests/test_cadf_spec.py +++ b/pycadf/tests/test_cadf_spec.py @@ -34,6 +34,11 @@ from pycadf import timestamp class TestCADFSpec(base.TestCase): + + def test_identifier_empty(self): + self.assertFalse(identifier.is_valid('')) + self.assertTrue(identifier.is_valid(identifier.generate_uuid())) + def test_endpoint(self): endp = endpoint.Endpoint(url='http://192.168.0.1', name='endpoint name', -- cgit v1.2.1