Peter Justin 8 лет назад
Родитель
Сommit
c9befa9d1a

+ 4 - 6
celery_worker.py

@@ -11,11 +11,9 @@
     :copyright: (c) 2016 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
 """
-try:
-    from flaskbb.configs.production import ProductionConfig as Config
-except ImportError:
-    from flaskbb.configs.default import DefaultConfig as Config
+import os
 from flaskbb.app import create_app
-from flaskbb.extensions import celery
+from flaskbb.extensions import celery  # noqa
 
-app = create_app(Config)
+_basepath = os.path.dirname(os.path.abspath(__file__))
+app = create_app(config=os.path.join(_basepath, 'flaskbb.cfg'))

+ 1 - 2
flaskbb/__init__.py

@@ -9,7 +9,6 @@
     :copyright: (c) 2014 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
 """
+from flaskbb.app import create_app  # noqa
 
 __version__ = '1.0.dev0'
-
-from flaskbb.app import create_app

+ 0 - 1
flaskbb/auth/__init__.py

@@ -1 +0,0 @@
-

+ 2 - 1
flaskbb/auth/forms.py

@@ -76,7 +76,8 @@ class RegisterForm(FlaskForm):
 
         if len(field.data) < min_length or len(field.data) > max_length:
             raise ValidationError(_(
-                "Username must be between %(min)s and %(max)s characters long.",
+                "Username must be between %(min)s and %(max)s "
+                "characters long.",
                 min=min_length, max=max_length)
             )
         if field.data.lower() in blacklist:

+ 5 - 5
flaskbb/cli/__init__.py

@@ -15,8 +15,8 @@
     :copyright: (c) 2016 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
 """
-from flaskbb.cli.main import flaskbb
-from flaskbb.cli.plugins import plugins
-from flaskbb.cli.themes import themes
-from flaskbb.cli.translations import translations
-from flaskbb.cli.users import users
+from flaskbb.cli.main import flaskbb  # noqa
+from flaskbb.cli.plugins import plugins  # noqa
+from flaskbb.cli.themes import themes  # noqa
+from flaskbb.cli.translations import translations  # noqa
+from flaskbb.cli.users import users  # noqa

+ 1 - 1
flaskbb/cli/main.py

@@ -218,7 +218,7 @@ def download_emoji():
     """
     click.secho("[+] Downloading emojis...", fg="cyan")
     HOSTNAME = "https://api.github.com"
-    REPO = "/repos/arvida/emoji-cheat-sheet.com/contents/public/graphics/emojis"
+    REPO = "/repos/arvida/emoji-cheat-sheet.com/contents/public/graphics/emojis"  # noqa
     FULL_URL = "{}{}".format(HOSTNAME, REPO)
     DOWNLOAD_PATH = os.path.join(current_app.static_folder, "emoji")
     response = requests.get(FULL_URL)

+ 1 - 1
flaskbb/cli/utils.py

@@ -25,7 +25,7 @@ from flaskbb.utils.populate import create_user, update_user
 
 cookiecutter_available = False
 try:
-    from cookiecutter.main import cookiecutter
+    from cookiecutter.main import cookiecutter  # noqa
     cookiecutter_available = True
 except ImportError:
     pass

+ 2 - 2
flaskbb/forum/models.py

@@ -331,8 +331,8 @@ class Topic(db.Model, CRUDMixin):
 
         :param topicsread: The topicsread object for the topic
 
-        :param user: The user who should be checked if he has read the last post
-                    in the topic
+        :param user: The user who should be checked if he has read the
+                     last post in the topic
 
         :param forumsread: The forumsread object in which the topic is. If you
                         also want to check if the user has marked the forum as

+ 9 - 8
flaskbb/plugins/portal/__init__.py

@@ -31,17 +31,18 @@ fixture = (
         "description": "Configure the portal",
         "settings": (
             ('plugin_portal_forum_ids', {
-                'value':        [1],
-                'value_type':   "selectmultiple",
-                'name':         "Forum IDs",
-                'description':  "The forum ids from which forums the posts should be displayed on the portal.",
+                'value': [1],
+                'value_type': "selectmultiple",
+                'name': "Forum IDs",
+                'description': ("The forum ids from which forums the posts "
+                                "should be displayed on the portal."),
                 'extra': {"choices": available_forums, "coerce": int}
             }),
             ('plugin_portal_recent_topics', {
-                'value':        10,
-                'value_type':   "integer",
-                'name':         "Number of Recent Topics",
-                'description':  "The number of topics in Recent Topics portlet.",
+                'value': 10,
+                'value_type': "integer",
+                'name': "Number of Recent Topics",
+                'description': "The number of topics in Recent Topics.",
                 'extra': {"min": 1},
             }),
         ),

+ 2 - 2
flaskbb/utils/populate.py

@@ -348,7 +348,7 @@ def insert_bulk_data(topic_count=10, post_count=100):
 
             # Uncomment the line underneath and the other line to reduce
             # performance but fixes the above mentioned problem.
-            #topic.last_post_id = last_post_id
+            # topic.last_post_id = last_post_id
 
             created_posts += 1
             posts.append(post)
@@ -356,7 +356,7 @@ def insert_bulk_data(topic_count=10, post_count=100):
         # uncomment this and delete the one below, also uncomment the
         # topic.last_post_id line above. This will greatly reduce the
         # performance.
-        #db.session.bulk_save_objects(posts)
+        # db.session.bulk_save_objects(posts)
     db.session.bulk_save_objects(posts)
 
     # and finally, lets update some stats

+ 3 - 3
tests/conftest.py

@@ -1,3 +1,3 @@
-from tests.fixtures.app import *
-from tests.fixtures.forum import *
-from tests.fixtures.user import *
+from tests.fixtures.app import *  # noqa
+from tests.fixtures.forum import *  # noqa
+from tests.fixtures.user import *  # noqa

+ 3 - 3
tests/endtoend/test_auth_views.py

@@ -5,10 +5,10 @@ import pytest
 
 
 def test_overview_not_authorized(application, default_settings):
-    with application.test_request_context(), pytest.raises(AuthorizationRequired) as excinfo:
+    with application.test_request_context(), pytest.raises(AuthorizationRequired) as excinfo:  # noqa
         views.overview()
 
-    assert "Authorization is required to access this area." == excinfo.value.description
+    assert "Authorization is required to access this area." == excinfo.value.description  # noqa
 
 
 def test_overview_with_authorized(admin_user, application, default_settings):
@@ -18,7 +18,7 @@ def test_overview_with_authorized(admin_user, application, default_settings):
         assert 'Overview' in resp
 
 
-def test_overview_with_supermod(super_moderator_user, application, default_settings):
+def test_overview_with_supermod(super_moderator_user, application, default_settings):  # noqa
     with application.test_request_context():
         login_user(super_moderator_user)
         resp = views.overview()

+ 4 - 2
tests/unit/test_email.py

@@ -11,7 +11,8 @@ def test_send_reset_token_to_user(default_settings, user):
             send_reset_token(user)
 
             assert len(outbox) == 1
-            assert "/auth/reset-password" in outbox[0].body  # from /auth/reset-password/<token>
+            # from /auth/reset-password/<token>
+            assert "/auth/reset-password" in outbox[0].body
             assert "/auth/reset-password" in outbox[0].html
 
 
@@ -23,5 +24,6 @@ def test_send_activation_token_to_user(default_settings, user):
             send_activation_token(user)
 
             assert len(outbox) == 1
-            assert "/auth/activate" in outbox[0].body  # from /auth/activate/<token>
+            # from /auth/activate/<token>
+            assert "/auth/activate" in outbox[0].body
             assert "/auth/activate" in outbox[0].html

+ 9 - 3
tests/unit/test_forum_models.py

@@ -27,7 +27,9 @@ def test_category_delete(category):
 
 
 def test_category_delete_with_user(topic):
-    """Test the delete category method with recounting the users post counts."""
+    """Test the delete category method with recounting the users post
+    counts.
+    """
     user = topic.user
     forum = topic.forum
     category = topic.forum.category
@@ -550,7 +552,9 @@ def test_forumsread(topic, user):
     assert forumsread is not None
 
     forumsread.delete()
-    forumsread = ForumsRead.query.filter_by(forum_id=forumsread.forum_id).first()
+    forumsread = ForumsRead.query.\
+        filter_by(forum_id=forumsread.forum_id).\
+        first()
     assert forumsread is None
 
 
@@ -566,5 +570,7 @@ def test_topicsread(topic, user):
     assert topicsread is not None
 
     topicsread.delete()
-    topicsread = TopicsRead.query.filter_by(topic_id=topicsread.topic_id).first()
+    topicsread = TopicsRead.query.\
+        filter_by(topic_id=topicsread.topic_id).\
+        first()
     assert topicsread is None

+ 3 - 1
tests/unit/test_requirements.py

@@ -62,7 +62,9 @@ def test_Moderator_in_Forum_CanEditLockedTopic(moderator_user, topic_locked):
     assert r.CanEditPost(moderator_user, request)
 
 
-def test_FredIsAMod_but_still_cant_edit_topic_in_locked_forum(Fred, topic_locked, default_groups):
+def test_FredIsAMod_but_still_cant_edit_topic_in_locked_forum(
+        Fred, topic_locked, default_groups):
+
     request = SimpleNamespace(view_args={'topic_id': topic_locked.id})
     Fred.primary_group = default_groups[2]
     assert not r.CanEditPost(Fred, request)

+ 17 - 15
tests/unit/utils/test_helpers.py

@@ -1,5 +1,5 @@
-#-*- coding: utf-8 -*-
-import datetime
+# -*- coding: utf-8 -*-
+import datetime as dt
 from flaskbb.utils.helpers import slugify, forum_is_unread, topic_is_unread, \
     crop_title, render_markup, is_online, format_date, format_quote, \
     get_image_info, check_image, time_utcnow
@@ -30,9 +30,9 @@ def test_forum_is_unread(guest, user, forum, topic, forumsread):
     # but before we have to add an read entry in forumsread and topicsread
     topic.update_read(user, topic.forum, forumsread)
 
-    time_read = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
+    time_read = dt.datetime.utcnow() - dt.timedelta(hours=1)
     forumsread.cleared = time_read  # lets cheat here a bit :P
-    forumsread.last_read = datetime.datetime.utcnow()
+    forumsread.last_read = dt.datetime.utcnow()
     forumsread.save()
     assert not forum_is_unread(forum, forumsread, user)
 
@@ -43,7 +43,7 @@ def test_forum_is_unread(guest, user, forum, topic, forumsread):
     # there haven't been a post since TRACKER_LENGTH and thus the forum is read
     flaskbb_config["TRACKER_LENGTH"] = 1
     # this is cheating; don't do this.
-    forum.last_post_created = forum.last_post_created - datetime.timedelta(hours=48)
+    forum.last_post_created = forum.last_post_created - dt.timedelta(hours=48)
     forum.save()
     assert not forum_is_unread(forum, forumsread, user)
 
@@ -63,20 +63,22 @@ def test_topic_is_unread(guest, user, forum, topic, topicsread, forumsread):
     assert topic_is_unread(topic, topicsread, user, forumsread)
 
     # TopicsRead is none and the forum has never been marked as read
-    assert topic_is_unread(topic, topicsread=None, user=user, forumsread=forumsread)
+    assert topic_is_unread(topic, topicsread=None, user=user,
+                           forumsread=forumsread)
 
     # lets mark the forum as read
     forumsread.cleared = time_utcnow()
     forumsread.last_read = time_utcnow()
     forumsread.save()
-    assert not topic_is_unread(topic, topicsread=None, user=user, forumsread=forumsread)
+    assert not topic_is_unread(topic, topicsread=None, user=user,
+                               forumsread=forumsread)
 
     # disabled tracker
     flaskbb_config["TRACKER_LENGTH"] = 0
     assert not topic_is_unread(topic, None, user, None)
 
     # post is older than tracker length
-    time_posted = time_utcnow() - datetime.timedelta(days=2)
+    time_posted = time_utcnow() - dt.timedelta(days=2)
     flaskbb_config["TRACKER_LENGTH"] = 1
     topic.last_post.date_created = time_posted
     topic.save()
@@ -101,13 +103,13 @@ def test_is_online(default_settings, user):
 
 
 def test_format_date():
-    date = datetime.date(2015, 2, 15)
-    time = datetime.datetime.combine(date, datetime.datetime.min.time())
+    date = dt.date(2015, 2, 15)
+    time = dt.datetime.combine(date, dt.datetime.min.time())
     assert format_date(time) == "2015-02-15"
 
 
 def test_format_quote(topic):
-    expected_markdown = "**[test_normal](http://localhost:5000/user/test_normal) wrote:**\n> Test Content Normal\n"
+    expected_markdown = "**[test_normal](http://localhost:5000/user/test_normal) wrote:**\n> Test Content Normal\n"  # noqa
     actual = format_quote(topic.first_post.username, topic.first_post.content)
     assert actual == expected_markdown
 
@@ -119,9 +121,9 @@ def test_get_image_info():
     png = "http://i.imgur.com/JXzKxNs.png"
 
     # Issue #207 Image - This works now
-    #issue_img = "http://b.reich.io/gtlbjc.jpg"
-    #issue_img = get_image_info(issue_img)
-    #assert issue_img["content_type"] == "JPEG"
+    # issue_img = "http://b.reich.io/gtlbjc.jpg"
+    # issue_img = get_image_info(issue_img)
+    # assert issue_img["content_type"] == "JPEG"
 
     jpg_img = get_image_info(jpg)
     assert jpg_img["content_type"] == "JPEG"
@@ -152,7 +154,7 @@ def test_check_image(default_settings):
     # random too big image
     img_size = "http://i.imgur.com/l3Vmp4m.gif"
     # random image wrong type
-    img_type = "https://d11xdyzr0div58.cloudfront.net/static/logos/archlinux-logo-black-scalable.f931920e6cdb.svg"
+    img_type = "https://d11xdyzr0div58.cloudfront.net/static/logos/archlinux-logo-black-scalable.f931920e6cdb.svg"  # noqa
 
     data = check_image(img_width)
     assert "wide" in data[0]

+ 7 - 4
tests/unit/utils/test_populate.py

@@ -1,11 +1,14 @@
-import pytest
-from flaskbb.utils.populate import *
+from flaskbb.utils.populate import delete_settings_from_fixture, \
+    create_settings_from_fixture, update_settings_from_fixture, \
+    create_default_groups, create_test_data, insert_bulk_data, \
+    create_welcome_forum, create_user
 from flaskbb.fixtures.groups import fixture as group_fixture
 from flaskbb.fixtures.settings import fixture as settings_fixture
-from flaskbb.user.models import Group
+from flaskbb.user.models import Group, User
 from flaskbb.forum.models import Category, Topic, Post
+from flaskbb.management.models import Setting, SettingsGroup
+
 
-# 184-199, 218-268, 278-307
 def test_delete_settings_from_fixture(default_settings):
     groups_count = SettingsGroup.query.count()
     assert len(settings_fixture) == groups_count

+ 1 - 1
tests/unit/utils/test_settings.py

@@ -12,4 +12,4 @@ def test_flaskbb_config(default_settings):
     assert flaskbb_config['PROJECT_TITLE'] == 'FlaskBBTest'
     # test __iter__
     test_dict = {}
-    assert type(flaskbb_config.__iter__()) == type(test_dict.__iter__())
+    assert type(flaskbb_config.__iter__()) == isinstance(test_dict.__iter__())

+ 15 - 0
tox.ini

@@ -5,3 +5,18 @@ envlist = py27,py35
 deps = -rrequirements-dev.txt
 whitelist_externals = make
 commands = py.test
+
+[flake8]
+ignore = E712, E711, C901
+exclude =
+    .git,
+    __pycache__,
+    docs/source/conf.py,
+    migrations,
+    flaskbb/configs,
+    flaskbb/fixtures,
+    flaskbb/_compat.py,
+    build,
+    dist,
+    *.egg-info
+max-complexity = 10

+ 2 - 2
wsgi.py

@@ -1,7 +1,7 @@
 import os
 from flaskbb import create_app
 
-basepath = os.path.dirname(os.path.abspath(__file__))
+_basepath = os.path.dirname(os.path.abspath(__file__))
 
 # will throw an error if the config doesn't exist
-flaskbb = create_app(config=os.path.join(basepath, 'flaskbb.cfg'))
+flaskbb = create_app(config=os.path.join(_basepath, 'flaskbb.cfg'))