-
Notifications
You must be signed in to change notification settings - Fork 1.9k
refactor: Rewrite empty_string & add more test cases #6222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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')) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tabs as well
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| self.assertFalse(string_empty(None)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be true IMO
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of times None can be passed for a string. We need to treat it as en empty string. For example, non-existent field. If we are using string_empty for validation, then having None as non empty will pass it as a correct value However, this needs to be checked where string_empty is used so that we can ensure the correct behaviour
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Travis was failing when I did that. What could be done? |
||
| 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() | ||
Uh oh!
There was an error while loading. Please reload this page.