Skip to content

Commit

Permalink
fix: --
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed May 22, 2024
1 parent 0f5b770 commit 4cf6d9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions xblock/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def open_local_resource(cls, uri):
if "/." in uri:
raise DisallowedFileError("Only safe file names are allowed: %r" % uri)

return cls.__open_resource(uri)
return cls.open_resource(uri)

@classmethod
def __open_resource(cls, uri):
def open_resource(cls, uri):
return importlib.resources.files(inspect.getmodule(cls).__package__).joinpath(
os.path.join(cls.resources_dir, uri)
).open('rb')
Expand Down
10 changes: 5 additions & 5 deletions xblock/test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ def stub_open_resource(self, uri):
)
def test_open_good_local_resource(self, uri):
loadable = self.LoadableXBlock(None, scope_ids=Mock())
with patch('xblock.core.Blocklike.__open_resource', self.stub_open_resource):
with patch('xblock.core.Blocklike.open_resource', self.stub_open_resource):
assert loadable.open_local_resource(uri) == "!" + uri + "!"
assert loadable.open_local_resource(uri.encode('utf-8')) == "!" + uri + "!"

Expand All @@ -988,7 +988,7 @@ def test_open_good_local_resource(self, uri):
)
def test_open_good_local_resource_binary(self, uri):
loadable = self.LoadableXBlock(None, scope_ids=Mock())
with patch('xblock.core.Blocklike.__open_resource', self.stub_open_resource):
with patch('xblock.core.Blocklike.open_resource', self.stub_open_resource):
assert loadable.open_local_resource(uri) == "!" + uri.decode('utf-8') + "!"

@ddt.data(
Expand All @@ -1002,7 +1002,7 @@ def test_open_good_local_resource_binary(self, uri):
)
def test_open_bad_local_resource(self, uri):
loadable = self.LoadableXBlock(None, scope_ids=Mock())
with patch('xblock.core.Blocklike.__open_resource', self.stub_open_resource):
with patch('xblock.core.Blocklike.open_resource', self.stub_open_resource):
msg_pattern = ".*: %s" % re.escape(repr(uri))
with pytest.raises(DisallowedFileError, match=msg_pattern):
loadable.open_local_resource(uri)
Expand All @@ -1018,7 +1018,7 @@ def test_open_bad_local_resource(self, uri):
)
def test_open_bad_local_resource_binary(self, uri):
loadable = self.LoadableXBlock(None, scope_ids=Mock())
with patch('xblock.core.Blocklike.__open_resource', self.stub_open_resource):
with patch('xblock.core.Blocklike.open_resource', self.stub_open_resource):
msg = ".*: %s" % re.escape(repr(uri.decode('utf-8')))
with pytest.raises(DisallowedFileError, match=msg):
loadable.open_local_resource(uri)
Expand All @@ -1041,7 +1041,7 @@ def test_open_bad_local_resource_binary(self, uri):
def test_open_local_resource_with_no_resources_dir(self, uri):
unloadable = self.UnloadableXBlock(None, scope_ids=Mock())

with patch('xblock.core.Blocklike.__open_resource', self.stub_open_resource):
with patch('xblock.core.Blocklike.open_resource', self.stub_open_resource):
msg = "not configured to serve local resources"
with pytest.raises(DisallowedFileError, match=msg):
unloadable.open_local_resource(uri)
Expand Down

0 comments on commit 4cf6d9e

Please sign in to comment.