Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

removed all pyflakes and pep8.py warnings #7

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
10 setup.py
@@ -12,7 +12,7 @@
'pyramid',
'SQLAlchemy',
'transaction',
- 'repoze.tm2>=1.0b1', # default_commit_veto
+ 'repoze.tm2>=1.0b1', # default_commit_veto
'zope.sqlalchemy',
'WebError',
'pyramid_simpleform',
@@ -21,13 +21,13 @@
'pycrypto',
]
-if sys.version_info[:3] < (2,5,0):
+if sys.version_info[:3] < (2, 5, 0):
requires.append('pysqlite')
setup(name='shootout',
version='0.2.1',
description='A generic idea discussion and rating app (Pyramid sample)',
- long_description=README + '\n\n' + CHANGES,
+ long_description=README + '\n\n' + CHANGES,
classifiers=[
"Framework :: Pylons",
"Framework :: BFG",
@@ -47,8 +47,8 @@
include_package_data=True,
zip_safe=False,
test_suite='shootout.tests',
- install_requires = requires,
- entry_points = """\
+ install_requires=requires,
+ entry_points="""\
[paste.app_factory]
main = shootout:main
""",
View
1  shootout/__init__.py
@@ -1,7 +1,6 @@
from pyramid.config import Configurator
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
-from pyramid.session import UnencryptedCookieSessionFactoryConfig
from pyramid_beaker import session_factory_from_settings
View
15 shootout/models.py
@@ -28,9 +28,11 @@
crypt = cryptacular.bcrypt.BCRYPTPasswordManager()
+
def hash_password(password):
return unicode(crypt.encode(password))
+
class User(Base):
"""
Application's user model.
@@ -64,7 +66,7 @@ def __init__(self, username, password, name, email):
@classmethod
def get_by_username(cls, username):
- return DBSession.query(cls).filter(cls.username==username).first()
+ return DBSession.query(cls).filter(cls.username == username).first()
@classmethod
def check_password(cls, username, password):
@@ -101,7 +103,7 @@ def extract_tags(tags_string):
@classmethod
def get_by_name(cls, tag_name):
- tag = DBSession.query(cls).filter(cls.name==tag_name)
+ tag = DBSession.query(cls).filter(cls.name == tag_name)
return tag.first()
@classmethod
@@ -117,7 +119,7 @@ def create_tags(cls, tags_string):
tags.append(tag)
return tags
-
+
@classmethod
def tag_counts(cls):
query = DBSession.query(Tag.name, func.count('*'))
@@ -164,7 +166,7 @@ def get_query(cls, with_joinedload=True):
@classmethod
def get_by_id(cls, idea_id, with_joinedload=True):
query = cls.get_query(with_joinedload)
- return query.filter(cls.idea_id==idea_id).first()
+ return query.filter(cls.idea_id == idea_id).first()
@classmethod
def get_by_tagname(cls, tag_name, with_joinedload=True):
@@ -174,7 +176,7 @@ def get_by_tagname(cls, tag_name, with_joinedload=True):
@classmethod
def ideas_bunch(cls, order_by, how_many=10, with_joinedload=True):
query = cls.get_query(with_joinedload).join('author')
- return query.filter(cls.target==None).order_by(order_by)[:how_many]
+ return query.filter(cls.target == None).order_by(order_by)[:how_many]
def user_voted(self, username):
return bool(self.voted_users.filter_by(username=username).first())
@@ -197,8 +199,9 @@ class RootFactory(object):
(Allow, Everyone, 'view'),
(Allow, Authenticated, 'post')
]
+
def __init__(self, request):
- pass #pragma: no cover
+ pass # pragma: no cover
def initialize_sql(engine): # pragma: no cover
View
10 shootout/tests/test_models.py
@@ -67,7 +67,6 @@ def test_doesnt_exitst(self):
self.assertRaises(NoResultFound, query.one)
def test_arleady_exist(self):
- from shootout.models import User
from sqlalchemy.exc import IntegrityError
self._addUser()
self.assertRaises(IntegrityError, self._addUser)
@@ -80,7 +79,7 @@ def test_password_hashing(self):
def test_password_checking(self):
from shootout.models import User
- user = self._addUser()
+ self._addUser()
self.assertTrue(User.check_password(u'username', u'password'))
self.assertFalse(User.check_password(u'username', u'wrong'))
self.assertFalse(User.check_password(u'nobody', u'password'))
@@ -89,7 +88,7 @@ def test_getting_by_username(self):
from shootout.models import User
user = self._addUser()
self.assertEqual(user, User.get_by_username(u'username'))
-
+
class TestTag(ModelsTestCase):
def test_extracting_tags(self):
@@ -110,7 +109,7 @@ def test_creating_tags(self):
self.assertEqual(tags[2].name, tags_names.pop())
def test_tags_counts(self):
- from shootout.models import Tag, Idea
+ from shootout.models import Tag
user = self._addUser()
@@ -233,11 +232,10 @@ def test_ideas_bunch(self):
[idea1, idea4, idea2, idea3])
def test_user_voted(self):
- from shootout.models import Idea
idea = self._addIdea()
voting_user = self._addUser(u'voter')
idea.voted_users.append(voting_user)
self.session.flush()
self.assertTrue(idea.user_voted(u'voter'))
self.assertFalse(idea.user_voted(u'xxx'))
-
+
View
21 shootout/tests/test_views.py
@@ -14,6 +14,7 @@ def _initTestingDB():
Base.metadata.create_all(engine)
return session
+
def _registerRoutes(config):
config.add_route('idea', '/ideas/{idea_id}')
config.add_route('user', '/users/{username}')
@@ -26,12 +27,14 @@ def _registerRoutes(config):
config.add_route('about', '/about')
config.add_route('main', '/')
+
def _registerCommonTemplates(config):
config.testing_add_renderer('templates/login.pt')
config.testing_add_renderer('templates/toolbar.pt')
config.testing_add_renderer('templates/cloud.pt')
config.testing_add_renderer('templates/latest.pt')
+
class ViewTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
@@ -59,7 +62,7 @@ def _addIdea(self, target=None, user=None):
self.session.add(idea)
self.session.flush()
return idea
-
+
def test_main_view(self):
from shootout.views import main_view
self.config.testing_securitypolicy(u'username')
@@ -77,7 +80,7 @@ def test_idea_add_nosubmit_idea(self):
result = idea_add(request)
self.assertEqual(result['target'], None)
self.assertEqual(result['kind'], 'idea')
-
+
def test_idea_add_nosubmit_comment(self):
from shootout.views import idea_add
self.config.testing_securitypolicy(u'username')
@@ -96,7 +99,6 @@ def test_idea_add_not_existing_target(self):
result = idea_add(request)
self.assertEqual(result.code, 404)
-
def test_idea_add_submit_schema_fail_empty_params(self):
from shootout.views import idea_add
self.config.testing_securitypolicy(u'username')
@@ -146,7 +148,7 @@ def test_vote_on_own_idea(self):
from shootout.models import User
_registerRoutes(self.config)
idea = self._addIdea()
- user = self.session.query(User).one()
+ self.session.query(User).one()
self.assertEqual(idea.user_voted(u'username'), False)
self.config.testing_securitypolicy(u'username')
post_data = {
@@ -166,8 +168,7 @@ def test_vote_on_own_idea(self):
def test_positive_idea_voting(self):
from shootout.views import idea_vote
- from shootout.models import User
- _registerRoutes(self.config)
+ _registerRoutes(self.config)
user = self._addUser()
idea = self._addIdea(user=user)
voter = self._addUser(u'votername')
@@ -191,8 +192,7 @@ def test_positive_idea_voting(self):
def test_negative_idea_voting(self):
from shootout.views import idea_vote
- from shootout.models import User
- _registerRoutes(self.config)
+ _registerRoutes(self.config)
user = self._addUser()
idea = self._addIdea(user=user)
voter = self._addUser(u'votername')
@@ -243,7 +243,7 @@ def test_registration_submit_empty(self):
def test_registration_submit_schema_succeed(self):
from shootout.views import user_add
from shootout.models import User
- _registerRoutes(self.config)
+ _registerRoutes(self.config)
request = testing.DummyRequest(
post={
'form.submitted': u'Register',
@@ -310,7 +310,7 @@ def test_tag_view(self):
idea3 = self._addIdea(user=user)
idea3.tags.append(tag2)
self.session.flush()
-
+
request = testing.DummyRequest()
request.matchdict = {'tag_name': u'bar'}
result = tag_view(request)
@@ -346,7 +346,6 @@ def test_login_view_submit_fail(self):
messages = request.session.peek_flash()
self.assertEqual(messages, [u'Failed to login.'])
-
def test_login_view_submit_success(self):
from shootout.views import login_view
_registerRoutes(self.config)
View
17 shootout/views.py
@@ -26,7 +26,7 @@ def main_view(request):
top = Idea.ideas_bunch(Idea.hits.desc())
bottom = Idea.ideas_bunch(Idea.misses.desc())
last10 = Idea.ideas_bunch(Idea.idea_id.desc())
-
+
toplists = [
{'title': 'Latest shots', 'items': last10},
{'title': 'Most hits', 'items': top},
@@ -35,7 +35,7 @@ def main_view(request):
]
login_form = login_form_view(request)
-
+
return {
'username': authenticated_userid(request),
'toolbar': toolbar_view(request),
@@ -57,7 +57,7 @@ def idea_vote(request):
voter = User.get_by_username(voter_username)
redirect_url = route_url('idea', request, idea_id=idea.idea_id)
- response = HTTPMovedPermanently(location=redirect_url)
+ response = HTTPMovedPermanently(location=redirect_url)
if voter.user_id == idea.author_id:
request.session.flash(u'You cannot vote on your own ideas.')
@@ -82,7 +82,7 @@ class RegistrationSchema(formencode.Schema):
password = formencode.validators.String(not_empty=True)
confirm_password = formencode.validators.String(not_empty=True)
chained_validators = [
- formencode.validators.FieldsMatch('password','confirm_password')
+ formencode.validators.FieldsMatch('password', 'confirm_password')
]
@@ -94,7 +94,7 @@ def user_add(request):
if 'form.submitted' in request.POST and form.validate():
session = DBSession()
- username=form.data['username']
+ username = form.data['username']
user = User(
username=username,
password=form.data['password'],
@@ -157,7 +157,7 @@ def idea_add(request):
if tags:
idea.tags = tags
- session.add(idea)
+ session.add(idea)
redirect_url = route_url('idea', request, idea_id=idea.idea_id)
return HTTPFound(location=redirect_url)
@@ -174,6 +174,7 @@ def idea_add(request):
'kind': kind,
}
+
@view_config(permission='view', route_name='user',
renderer='templates/user.pt')
def user_view(request):
@@ -251,7 +252,7 @@ def login_view(request):
headers = remember(request, login)
request.session.flash(u'Logged in successfully.')
return HTTPFound(location=came_from, headers=headers)
-
+
request.session.flash(u'Failed to login.')
return HTTPFound(location=came_from)
@@ -269,7 +270,7 @@ def toolbar_view(request):
viewer_username = authenticated_userid(request)
return render(
'templates/toolbar.pt',
- {'viewer_username': viewer_username},
+ {'viewer_username': viewer_username},
request
)
Something went wrong with that request. Please try again.