From f861f497be9b3537ad8a3ba2eac1fb3b8188b153 Mon Sep 17 00:00:00 2001 From: mrsaicharan1 Date: Sun, 21 Jul 2019 20:05:01 +0530 Subject: [PATCH] refactor empty_string for python3 Shifted test to unit dir Added tabs --- app/api/helpers/utilities.py | 7 +------ .../integration/api/helpers/test_utilities.py | 12 ------------ tests/all/unit/api/helpers/test_utilities.py | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/api/helpers/utilities.py b/app/api/helpers/utilities.py index 6d4ad07b41..24e8e44417 100644 --- a/app/api/helpers/utilities.py +++ b/app/api/helpers/utilities.py @@ -26,12 +26,7 @@ def require_relationship(resource_list, data): def string_empty(value): - is_not_str_type = type(value) is not str - if sys.version_info[0] < 3: - is_not_str_type = is_not_str_type and type(value) is not unicode - if type(value) is not value and is_not_str_type: - return False - return not (value and value.strip() and value != u'' and value != u' ') + return isinstance(value, str) and not value.strip() def strip_tags(html): diff --git a/tests/all/integration/api/helpers/test_utilities.py b/tests/all/integration/api/helpers/test_utilities.py index 073ea44f85..b71fe0cb7f 100644 --- a/tests/all/integration/api/helpers/test_utilities.py +++ b/tests/all/integration/api/helpers/test_utilities.py @@ -29,18 +29,6 @@ def test_require_relationship(self): data = ['event'] require_relationship(['sponsor', 'event'], data) - def test_string_empty(self): - """Method to test whether an empty string is correctly identified.""" - - with app.test_request_context(): - self.assertTrue(string_empty('')) - self.assertTrue(string_empty(' ')) - self.assertFalse(string_empty('some value')) - self.assertFalse(string_empty(' some value ')) - self.assertFalse(string_empty(str)) - self.assertFalse(string_empty(int)) - self.assertFalse(string_empty(None)) - def test_monthdelta(self): """Method to test difference in months result""" diff --git a/tests/all/unit/api/helpers/test_utilities.py b/tests/all/unit/api/helpers/test_utilities.py index 946294b281..3b5d95cfc5 100644 --- a/tests/all/unit/api/helpers/test_utilities.py +++ b/tests/all/unit/api/helpers/test_utilities.py @@ -1,6 +1,6 @@ import unittest from app.api.helpers.utilities import get_filename_from_cd - +from app.api.helpers.utilities import string_empty class TestUtilitiesHelperValidation(unittest.TestCase): def test_get_filename_from_cd(self): @@ -17,6 +17,20 @@ def test_get_filename_from_cd(self): self.assertEqual(expected_response_first, response_first) self.assertEqual(expected_response_none, response_none) + def test_string_empty(self): + """Method to test whether an empty string is correctly identified.""" + + self.assertTrue(string_empty('')) + self.assertTrue(string_empty(' ')) + self.assertTrue(string_empty('\t')) + self.assertTrue(string_empty('\n')) + self.assertFalse(string_empty(None)) + self.assertFalse(string_empty('some value')) + self.assertFalse(string_empty(' some value ')) + self.assertFalse(string_empty(0)) + self.assertFalse(string_empty([])) + self.assertFalse(string_empty(False)) + if __name__ == '__main__': unittest.main()