Skip to content

Commit

Permalink
Fix code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Feb 15, 2018
1 parent f08ab03 commit 915ad85
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 137 deletions.
2 changes: 1 addition & 1 deletion src/collective/cover/behaviors/interfaces.py
Expand Up @@ -23,7 +23,7 @@ class IRefresh(model.Schema):

ttl = schema.Int(
title=_(u'Time to live'),
description=_(u'Number of seconds after which to reload the current page.',),
description=_(u'Number of seconds after which to reload the current page.'),
default=300,
)

Expand Down
9 changes: 3 additions & 6 deletions src/collective/cover/browser/contentchooser.py
Expand Up @@ -52,10 +52,7 @@ def setup(self):
strategy = SitemapNavtreeStrategy(self.context)

uuids = None
result = self.search(
self.query, uuids=uuids,
page=page
)
result = self.search(self.query, uuids=uuids, page=page)
self.has_next = result.next is not None
self.nextpage = result.pagenumber + 1
children = [strategy.decoratorFactory({'item': node}) for node in result]
Expand Down Expand Up @@ -206,9 +203,9 @@ def jsonByType(self, rooted, document_base_url, searchtext, page='1'):
'title': brain.Title == '' and brain.id or brain.Title,
'icon': self.getIcon(brain).url or '',
'is_folderish': brain.is_folderish,
'description': brain.Description or ''
'description': brain.Description or '',
})
# add catalog_ressults
# add catalog_results
results['items'] = catalog_results
# return results in JSON format
return json.dumps(results)
2 changes: 1 addition & 1 deletion src/collective/cover/browser/layout.py
Expand Up @@ -270,7 +270,7 @@ def get_tile_metadata(self, tile_name):
'icon': tile_type.icon,
'description': tile_type.description,
'title': title,
'is_configurable': tile.is_configurable and 1 or 0
'is_configurable': tile.is_configurable and 1 or 0,
}

return tile_metadata
Expand Down
2 changes: 1 addition & 1 deletion src/collective/cover/config.py
Expand Up @@ -28,7 +28,7 @@
'File',
'Image',
'Link',
'News Item'
'News Item',
]

IS_PLONE_5 = api.env.plone_version().startswith('5')
Expand Down
12 changes: 4 additions & 8 deletions src/collective/cover/grids.py
Expand Up @@ -21,8 +21,7 @@ def transform(self, layout):
element['class'] = self.row_class
if 'css-class' in element:
element['class'] += ' {0}'.format(
element['css-class']
)
element['css-class'])
if 'children' in element:
self.transform(self.columns_formatter(element['children']))
if element['type'] == 'group' and 'children' in element:
Expand Down Expand Up @@ -50,8 +49,7 @@ def columns_formatter(self, columns):
column['class'] = self.column_class + ' ' + (prefix + str(width))
if 'css-class' in column:
column['class'] += ' {0}'.format(
column['css-class']
)
column['css-class'])

return columns

Expand All @@ -71,8 +69,7 @@ def columns_formatter(self, columns):
column['class'] = self.column_class + ' ' + (prefix + str(width))
if 'css-class' in column:
column['class'] += ' {0}'.format(
column['css-class']
)
column['css-class'])

return columns

Expand All @@ -95,7 +92,6 @@ def columns_formatter(self, columns):
column['class'] = self.column_class + ' ' + (w + str(width)) + ' ' + (p + str(offset))
if 'css-class' in column:
column['class'] += ' {0}'.format(
column['css-class']
)
column['css-class'])
offset = offset + width
return columns
5 changes: 1 addition & 4 deletions src/collective/cover/tests/test_banner_tile.py
Expand Up @@ -53,10 +53,7 @@ def test_populate_tile_with_image_object_string(self):
obj.setTitle(title)
obj.reindexObject()
self.tile.populate_with_object(obj)
self.assertEqual(
unicode(title, 'utf-8'),
self.tile.data.get('title')
)
self.assertEqual(unicode(title, 'utf-8'), self.tile.data.get('title'))
self.assertTrue(self.tile.has_image)
self.assertIsNotNone(self.tile.getRemoteUrl())

Expand Down
9 changes: 2 additions & 7 deletions src/collective/cover/tests/test_basic_tile.py
Expand Up @@ -124,14 +124,9 @@ def test_populate_with_object_string(self):
obj.setDescription(description)
obj.reindexObject()
self.tile.populate_with_object(obj)
self.assertEqual(unicode(title, 'utf-8'), self.tile.data.get('title'))
self.assertEqual(
unicode(title, 'utf-8'),
self.tile.data.get('title')
)
self.assertEqual(
unicode(description, 'utf-8'),
self.tile.data.get('description')
)
unicode(description, 'utf-8'), self.tile.data.get('description'))

def test_render_empty(self):
msg = 'Please drag&drop some content here to populate the tile.'
Expand Down
18 changes: 3 additions & 15 deletions src/collective/cover/tests/test_carousel_tile.py
Expand Up @@ -129,13 +129,9 @@ def test_custom_title(self):
# now we 2 elements
obj1 = self.portal['my-document']
obj2 = self.portal['my-image']

self.tile.populate_with_uuids([
obj1.UID(), obj2.UID()
])
self.tile.populate_with_uuids([obj1.UID(), obj2.UID()])

# For obj2 we will assign a custom_title

uuids = ITileDataManager(self.tile).get().get('uuids', None)
uuids[obj2.UID()]['custom_title'] = u'New Title'

Expand All @@ -157,13 +153,9 @@ def test_custom_description(self):
# now we 2 elements
obj1 = self.portal['my-document']
obj2 = self.portal['my-image']

self.tile.populate_with_uuids([
obj1.UID(), obj2.UID()
])
self.tile.populate_with_uuids([obj1.UID(), obj2.UID()])

# For obj2 we will assign a custom_description

uuids = ITileDataManager(self.tile).get().get('uuids', None)
uuids[obj2.UID()]['custom_description'] = u'New Description'

Expand All @@ -186,13 +178,9 @@ def test_custom_url(self):
obj1 = self.portal['my-document']
obj2 = self.portal['my-image']
obj3 = self.portal['my-image1']

self.tile.populate_with_uuids([
obj1.UID(), obj2.UID(), obj3.UID()
])
self.tile.populate_with_uuids([obj1.UID(), obj2.UID(), obj3.UID()])

# For obj2 we will assign a custom_url

uuids = ITileDataManager(self.tile).get().get('uuids', None)
uuids[obj2.UID()]['custom_url'] = u'http://www.custom_url.com'

Expand Down
5 changes: 1 addition & 4 deletions src/collective/cover/tests/test_collection_tile.py
Expand Up @@ -221,10 +221,7 @@ def test_date_on_items(self):
fmt_date = self.portal.toLocalizedTime(date, True)

rendered = self.tile()
self.assertTrue(
fmt_date in rendered,
'Formatted date should be in rendered tile'
)
self.assertIn(fmt_date, rendered)

def test_localized_time_is_rendered(self):
obj = self._create_events_collection()
Expand Down
12 changes: 3 additions & 9 deletions src/collective/cover/tests/test_contentbody_tile.py
Expand Up @@ -75,13 +75,10 @@ def test_render_deleted_object(self):
self.tile.populate_with_object(obj)
# Delete original object
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.portal.manage_delObjects(['my-news-item', ])
self.portal.manage_delObjects(['my-news-item'])

self.tile.is_compose_mode = Mock(return_value=True)
self.assertIn(
'This item does not have any body text.',
self.tile()
)
self.assertIn('This item does not have any body text.', self.tile())

def test_render_restricted_object(self):
text = '<h2>Peace of mind</h2>'
Expand All @@ -92,10 +89,7 @@ def test_render_restricted_object(self):
obj.manage_permission('View', [], 0)

self.tile.is_compose_mode = Mock(return_value=True)
self.assertIn(
'This item does not have any body text.',
self.tile()
)
self.assertIn('This item does not have any body text.', self.tile())

def test_item_url(self):
obj = self.portal['my-news-item']
Expand Down
2 changes: 1 addition & 1 deletion src/collective/cover/tests/test_controlpanel.py
Expand Up @@ -86,7 +86,7 @@ def test_styles_record_in_registry(self):
set(['-Default-|tile-default',
'Border|tile-edge',
'Dark Background|tile-dark',
'Shadow|tile-shadow'])
'Shadow|tile-shadow']),
)

def test_grid_system_record_in_registry(self):
Expand Down
2 changes: 1 addition & 1 deletion src/collective/cover/tests/test_cover.py
Expand Up @@ -160,5 +160,5 @@ def test_searchabletext_indexer(self):
# indexer should contain id, title, description and text in tiles
self.assertEqual(
searchableText(self.cover)(),
u'c1 Lorem ipsum Neque porro 01234 56789'
u'c1 Lorem ipsum Neque porro 01234 56789',
)
9 changes: 2 additions & 7 deletions src/collective/cover/tests/test_file_tile.py
Expand Up @@ -62,14 +62,9 @@ def test_populate_tile_with_object_string(self):
obj.setDescription(description)
obj.reindexObject()
self.tile.populate_with_object(obj)
self.assertEqual(unicode(title, 'utf-8'), self.tile.data.get('title'))
self.assertEqual(
unicode(title, 'utf-8'),
self.tile.data.get('title')
)
self.assertEqual(
unicode(description, 'utf-8'),
self.tile.data.get('description')
)
unicode(description, 'utf-8'), self.tile.data.get('description'))
self.assertEqual(self.tile.data.get('uuid'), IUUID(obj))

def test_populate_tile_with_invalid_object(self):
Expand Down
2 changes: 1 addition & 1 deletion src/collective/cover/tests/test_richtext_tile.py
Expand Up @@ -56,7 +56,7 @@ def test_seachable_text(self):
value = RichTextValue(
raw=text,
mimeType='text/x-html-safe',
outputMimeType='text/x-html-safe'
outputMimeType='text/x-html-safe',
)
self.tile.data['text'] = value
self.assertEqual(searchable.SearchableText(), 'My document text...')
66 changes: 22 additions & 44 deletions src/collective/cover/tests/test_textlinessortable_widget.py
Expand Up @@ -24,7 +24,7 @@ def test_sort_results(self):
obj1.UID(): {u'order': u'0'},
obj2.UID(): {u'order': u'2'},
obj3.UID(): {u'order': u'1'},
}
},
}

expected = [
Expand Down Expand Up @@ -59,21 +59,15 @@ def test_get_custom_title(self):
obj1.UID(): {u'order': u'0', u'custom_title': u'custom_title'},
obj2.UID(): {u'order': u'1', u'custom_title': u''},
obj3.UID(): {u'order': u'2'},
}
},
}

self.assertEqual(
widget.get_custom_title(obj1.UID()),
u'custom_title'
)
widget.get_custom_title(obj1.UID()), u'custom_title')
self.assertEqual(
widget.get_custom_title(obj2.UID()),
u'Test image #1'
)
widget.get_custom_title(obj2.UID()), u'Test image #1')
self.assertEqual(
widget.get_custom_title(obj3.UID()),
u'Test image #2'
)
widget.get_custom_title(obj3.UID()), u'Test image #2')

def test_get_custom_description(self):
widget = TextLinesSortableWidget(self.request)
Expand All @@ -86,20 +80,20 @@ def test_get_custom_description(self):
obj1.UID(): {u'order': u'0', u'custom_description': u'custom_description'},
obj2.UID(): {u'order': u'1', u'custom_description': u''},
obj3.UID(): {u'order': u'2'},
}
},
}

self.assertEqual(
widget.get_custom_description(obj1.UID()),
u'custom_description'
u'custom_description',
)
self.assertEqual(
widget.get_custom_description(obj2.UID()),
u'This image #1 was created for testing purposes'
u'This image #1 was created for testing purposes',
)
self.assertEqual(
widget.get_custom_description(obj3.UID()),
u'This image #2 was created for testing purposes'
u'This image #2 was created for testing purposes',
)

def test_get_custom_url(self):
Expand All @@ -113,7 +107,7 @@ def test_get_custom_url(self):
obj1.UID(): {u'order': u'0', u'custom_url': u'custom_url'},
obj2.UID(): {u'order': u'1', u'custom_url': u''},
obj3.UID(): {u'order': u'2'},
}
},
}

self.assertEqual(widget.get_custom_url(obj1.UID()), u'custom_url')
Expand All @@ -127,7 +121,7 @@ def test_extract(self):
uuids = [
obj1.UID(),
obj3.UID(),
obj2.UID()
obj2.UID(),
]

name = 'uuid.field'
Expand All @@ -141,10 +135,10 @@ def test_extract(self):
expected = {
obj1.UID(): {
u'custom_url': u'custom_url',
u'order': u'0'
u'order': u'0',
},
obj2.UID(): {u'order': u'2'},
obj3.UID(): {u'order': u'1'}
obj3.UID(): {u'order': u'1'},
}

extracted_value = widget.extract()
Expand Down Expand Up @@ -178,7 +172,7 @@ def test_utf8_custom_data(self):
widget.context = {'uuids': {
obj1.UID(): {u'order': u'0', u'custom_description': u'áéíóú'},
obj2.UID(): {u'order': u'1', u'custom_description': u''},
}
},
}

expected = {
Expand All @@ -191,34 +185,18 @@ def test_utf8_custom_data(self):
self.assertDictEqual(extracted_value, expected)

self.assertEqual(
widget.get_custom_title(obj1.UID()),
u'Test image'
)
widget.get_custom_title(obj1.UID()), u'Test image')
self.assertEqual(
widget.get_custom_description(obj1.UID()),
u'áéíóú'
)
widget.get_custom_description(obj1.UID()), u'áéíóú')
self.assertIsInstance(
widget.get_custom_title(obj1.UID()),
unicode
)
widget.get_custom_title(obj1.UID()), unicode)
self.assertIsInstance(
widget.get_custom_description(obj1.UID()),
unicode
)
widget.get_custom_description(obj1.UID()), unicode)
self.assertEqual(
widget.get_custom_title(obj2.UID()),
u'áéíóú'
)
widget.get_custom_title(obj2.UID()), u'áéíóú')
self.assertEqual(
widget.get_custom_description(obj2.UID()),
u'áéíóú'
)
widget.get_custom_description(obj2.UID()), u'áéíóú')
self.assertIsInstance(
widget.get_custom_title(obj2.UID()),
unicode
)
widget.get_custom_title(obj2.UID()), unicode)
self.assertIsInstance(
widget.get_custom_description(obj2.UID()),
unicode
)
widget.get_custom_description(obj2.UID()), unicode)
5 changes: 2 additions & 3 deletions src/collective/cover/tests/test_tiles.py
Expand Up @@ -55,6 +55,5 @@ def test_is_editable(self):
self.assertTrue(self.view.tile_is_editable('collective.cover.basic'))

def test_is_configurable(self):
self.assertTrue(self.view.tile_is_configurable(
'collective.cover.basic')
)
self.assertTrue(
self.view.tile_is_configurable('collective.cover.basic'))

0 comments on commit 915ad85

Please sign in to comment.