Record valid scopes when raising InvalidScopeError
This commit is contained in:
@@ -119,7 +119,10 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
|
||||
elif key.scope == Scope.content:
|
||||
return self._data[key.field_name]
|
||||
else:
|
||||
raise InvalidScopeError(key)
|
||||
raise InvalidScopeError(
|
||||
key,
|
||||
(Scope.children, Scope.parent, Scope.settings, Scope.content),
|
||||
)
|
||||
|
||||
def set(self, key, value):
|
||||
if key.scope == Scope.children:
|
||||
@@ -129,7 +132,10 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
|
||||
elif key.scope == Scope.content:
|
||||
self._data[key.field_name] = value
|
||||
else:
|
||||
raise InvalidScopeError(key)
|
||||
raise InvalidScopeError(
|
||||
key,
|
||||
(Scope.children, Scope.settings, Scope.content),
|
||||
)
|
||||
|
||||
def delete(self, key):
|
||||
if key.scope == Scope.children:
|
||||
@@ -141,7 +147,10 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
|
||||
if key.field_name in self._data:
|
||||
del self._data[key.field_name]
|
||||
else:
|
||||
raise InvalidScopeError(key)
|
||||
raise InvalidScopeError(
|
||||
key,
|
||||
(Scope.children, Scope.settings, Scope.content),
|
||||
)
|
||||
|
||||
def has(self, key):
|
||||
if key.scope in (Scope.children, Scope.parent):
|
||||
|
||||
@@ -18,6 +18,8 @@ class SplitMongoKVS(InheritanceKeyValueStore):
|
||||
known to the MongoModuleStore (data, children, and metadata)
|
||||
"""
|
||||
|
||||
VALID_SCOPES = (Scope.parent, Scope.children, Scope.settings, Scope.content)
|
||||
|
||||
@contract(parent="BlockUsageLocator | None")
|
||||
def __init__(self, definition, initial_values, default_values, parent, field_decorator=None):
|
||||
"""
|
||||
@@ -59,7 +61,7 @@ class SplitMongoKVS(InheritanceKeyValueStore):
|
||||
else:
|
||||
raise KeyError()
|
||||
else:
|
||||
raise InvalidScopeError(key)
|
||||
raise InvalidScopeError(key, self.VALID_SCOPES)
|
||||
|
||||
if key.field_name in self._fields:
|
||||
field_value = self._fields[key.field_name]
|
||||
@@ -71,8 +73,8 @@ class SplitMongoKVS(InheritanceKeyValueStore):
|
||||
|
||||
def set(self, key, value):
|
||||
# handle any special cases
|
||||
if key.scope not in [Scope.children, Scope.settings, Scope.content]:
|
||||
raise InvalidScopeError(key)
|
||||
if key.scope not in self.VALID_SCOPES:
|
||||
raise InvalidScopeError(key, self.VALID_SCOPES)
|
||||
if key.scope == Scope.content:
|
||||
self._load_definition()
|
||||
|
||||
@@ -90,8 +92,8 @@ class SplitMongoKVS(InheritanceKeyValueStore):
|
||||
|
||||
def delete(self, key):
|
||||
# handle any special cases
|
||||
if key.scope not in [Scope.children, Scope.settings, Scope.content]:
|
||||
raise InvalidScopeError(key)
|
||||
if key.scope not in self.VALID_SCOPES:
|
||||
raise InvalidScopeError(key, self.VALID_SCOPES)
|
||||
if key.scope == Scope.content:
|
||||
self._load_definition()
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ class DjangoKeyValueStore(KeyValueStore):
|
||||
def _raise_unless_scope_is_allowed(self, key):
|
||||
"""Raise an InvalidScopeError if key.scope is not in self._allowed_scopes."""
|
||||
if key.scope not in self._allowed_scopes:
|
||||
raise InvalidScopeError(key)
|
||||
raise InvalidScopeError(key, self._allowed_scopes)
|
||||
|
||||
|
||||
new_contract("DjangoKeyValueStore", DjangoKeyValueStore)
|
||||
|
||||
@@ -29,7 +29,7 @@ git+https://github.com/pmitros/pyfs.git@96e1922348bfe6d99201b9512a9ed946c87b7e0b
|
||||
git+https://github.com/hmarr/django-debug-toolbar-mongo.git@b0686a76f1ce3532088c4aee6e76b9abe61cc808
|
||||
|
||||
# Our libraries:
|
||||
-e git+https://github.com/edx/XBlock.git@1934a2978cdd3e2414486c74b76e3040ff1fb138#egg=XBlock
|
||||
-e git+https://github.com/cpennington/XBlock.git@e9c4d441d1eaf7c9f176b873fe23e24c1152dba6#egg=XBlock
|
||||
-e git+https://github.com/edx/codejail.git@6b17c33a89bef0ac510926b1d7fea2748b73aadd#egg=codejail
|
||||
-e git+https://github.com/edx/js-test-tool.git@v0.1.6#egg=js_test_tool
|
||||
-e git+https://github.com/edx/event-tracking.git@0.2.0#egg=event-tracking
|
||||
|
||||
Reference in New Issue
Block a user