Merge pull request #18471 from edx/aj/fix-correct-map-problem

Do not update correct_map if state is invalid (EDUCATOR-3016)
This commit is contained in:
Awais Jibran
2018-06-28 13:42:31 +05:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -91,8 +91,11 @@ class CorrectMap(object):
# empty current dict
self.__init__()
if not correct_map:
return
# create new dict entries
if correct_map and not isinstance(correct_map.values()[0], dict):
if not isinstance(correct_map.values()[0], dict):
# special migration
for k in correct_map:
self.set(k, correctness=correct_map[k])

View File

@@ -215,3 +215,13 @@ class CorrectMapTest(unittest.TestCase):
for invalid in invalid_list:
with self.assertRaises(Exception):
self.cmap.update(invalid)
def test_set_none_state(self):
"""
Test that if an invalid state is set to correct map, the state does not
update at all.
"""
invalid_list = [None, "", False, 0]
for invalid in invalid_list:
self.cmap.set_dict(invalid)
self.assertEqual(self.cmap.get_dict(), {})