Commit 63a49d6d by Renzo Lucioni

Merge pull request #9398 from edx/release

Merge release into master
parents 987ca4b4 f17df2d0
...@@ -161,7 +161,11 @@ class UserPartition(namedtuple("UserPartition", "id name description groups sche ...@@ -161,7 +161,11 @@ class UserPartition(namedtuple("UserPartition", "id name description groups sche
if value["version"] == 1: if value["version"] == 1:
# If no scheme was provided, set it to the default ('random') # If no scheme was provided, set it to the default ('random')
scheme_id = UserPartition.VERSION_1_SCHEME scheme_id = UserPartition.VERSION_1_SCHEME
elif value["version"] == UserPartition.VERSION:
# Version changes should be backwards compatible in case the code
# gets rolled back. If we see a version number greater than the current
# version, we should try to read it rather than raising an exception.
elif value["version"] >= UserPartition.VERSION:
if "scheme" not in value: if "scheme" not in value:
raise TypeError("UserPartition dict {0} missing value key 'scheme'".format(value)) raise TypeError("UserPartition dict {0} missing value key 'scheme'".format(value))
scheme_id = value["scheme"] scheme_id = value["scheme"]
......
...@@ -60,7 +60,7 @@ class TestGroup(TestCase): ...@@ -60,7 +60,7 @@ class TestGroup(TestCase):
jsonified = { jsonified = {
"id": test_id, "id": test_id,
"name": name, "name": name,
"version": 9001 "version": -1,
} }
with self.assertRaisesRegexp(TypeError, "has unexpected version"): with self.assertRaisesRegexp(TypeError, "has unexpected version"):
Group.from_json(jsonified) Group.from_json(jsonified)
...@@ -241,14 +241,13 @@ class TestUserPartition(PartitionTestCase): ...@@ -241,14 +241,13 @@ class TestUserPartition(PartitionTestCase):
with self.assertRaisesRegexp(UserPartitionError, "Unrecognized scheme"): with self.assertRaisesRegexp(UserPartitionError, "Unrecognized scheme"):
UserPartition.from_json(jsonified) UserPartition.from_json(jsonified)
# Wrong version (it's over 9000!) # Wrong version
# Wrong version (it's over 9000!)
jsonified = { jsonified = {
'id': self.TEST_ID, 'id': self.TEST_ID,
"name": self.TEST_NAME, "name": self.TEST_NAME,
"description": self.TEST_DESCRIPTION, "description": self.TEST_DESCRIPTION,
"groups": [group.to_json() for group in self.TEST_GROUPS], "groups": [group.to_json() for group in self.TEST_GROUPS],
"version": 9001, "version": -1,
"scheme": self.TEST_SCHEME_NAME, "scheme": self.TEST_SCHEME_NAME,
} }
with self.assertRaisesRegexp(TypeError, "has unexpected version"): with self.assertRaisesRegexp(TypeError, "has unexpected version"):
...@@ -284,6 +283,24 @@ class TestUserPartition(PartitionTestCase): ...@@ -284,6 +283,24 @@ class TestUserPartition(PartitionTestCase):
with self.assertRaises(NoSuchUserPartitionGroupError): with self.assertRaises(NoSuchUserPartitionGroupError):
self.user_partition.get_group(3) self.user_partition.get_group(3)
def test_forward_compatibility(self):
# If the user partition version is updated in a release,
# then the release is rolled back, courses might contain
# version numbers greater than the currently deployed
# version number.
newer_version_json = {
"id": self.TEST_ID,
"name": self.TEST_NAME,
"description": self.TEST_DESCRIPTION,
"groups": [group.to_json() for group in self.TEST_GROUPS],
"version": UserPartition.VERSION + 1,
"scheme": "mock",
"additional_new_field": "foo",
}
partition = UserPartition.from_json(newer_version_json)
self.assertEqual(partition.id, self.TEST_ID)
self.assertEqual(partition.name, self.TEST_NAME)
class StaticPartitionService(PartitionService): class StaticPartitionService(PartitionService):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment