Fix failing tests.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-08-22 02:56:16 -04:00
parent 78bfc6501c
commit a4552cf415
3 changed files with 18 additions and 14 deletions

View File

@@ -159,10 +159,15 @@ class Menu(object):
try:
request = context.request
except AttributeError:
# There is no request variable, most probable a 500 in a test view
# Don't return any resolved links then.
logger.warning('No request variable, aborting menu resolution')
return ()
# Simple request extraction failed. Might not be a view context.
# Try alternate method.
try:
request = Variable('request').resolve(context)
except VariableDoesNotExist:
# There is no request variable, most probable a 500 in a test
# view. Don't return any resolved links then.
logger.warning('No request variable, aborting menu resolution')
return ()
current_path = request.META['PATH_INFO']
@@ -296,13 +301,6 @@ class Link(object):
self.url = url
def resolve(self, context, resolved_object=None):
# Check to see if link has conditional display function and only
# display it if the result of the conditional display function is
# True
if self.condition:
if not self.condition(context):
return None
AccessControlList = apps.get_model(
app_label='acls', model_name='AccessControlList'
)
@@ -380,6 +378,13 @@ class Link(object):
elif self.url:
resolved_link.url = self.url
# Check to see if link has conditional display function and only
# display it if the result of the conditional display function is
# True
if self.condition:
if not self.condition(context):
return None
# This is for links that should be displayed but that are not clickable
if self.conditional_disable:
resolved_link.disabled = self.conditional_disable(context)

View File

@@ -181,7 +181,6 @@ class MenuClassTestCase(GenericViewTestCase):
response = self.get(TEST_VIEW_NAME)
context = Context({'request': response.wsgi_request})
self.assertEqual(
self.menu.resolve(context=context)[0][0].link, self.link
)

View File

@@ -17,7 +17,7 @@ class TagActionTestCase(ActionTestCase):
def test_tag_attach_action(self):
action = AttachTagAction(form_data={'tags': Tag.objects.all()})
action.execute(context={'entry_log': self.entry_log})
action.execute(context={'document': self.document})
self.assertEqual(self.tag.documents.count(), 1)
self.assertEqual(list(self.tag.documents.all()), [self.document])
@@ -26,6 +26,6 @@ class TagActionTestCase(ActionTestCase):
self.tag.attach_to(document=self.document)
action = RemoveTagAction(form_data={'tags': Tag.objects.all()})
action.execute(context={'entry_log': self.entry_log})
action.execute(context={'document': self.document})
self.assertEqual(self.tag.documents.count(), 0)