Code review feedback.

This commit is contained in:
cahrens
2013-11-14 16:27:50 -05:00
parent 53a4016619
commit 569c86de74
7 changed files with 34 additions and 34 deletions

View File

@@ -2,14 +2,11 @@
Utilities for string manipulation.
"""
import ast
def str_to_bool(str):
"""
Converts "true" (case-insensitive) to the boolean True.
Everything else will return False.
Everything else will return False (including None).
An error will be thrown for non-string input (besides None).
"""
try:
return ast.literal_eval(str.title())
except:
return False
return False if str is None else str.lower() == "true"

View File

@@ -21,6 +21,13 @@ class StringUtilsTest(TestCase):
self.assertFalse(str_to_bool(''))
self.assertFalse(str_to_bool(None))
self.assertFalse(str_to_bool('anything'))
self.assertFalse(str_to_bool([]))
self.assertFalse(str_to_bool({}))
self.assertFalse(str_to_bool(1))
def test_str_to_bool_errors(self):
def test_raises_error(val):
with self.assertRaises(AttributeError):
self.assertFalse(str_to_bool(val))
test_raises_error({})
test_raises_error([])
test_raises_error(1)
test_raises_error(True)

View File

@@ -187,11 +187,7 @@ class DraftModuleStore(MongoModuleStore):
# We expect the children IDs to always be the non-draft version. With view refactoring
# for split, we are now passing the draft version in some cases.
children_ids = [
Location(child).replace(revision=None).url()
for child
in children
]
children_ids = [as_published(child).url() for child in children]
draft_loc = as_draft(location)
draft_item = self.get_item(location)