I did some more code-keeping in this commit. I added a lot of documentation, so
that most of my functions do indeed have effective docstrings. I also changed
the decorators so that they imply eachother in a logical way. I also modified
the one decorator get_media_comment_by_id to be more usable with the variable
urls of mediagoblin.user_pages.views:file_a_report. I also noticed a few tests
had broken, so I went through them and fixed them up, finding that mostly there
were problems in my actual writing of the tests. I also did a few other small
tasks such as creating a new User method to check whether or not a User is ban-
-ned.
===============================================================================
Added in documentation
===============================================================================
--\ mediagoblin/db/models.py
--\ mediagoblin/decorators.py
--\ mediagoblin/moderation/forms.py
--\ mediagoblin/moderation/tools.py
--\ mediagoblin/moderation/views.py
--\ mediagoblin/user_pages/lib.py
===============================================================================
Rearranged decorators to be more efficient
===============================================================================
--\ mediagoblin/decorators.py
--| Made it so that user_not_banned is encapsulated in require_active_login
--| Made it so that require_active_login is encapsulated in user_has_privilege
--| Changed get_media_comment_by_id into get_optional_media_comment_by_id. It
| now returns valid code if the MediaComment id is absent. This makes it pos-
| -sible to use this decorator for the function:
| mediagoblin.user_pages.views:file_a_report
--\ mediagoblin/user_pages/views.py
--| Replaced the mediagoblin.user_pages.views:file_a_comment_report with the
| decorator mentioned above
--\ mediagoblin/user_pages/routing.py
-----------------------------------------------------------
| took out unnecessary @user_not_banned decorators |
-----------------------------------------------------------
--\ mediagoblin/submit/views.py
--\ mediagoblin/user_pages/views.py
===============================================================================
Fixed broken tests
===============================================================================
--\ mediagoblin/tests/test_auth.py
--\ mediagoblin/tests/test_privileges.py
--\ mediagoblin/tests/test_submission.py
===============================================================================
Fixed broken code
===============================================================================
--\ mediagoblin/tools/response.py
===============================================================================
Other Tasks
===============================================================================
--\ mediagoblin/db/models.py
--| Added in User.is_banned() method
--\ mediagoblin/decorators.py
--| Utitilized User.is_banned() method in the user_not_banned decorator
--\ mediagoblin/moderation/views.py
--| Made it impossible for an admin to ban themself.
--| Got rid of a vestigial print statement
--\ mediagoblin/templates/mediagoblin/base.html
--| Made it so the top panel does not show up for users that are banned.
--\ mediagoblin/templates/mediagoblin/moderation/user.html
--| Rearranged the javascript slightly
===============================================================================
This commit is contained in:
@@ -99,6 +99,12 @@ def test_register_views(test_app):
|
||||
assert new_user.status == u'needs_email_verification'
|
||||
assert new_user.email_verified == False
|
||||
|
||||
## Make sure that the proper privileges are granted on registration
|
||||
|
||||
assert new_user.has_privilege(u'commenter')
|
||||
assert new_user.has_privilege(u'uploader')
|
||||
assert new_user.has_privilege(u'reporter')
|
||||
assert not new_user.has_privilege(u'active')
|
||||
## Make sure user is logged in
|
||||
request = template.TEMPLATE_TEST_CONTEXT[
|
||||
'mediagoblin/user_pages/user.html']['request']
|
||||
@@ -330,14 +336,6 @@ def test_authentication_views(test_app):
|
||||
'next' : '/u/chris/'})
|
||||
assert urlparse.urlsplit(response.location)[2] == '/u/chris/'
|
||||
|
||||
def test_basic_privileges_granted_on_registration(test_app):
|
||||
user = User.query.filter(User.username==u'angrygirl').first()
|
||||
|
||||
assert User.has_privilege(u'commenter')
|
||||
assert User.has_privilege(u'uploader')
|
||||
assert User.has_privilege(u'reporter')
|
||||
assert not User.has_privilege(u'active')
|
||||
|
||||
@pytest.fixture()
|
||||
def authentication_disabled_app(request):
|
||||
return get_app(
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import date, timedelta
|
||||
from webtest import AppError
|
||||
|
||||
from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry
|
||||
@@ -88,7 +88,7 @@ class TestPrivilegeFunctionality:
|
||||
user_ban.delete()
|
||||
user_ban = UserBan(user_id=uid,
|
||||
reason=u'Testing whether user is banned',
|
||||
expiration_date= datetime.now() + timedelta(days=20))
|
||||
expiration_date= date.today() + timedelta(days=20))
|
||||
user_ban.save()
|
||||
|
||||
response = self.test_app.get('/')
|
||||
@@ -100,7 +100,7 @@ class TestPrivilegeFunctionality:
|
||||
#----------------------------------------------------------------------
|
||||
user_ban = UserBan.query.get(uid)
|
||||
user_ban.delete()
|
||||
exp_date = datetime.now() - timedelta(days=20)
|
||||
exp_date = date.today() - timedelta(days=20)
|
||||
user_ban = UserBan(user_id=uid,
|
||||
reason=u'Testing whether user is banned',
|
||||
expiration_date= exp_date)
|
||||
|
||||
@@ -46,7 +46,7 @@ class TestSubmission:
|
||||
|
||||
# TODO: Possibly abstract into a decorator like:
|
||||
# @as_authenticated_user('chris')
|
||||
fixture_add_user(privileges=[u'active',u'uploader'])
|
||||
fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
|
||||
|
||||
self.login()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user