Skip to content

Commit

Permalink
Fix _collect_addons() and related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Oct 30, 2023
1 parent fef0e65 commit f4fea4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions tests/test_rubeus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from website.util import rubeus
from website.util.rubeus import sort_by_name


class TestRubeus(OsfTestCase):

def setUp(self):
Expand Down Expand Up @@ -316,8 +317,9 @@ def setUp(self):
self.serializer = rubeus.NodeFileCollector(node=self.project, auth=self.auth)

def test_collect_addons(self):
ret = self.serializer._collect_addons(self.project)
assert_equal(ret, [serialized])
return_value, active_addons = self.serializer._collect_addons(self.project)
assert_equal(return_value, [serialized])
assert_equal(len(active_addons), 1)

def test_sort_by_name(self):
files = [
Expand Down
12 changes: 6 additions & 6 deletions website/util/rubeus.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def _serialize_node(self, node, parent=None, grid_root=None, children=None,

def _get_nodes(self, node, grid_root=None):
data = []
active_addons = []
if node.can_view(auth=self.auth):
serialized_addons, active_addons = self._collect_addons(node)
serialized_children = [
Expand All @@ -251,26 +252,25 @@ def _get_nodes(self, node, grid_root=None):
return self._serialize_node(node, children=data, active_addons=active_addons)

def _collect_addons(self, node):
rv = []
return_value = []
active_addons = []
for addon in node.get_addons():
if addon.has_auth:
active_addons.append(addon.config.short_name)

if addon.config.has_hgrid_files:
# WARNING: get_hgrid_data can return None if the addon is added but has no credentials.
try:
temp = addon.config.get_hgrid_data(addon, self.auth, **self.extra)
except Exception as e:
logger.warn(
logger.warning(
getattr(
e,
'data',
'Unexpected error when fetching file contents for {0}.'.format(addon.config.full_name)
)
)
sentry.log_exception()
rv.append({
return_value.append({
KIND: FOLDER,
'unavailable': True,
'iconUrl': addon.config.icon_url,
Expand All @@ -280,8 +280,8 @@ def _collect_addons(self, node):
'name': '{} is currently unavailable'.format(addon.config.full_name),
})
continue
rv.extend(sort_by_name(temp) or [])
return rv, active_addons
return_value.extend(sort_by_name(temp) or [])
return return_value, active_addons


# TODO: these might belong in addons module
Expand Down

0 comments on commit f4fea4b

Please sign in to comment.