Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

pep8/pyflakes

  • Loading branch information...
commit 983e9a3f7c29f68c4b2d0e68f553f8cf71157e5b 1 parent 84460d2
Héctor Velarde hvelarde authored
4 src/collective/twitter/portlets/Extensions/Install.py
... ... @@ -1,5 +1,8 @@
  1 +# -*- coding: utf-8 -*-
  2 +
1 3 from Products.CMFCore.utils import getToolByName
2 4
  5 +
3 6 def install(portal, reinstall=False):
4 7 setup_tool = getToolByName(portal, 'portal_setup')
5 8 qi = getToolByName(portal, 'portal_quickinstaller')
@@ -9,6 +12,7 @@ def install(portal, reinstall=False):
9 12 setup_tool.runAllImportStepsFromProfile('profile-collective.twitter.portlets:default')
10 13 return "Ran all uninstall steps."
11 14
  15 +
12 16 def uninstall(portal, reinstall=False):
13 17 if not reinstall:
14 18 setup_tool = getToolByName(portal, 'portal_setup')
2  src/collective/twitter/portlets/testing.py
@@ -5,6 +5,7 @@
5 5 from plone.app.testing import IntegrationTesting
6 6 from plone.app.testing import FunctionalTesting
7 7
  8 +
8 9 class Fixture(PloneSandboxLayer):
9 10
10 11 defaultBases = (PLONE_FIXTURE,)
@@ -18,7 +19,6 @@ def setUpPloneSite(self, portal):
18 19 # Install into Plone site using portal_setup
19 20 self.applyProfile(portal, 'collective.twitter.portlets:default')
20 21
21   -
22 22 FIXTURE = Fixture()
23 23 INTEGRATION_TESTING = IntegrationTesting(
24 24 bases=(FIXTURE,),
44 src/collective/twitter/portlets/tests/test_profile_portlet.py
... ... @@ -1,8 +1,12 @@
  1 +# -*- coding: utf-8 -*-
  2 +
1 3 import unittest2 as unittest
2 4
3   -from collective.twitter.portlets.testing import INTEGRATION_TESTING
  5 +from zope.component import getMultiAdapter
  6 +from zope.component import getUtility
4 7
5   -from zope.component import getUtility, getMultiAdapter
  8 +from plone.app.testing import TEST_USER_ID
  9 +from plone.app.testing import setRoles
6 10
7 11 from plone.portlets.interfaces import IPortletType
8 12 from plone.portlets.interfaces import IPortletManager
@@ -13,9 +17,8 @@
13 17 from plone.app.portlets.storage import PortletAssignmentMapping
14 18
15 19 from collective.twitter.portlets import twprofile
  20 +from collective.twitter.portlets.testing import INTEGRATION_TESTING
16 21
17   -from plone.app.testing import TEST_USER_ID
18   -from plone.app.testing import setRoles
19 22
20 23 class PortletTest(unittest.TestCase):
21 24
@@ -35,10 +38,10 @@ def test_portlet_type_registered(self):
35 38
36 39 def test_interfaces(self):
37 40 # TODO: Pass any keyword arguments to the Assignment constructor
38   - portlet = twprofile.Assignment(tw_account = u"test",
39   - tw_user = u"Test",
40   - show_avatars = False,
41   - max_results = 20)
  41 + portlet = twprofile.Assignment(tw_account=u"test",
  42 + tw_user=u"Test",
  43 + show_avatars=False,
  44 + max_results=20)
42 45
43 46 self.failUnless(IPortletAssignment.providedBy(portlet))
44 47 self.failUnless(IPortletDataProvider.providedBy(portlet.data))
@@ -71,10 +74,10 @@ def test_invoke_edit_view(self):
71 74 mapping = PortletAssignmentMapping()
72 75 request = self.request
73 76
74   - mapping['foo'] = twprofile.Assignment(tw_account = u"test",
75   - tw_user = u"Test",
76   - show_avatars = False,
77   - max_results = 20)
  77 + mapping['foo'] = twprofile.Assignment(tw_account=u"test",
  78 + tw_user=u"Test",
  79 + show_avatars=False,
  80 + max_results=20)
78 81
79 82 editview = getMultiAdapter((mapping['foo'], request), name='edit')
80 83 self.failUnless(isinstance(editview, twprofile.EditForm))
@@ -87,17 +90,16 @@ def test_obtain_renderer(self):
87 90 context=self.portal)
88 91
89 92 # TODO: Pass any keyword arguments to the Assignment constructor
90   - assignment = twprofile.Assignment(tw_account = u"test",
91   - tw_user = u"Test",
92   - show_avatars = False,
93   - max_results = 20)
  93 + assignment = twprofile.Assignment(tw_account=u"test",
  94 + tw_user=u"Test",
  95 + show_avatars=False,
  96 + max_results=20)
94 97
95 98 renderer = getMultiAdapter(
96 99 (context, request, view, manager, assignment), IPortletRenderer)
97 100 self.failUnless(isinstance(renderer, twprofile.Renderer))
98 101
99 102
100   -
101 103 class RenderTest(unittest.TestCase):
102 104
103 105 layer = INTEGRATION_TESTING
@@ -124,10 +126,10 @@ def renderer(self, context=None, request=None, view=None, manager=None,
124 126 def test_render(self):
125 127 # TODO: Pass any keyword arguments to the Assignment constructor.
126 128 r = self.renderer(context=self.portal,
127   - assignment=twprofile.Assignment(tw_account = u"test",
128   - tw_user = u"Test",
129   - show_avatars = False,
130   - max_results = 20))
  129 + assignment=twprofile.Assignment(tw_account=u"test",
  130 + tw_user=u"Test",
  131 + show_avatars=False,
  132 + max_results=20))
131 133 r = r.__of__(self.portal)
132 134 r.update()
133 135 #output = r.render()
44 src/collective/twitter/portlets/tests/test_search_portlet.py
... ... @@ -1,8 +1,12 @@
  1 +# -*- coding: utf-8 -*-
  2 +
1 3 import unittest2 as unittest
2 4
3   -from collective.twitter.portlets.testing import INTEGRATION_TESTING
  5 +from zope.component import getMultiAdapter
  6 +from zope.component import getUtility
4 7
5   -from zope.component import getUtility, getMultiAdapter
  8 +from plone.app.testing import TEST_USER_ID
  9 +from plone.app.testing import setRoles
6 10
7 11 from plone.portlets.interfaces import IPortletType
8 12 from plone.portlets.interfaces import IPortletManager
@@ -13,9 +17,8 @@
13 17 from plone.app.portlets.storage import PortletAssignmentMapping
14 18
15 19 from collective.twitter.portlets import twsearch
  20 +from collective.twitter.portlets.testing import INTEGRATION_TESTING
16 21
17   -from plone.app.testing import TEST_USER_ID
18   -from plone.app.testing import setRoles
19 22
20 23 class PortletTest(unittest.TestCase):
21 24
@@ -35,10 +38,10 @@ def test_portlet_type_registered(self):
35 38
36 39 def test_interfaces(self):
37 40 # TODO: Pass any keyword arguments to the Assignment constructor
38   - portlet = twsearch.Assignment(tw_account = u"test",
39   - search_string = u"Test",
40   - show_avatars = False,
41   - max_results = 20)
  41 + portlet = twsearch.Assignment(tw_account=u"test",
  42 + search_string=u"Test",
  43 + show_avatars=False,
  44 + max_results=20)
42 45
43 46 self.failUnless(IPortletAssignment.providedBy(portlet))
44 47 self.failUnless(IPortletDataProvider.providedBy(portlet.data))
@@ -71,10 +74,10 @@ def test_invoke_edit_view(self):
71 74 mapping = PortletAssignmentMapping()
72 75 request = self.request
73 76
74   - mapping['foo'] = twsearch.Assignment(tw_account = u"test",
75   - search_string = u"Test",
76   - show_avatars = False,
77   - max_results = 20)
  77 + mapping['foo'] = twsearch.Assignment(tw_account=u"test",
  78 + search_string=u"Test",
  79 + show_avatars=False,
  80 + max_results=20)
78 81
79 82 editview = getMultiAdapter((mapping['foo'], request), name='edit')
80 83 self.failUnless(isinstance(editview, twsearch.EditForm))
@@ -87,17 +90,16 @@ def test_obtain_renderer(self):
87 90 context=self.portal)
88 91
89 92 # TODO: Pass any keyword arguments to the Assignment constructor
90   - assignment = twsearch.Assignment(tw_account = u"test",
91   - search_string = u"Test",
92   - show_avatars = False,
93   - max_results = 20)
  93 + assignment = twsearch.Assignment(tw_account=u"test",
  94 + search_string=u"Test",
  95 + show_avatars=False,
  96 + max_results=20)
94 97
95 98 renderer = getMultiAdapter(
96 99 (context, request, view, manager, assignment), IPortletRenderer)
97 100 self.failUnless(isinstance(renderer, twsearch.Renderer))
98 101
99 102
100   -
101 103 class RenderTest(unittest.TestCase):
102 104
103 105 layer = INTEGRATION_TESTING
@@ -124,10 +126,10 @@ def renderer(self, context=None, request=None, view=None, manager=None,
124 126 def test_render(self):
125 127 # TODO: Pass any keyword arguments to the Assignment constructor.
126 128 r = self.renderer(context=self.portal,
127   - assignment=twsearch.Assignment(tw_account = u"test",
128   - search_string = u"Test",
129   - show_avatars = False,
130   - max_results = 20))
  129 + assignment=twsearch.Assignment(tw_account=u"test",
  130 + search_string=u"Test",
  131 + show_avatars=False,
  132 + max_results=20))
131 133 r = r.__of__(self.portal)
132 134 r.update()
133 135 #output = r.render()
5 src/collective/twitter/portlets/tests/test_setup.py
@@ -8,6 +8,7 @@
8 8 from collective.twitter.portlets.config import PROJECTNAME
9 9 from collective.twitter.portlets.testing import INTEGRATION_TESTING
10 10
  11 +
11 12 class InstallTest(unittest.TestCase):
12 13
13 14 layer = INTEGRATION_TESTING
@@ -17,7 +18,7 @@ def setUp(self):
17 18
18 19 def test_installed(self):
19 20 qi = getattr(self.portal, 'portal_quickinstaller')
20   - self.failUnless(qi.isProductInstalled(PROJECTNAME))
  21 + self.assertTrue(qi.isProductInstalled(PROJECTNAME))
21 22
22 23
23 24 class UninstallTest(unittest.TestCase):
@@ -31,7 +32,7 @@ def setUp(self):
31 32 self.qi.uninstallProducts(products=[PROJECTNAME])
32 33
33 34 def test_uninstalled(self):
34   - self.failIf(self.qi.isProductInstalled(PROJECTNAME))
  35 + self.assertFalse(self.qi.isProductInstalled(PROJECTNAME))
35 36
36 37
37 38 def test_suite():
50 src/collective/twitter/portlets/twprofile.py
... ... @@ -1,3 +1,5 @@
  1 +# -*- coding: utf-8 -*-
  2 +
1 3 from zope.interface import implements
2 4 from zope.interface import alsoProvides
3 5
@@ -31,6 +33,7 @@
31 33
32 34 logger = logging.getLogger(PROJECTNAME)
33 35
  36 +
34 37 def TwitterAccounts(context):
35 38 registry = getUtility(IRegistry)
36 39 accounts = registry['collective.twitter.accounts']
@@ -79,7 +82,7 @@ class ITwitterProfilePortlet(IPortletDataProvider):
79 82 description=_(u"Show people's avatars."),
80 83 required=False)
81 84
82   - max_results = schema.Int(title=_(u'Maximum results'),
  85 + max_results = schema.Int(title=_(u'Maximum results'),
83 86 description=_(u"The maximum results number."),
84 87 required=True,
85 88 default=5)
@@ -129,7 +132,6 @@ def title(self):
129 132 return _(u"Twitter profile Portlet")
130 133
131 134
132   -
133 135 class Renderer(base.Renderer):
134 136 """Portlet renderer.
135 137
@@ -140,7 +142,6 @@ class Renderer(base.Renderer):
140 142
141 143 render = ViewPageTemplateFile('twprofile.pt')
142 144
143   -
144 145 def getHeader(self):
145 146 """
146 147 Returns the header for the portlet
@@ -167,37 +168,36 @@ def getSearchResults(self):
167 168
168 169 if account:
169 170 logger.info("Got a valid account.")
170   - logger.info("consumer_key = %s"%account.get('consumer_key'))
171   - logger.info("consumer_secret = %s"%account.get('consumer_secret'))
172   - logger.info("access_token_key = %s"%account.get('oauth_token'))
173   - logger.info("access_token_secret = %s"%account.get('oauth_token_secret'))
  171 + logger.info("consumer_key = %s" % account.get('consumer_key'))
  172 + logger.info("consumer_secret = %s" % account.get('consumer_secret'))
  173 + logger.info("access_token_key = %s" % account.get('oauth_token'))
  174 + logger.info("access_token_secret = %s" % account.get('oauth_token_secret'))
174 175
175   - tw = twitter.Api(consumer_key = account.get('consumer_key'),
176   - consumer_secret = account.get('consumer_secret'),
177   - access_token_key = account.get('oauth_token'),
178   - access_token_secret = account.get('oauth_token_secret'),)
  176 + tw = twitter.Api(consumer_key=account.get('consumer_key'),
  177 + consumer_secret=account.get('consumer_secret'),
  178 + access_token_key=account.get('oauth_token'),
  179 + access_token_secret=account.get('oauth_token_secret'),)
179 180
180 181 tw_user = self.data.tw_user
181 182 max_results = self.data.max_results
182 183
183 184 try:
184 185 results = tw.GetUserTimeline(tw_user, count=max_results)
185   - logger.info("%s results obtained."%len(results))
  186 + logger.info("%s results obtained." % len(results))
186 187 except Exception, e:
187   - logger.info("Something went wrong: %s."%e)
  188 + logger.info("Something went wrong: %s." % e)
188 189 results = []
189 190 return results
190 191
191   -
192 192 def getTweet(self, result):
193 193 # We need to make URLs, hastags and users clickable.
194   - URL_TEMPLATE ="""
  194 + URL_TEMPLATE = """
195 195 <a href="%s" target="blank_">%s</a>
196 196 """
197   - HASHTAG_TEMPLATE ="""
  197 + HASHTAG_TEMPLATE = """
198 198 <a href="http://twitter.com/#!/search?q=%s" target="blank_">%s</a>
199 199 """
200   - USER_TEMPLATE ="""
  200 + USER_TEMPLATE = """
201 201 <a href="http://twitter.com/#!/%s" target="blank_">%s</a>
202 202 """
203 203
@@ -208,26 +208,26 @@ def getTweet(self, result):
208 208 for index, word in enumerate(split_text):
209 209 if word.startswith('@'):
210 210 # This is a user
211   - split_text[index] = USER_TEMPLATE%(word[1:],word)
  211 + split_text[index] = USER_TEMPLATE % (word[1:], word)
212 212 elif word.startswith('#'):
213 213 # This is a hashtag
214   - split_text[index] = HASHTAG_TEMPLATE%("%23"+word[1:],word)
  214 + split_text[index] = HASHTAG_TEMPLATE % ("%23" + word[1:], word)
215 215 elif word.startswith('http'):
216 216 # This is a hashtag
217   - split_text[index] = URL_TEMPLATE%(word,word)
  217 + split_text[index] = URL_TEMPLATE % (word, word)
218 218
219   - return "<p>%s</p>"%' '.join(split_text)
  219 + return "<p>%s</p>" % ' '.join(split_text)
220 220
221 221 def getTweetUrl(self, result):
222 222 return "https://twitter.com/%s/status/%s" % \
223 223 (result.user.screen_name, result.id)
224   -
  224 +
225 225 def getReplyTweetUrl(self, result):
226 226 return "https://twitter.com/intent/tweet?in_reply_to=%s" % result.id
227   -
  227 +
228 228 def getReTweetUrl(self, result):
229 229 return "https://twitter.com/intent/retweet?tweet_id=%s" % result.id
230   -
  230 +
231 231 def getFavTweetUrl(self, result):
232 232 return "https://twitter.com/intent/favorite?tweet_id=%s" % result.id
233 233
@@ -241,6 +241,7 @@ def getDate(self, result):
241 241
242 242 return date
243 243
  244 +
244 245 class AddForm(base.AddForm):
245 246 """Portlet add form.
246 247
@@ -253,6 +254,7 @@ class AddForm(base.AddForm):
253 254 def create(self, data):
254 255 return Assignment(**data)
255 256
  257 +
256 258 class EditForm(base.EditForm):
257 259 """Portlet edit form.
258 260
81 src/collective/twitter/portlets/twsearch.py
... ... @@ -1,36 +1,36 @@
1   -from zope.interface import implements
2   -from zope.interface import alsoProvides
  1 +# -*- coding: utf-8 -*-
3 2
4   -from plone.portlets.interfaces import IPortletDataProvider
5   -from plone.app.portlets.portlets import base
  3 +import DateTime
  4 +import logging
  5 +import twitter
  6 +
  7 +from time import time
6 8
7 9 from zope import schema
  10 +
8 11 from zope.component import getUtility
9   -from Products.CMFCore.utils import getToolByName
  12 +from zope.interface import implements
  13 +from zope.interface import alsoProvides
10 14 from zope.formlib import form
  15 +from zope.schema.interfaces import IContextSourceBinder
11 16 from zope.schema.vocabulary import SimpleVocabulary
  17 +from zope.security import checkPermission
  18 +
  19 +from plone.app.portlets.portlets import base
  20 +from plone.memoize import ram
  21 +from plone.portlets.interfaces import IPortletDataProvider
  22 +from plone.registry.interfaces import IRegistry
12 23
13 24 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
14 25
15   -from plone.registry.interfaces import IRegistry
16   -from zope.schema.interfaces import IContextSourceBinder
17 26 from collective.prettydate.interfaces import IPrettyDate
18 27
19   -from zope.security import checkPermission
20   -
21   -from collective.twitter.portlets.config import PROJECTNAME
22 28 from collective.twitter.portlets import _
23   -
24   -from plone.memoize import ram
25   -from time import time
26   -
27   -import DateTime
28   -import twitter
29   -import hashlib
30   -import logging
  29 +from collective.twitter.portlets.config import PROJECTNAME
31 30
32 31 logger = logging.getLogger(PROJECTNAME)
33 32
  33 +
34 34 def TwitterAccounts(context):
35 35 registry = getUtility(IRegistry)
36 36 accounts = registry['collective.twitter.accounts']
@@ -79,7 +79,7 @@ class ITwitterSearchPortlet(IPortletDataProvider):
79 79 description=_(u"Show people's avatars."),
80 80 required=False)
81 81
82   - max_results = schema.Int(title=_(u'Maximum results'),
  82 + max_results = schema.Int(title=_(u'Maximum results'),
83 83 description=_(u"The maximum results number."),
84 84 required=True,
85 85 default=20)
@@ -129,7 +129,6 @@ def title(self):
129 129 return _(u"Twitter search Portlet")
130 130
131 131
132   -
133 132 class Renderer(base.Renderer):
134 133 """Portlet renderer.
135 134
@@ -140,7 +139,6 @@ class Renderer(base.Renderer):
140 139
141 140 render = ViewPageTemplateFile('twsearch.pt')
142 141
143   -
144 142 def getHeader(self):
145 143 """
146 144 Returns the header for the portlet
@@ -162,47 +160,45 @@ def getSearchResults(self):
162 160 registry = getUtility(IRegistry)
163 161 accounts = registry.get('collective.twitter.accounts', [])
164 162
165   - ploneutils = getToolByName(self.context, 'plone_utils')
166   -
167 163 account = accounts.get(self.data.tw_account, {})
168 164 results = []
169 165
170 166 if account:
171 167 logger.info("Got a valid account.")
172   - logger.info("consumer_key = %s"%account.get('consumer_key'))
173   - logger.info("consumer_secret = %s"%account.get('consumer_secret'))
174   - logger.info("access_token_key = %s"%account.get('oauth_token'))
175   - logger.info("access_token_secret = %s"%account.get('oauth_token_secret'))
  168 + logger.info("consumer_key = %s" % account.get('consumer_key'))
  169 + logger.info("consumer_secret = %s" % account.get('consumer_secret'))
  170 + logger.info("access_token_key = %s" % account.get('oauth_token'))
  171 + logger.info("access_token_secret = %s" % account.get('oauth_token_secret'))
176 172
177   - tw = twitter.Api(consumer_key = account.get('consumer_key'),
178   - consumer_secret = account.get('consumer_secret'),
179   - access_token_key = account.get('oauth_token'),
180   - access_token_secret = account.get('oauth_token_secret'),)
  173 + tw = twitter.Api(consumer_key=account.get('consumer_key'),
  174 + consumer_secret=account.get('consumer_secret'),
  175 + access_token_key=account.get('oauth_token'),
  176 + access_token_secret=account.get('oauth_token_secret'),)
181 177
182 178 search_str = self.data.search_string
183 179 max_results = self.data.max_results
184 180
185 181 try:
186 182 results = tw.GetSearch(search_str, per_page=max_results)
187   - logger.info("%s results obtained."%len(results))
  183 + logger.info("%s results obtained." % len(results))
188 184 except Exception, e:
189   - logger.info("Something went wrong: %s."%e)
  185 + logger.info("Something went wrong: %s." % e)
190 186 results = []
191 187
192 188 return results
193 189
194   -
195 190 def getTweet(self, result):
196 191 # The API includes the username in the tweet's text, we need to
197 192 # remove it here. Also, we need to make URLs, hastags and users,
198 193 # clickable.
199   - URL_TEMPLATE ="""
  194 +
  195 + URL_TEMPLATE = """
200 196 <a href="%s" target="blank_">%s</a>
201 197 """
202   - HASHTAG_TEMPLATE ="""
  198 + HASHTAG_TEMPLATE = """
203 199 <a href="http://twitter.com/#!/search?q=%s" target="blank_">%s</a>
204 200 """
205   - USER_TEMPLATE ="""
  201 + USER_TEMPLATE = """
206 202 <a href="http://twitter.com/#!/%s" target="blank_">%s</a>
207 203 """
208 204
@@ -216,15 +212,15 @@ def getTweet(self, result):
216 212 for index, word in enumerate(split_text):
217 213 if word.startswith('@'):
218 214 # This is a user
219   - split_text[index] = USER_TEMPLATE%(word[1:],word)
  215 + split_text[index] = USER_TEMPLATE % (word[1:], word)
220 216 elif word.startswith('#'):
221 217 # This is a hashtag
222   - split_text[index] = HASHTAG_TEMPLATE%("%23"+word[1:],word)
  218 + split_text[index] = HASHTAG_TEMPLATE % ("%23" + word[1:], word)
223 219 elif word.startswith('http'):
224 220 # This is a hashtag
225   - split_text[index] = URL_TEMPLATE%(word,word)
  221 + split_text[index] = URL_TEMPLATE % (word, word)
226 222
227   - return "<p>%s</p>"%' '.join(split_text)
  223 + return "<p>%s</p>" % ' '.join(split_text)
228 224
229 225 def getTweetUrl(self, result):
230 226 return "https://twitter.com/%s/status/%s" % \
@@ -239,7 +235,6 @@ def getReTweetUrl(self, result):
239 235 def getFavTweetUrl(self, result):
240 236 return "https://twitter.com/intent/favorite?tweet_id=%s" % result.id
241 237
242   -
243 238 def getDate(self, result):
244 239 if self.data.pretty_date:
245 240 # Returns human readable date for the tweet
@@ -250,6 +245,7 @@ def getDate(self, result):
250 245
251 246 return date
252 247
  248 +
253 249 class AddForm(base.AddForm):
254 250 """Portlet add form.
255 251
@@ -262,6 +258,7 @@ class AddForm(base.AddForm):
262 258 def create(self, data):
263 259 return Assignment(**data)
264 260
  261 +
265 262 class EditForm(base.EditForm):
266 263 """Portlet edit form.
267 264

0 comments on commit 983e9a3

Please sign in to comment.
Something went wrong with that request. Please try again.