Skip to content

Commit

Permalink
remove all pyflakes and pep8.py warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
virhilo committed Aug 24, 2011
1 parent 7687856 commit 7b6a8d6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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",
Expand All @@ -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
""",
Expand Down
1 change: 0 additions & 1 deletion shootout/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 9 additions & 6 deletions shootout/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

crypt = cryptacular.bcrypt.BCRYPTPasswordManager()


def hash_password(password):
return unicode(crypt.encode(password))


class User(Base):
"""
Application's user model.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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('*'))
Expand Down Expand Up @@ -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):
Expand All @@ -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())
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions shootout/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'))
Expand All @@ -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):
Expand All @@ -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()

Expand Down Expand Up @@ -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'))

21 changes: 10 additions & 11 deletions shootout/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand All @@ -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()
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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 = {
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions shootout/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -35,7 +35,7 @@ def main_view(request):
]

login_form = login_form_view(request)

return {
'username': authenticated_userid(request),
'toolbar': toolbar_view(request),
Expand All @@ -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.')
Expand All @@ -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')
]


Expand All @@ -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'],
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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
)

Expand Down

0 comments on commit 7b6a8d6

Please sign in to comment.