-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,791 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
migrations/versions/7f3f1a931278_add_tos_approved_at_to_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Add 'tos_approved_at' to User. | ||
Revision ID: 7f3f1a931278 | ||
Revises: b984311d26d7 | ||
Create Date: 2017-11-29 14:42:23.349903 | ||
""" | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# Revision identifiers, used by Alembic. | ||
revision = '7f3f1a931278' | ||
down_revision = 'b984311d26d7' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
"""Add 'users.tos_approved_at' column.""" | ||
with op.batch_alter_table('users', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('tos_approved_at', sa.DateTime(), nullable=True)) | ||
|
||
|
||
def downgrade(): | ||
"""Drop 'users.tos_approved_at' column.""" | ||
with op.batch_alter_table('users', schema=None) as batch_op: | ||
batch_op.drop_column('tos_approved_at') |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Test viewing collection.""" | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from flask import escape, url_for | ||
from flask_babel import gettext as _ | ||
|
||
from ..factories import CollectionFactory, PermissionFactory | ||
|
||
|
||
def test_user_can_view_collection_info(permission, testapp): | ||
"""View info about one of the user's collections.""" | ||
# Goes to homepage. | ||
res = testapp.get('/') | ||
# Fills out login form. | ||
form = res.forms['loginForm'] | ||
form['username'] = permission.user.email | ||
form['password'] = 'example' | ||
# Submits. | ||
res = form.submit().follow() | ||
# Clicks 'view collection' on profile page | ||
res = res.click(href=url_for('collection.view', collection_code=permission.collection.code)) | ||
# Sees collection info. | ||
assert res.status_code is 200 | ||
assert _('View Collection \'%(code)s\'', code=permission.collection.code) in res | ||
|
||
|
||
def test_user_sees_error_message_if_collection_code_does_not_exist(user, testapp): | ||
"""Show error when attempting to view a permission that does not exist.""" | ||
# Goes to homepage. | ||
res = testapp.get('/') | ||
# Fills out login form. | ||
form = res.forms['loginForm'] | ||
form['username'] = user.email | ||
form['password'] = 'myPrecious' | ||
# Submits. | ||
res = form.submit().follow() | ||
assert res.status_code is 200 | ||
# Fails to figures out the correct ID for another user. | ||
res = testapp.get(url_for('collection.view', collection_code='FAKE1')).follow() | ||
# Sees error message. | ||
assert escape(_('Collection code "%(code)s" does not exist', code='FAKE1')) in res | ||
|
||
|
||
def test_superuser_can_view_all_permissions_on_collection(superuser, permission, testapp): | ||
"""View all permissions as superuser.""" | ||
# Goes to homepage. | ||
res = testapp.get('/') | ||
# Fills out login form. | ||
form = res.forms['loginForm'] | ||
form['username'] = superuser.email | ||
form['password'] = 'myPrecious' | ||
# Submits. | ||
res = form.submit().follow() | ||
assert res.status_code is 200 | ||
# Goes to the right URL for viewing a collection. | ||
res = testapp.get(url_for('collection.view', collection_code=permission.collection.code)) | ||
assert res.status_code is 200 | ||
# Sees all permissions. | ||
assert _('Permissions') in res | ||
assert permission.user.email in res | ||
|
||
|
||
def test_cataloging_admin_can_view_all_permissions_on_own_collection(user, collection, testapp): | ||
"""View all permissions on a collection that you're managing.""" | ||
# Add cataloging admin permission. | ||
cataloging_admin_permission = PermissionFactory(user=user, collection=collection, | ||
cataloging_admin=True) | ||
cataloging_admin_permission.save() | ||
# Add 2nd cataloger+registrant permission. | ||
other_users_non_cataloging_admin_permission = PermissionFactory(collection=collection, | ||
cataloging_admin=False) | ||
other_users_non_cataloging_admin_permission.save() | ||
# Goes to homepage. | ||
res = testapp.get('/') | ||
# Fills out login form. | ||
form = res.forms['loginForm'] | ||
form['username'] = user.email | ||
form['password'] = 'myPrecious' | ||
# Submits. | ||
res = form.submit().follow() | ||
assert res.status_code is 200 | ||
# Goes to the right URL for viewing a collection. | ||
res = testapp.get(url_for('collection.view', | ||
collection_code=cataloging_admin_permission.collection.code)) | ||
assert res.status_code is 200 | ||
# Sees all permissions. | ||
assert _('Permissions') in res | ||
assert cataloging_admin_permission.user.email in res | ||
assert other_users_non_cataloging_admin_permission.user.email in res | ||
|
||
|
||
def test_cataloging_admin_sees_only_cataloging_admins_on_others_collection(user, collection, | ||
testapp): | ||
"""View only 'cataloging_admin' permissions on a collection that you're NOT managing.""" | ||
# Add cataloging admin permission. | ||
cataloging_admin_permission = PermissionFactory(user=user, collection=collection, | ||
cataloging_admin=True) | ||
cataloging_admin_permission.save() | ||
other_collection = CollectionFactory().save() | ||
# Add cataloger/registrant permission on 'other_collection'. | ||
other_users_non_cataloging_admin_permission = PermissionFactory(collection=other_collection, | ||
cataloging_admin=False) | ||
other_users_non_cataloging_admin_permission.save() | ||
# Add cataloging admin on 'other_collection'. | ||
other_user_with_cataloging_admin_permission = PermissionFactory(collection=other_collection, | ||
cataloging_admin=True) | ||
other_user_with_cataloging_admin_permission.save() | ||
# Goes to homepage. | ||
res = testapp.get('/') | ||
# Fills out login form. | ||
form = res.forms['loginForm'] | ||
form['username'] = user.email | ||
form['password'] = 'myPrecious' | ||
# Submits. | ||
res = form.submit().follow() | ||
assert res.status_code is 200 | ||
# Goes to the right URL for viewing a collection. | ||
res = testapp.get(url_for('collection.view', collection_code=other_collection.code)) | ||
assert res.status_code is 200 | ||
# Sees a subset of permissions. | ||
assert _('Cataloging Admins') in res | ||
assert _('Permissions') in res | ||
assert _('You will only see all permissions for those collections that you are ' | ||
'cataloging admin for.') in res | ||
assert other_users_non_cataloging_admin_permission.user.email not in res | ||
assert other_user_with_cataloging_admin_permission.user.email in res | ||
|
||
|
||
def test_non_cataloging_admin_user_sees_permissions_table_on_collections_they_have_permissions_for( | ||
user, collection, testapp): | ||
"""View own and 'cataloging_admin' permissions on collection thyself is associated with.""" | ||
# Preconditions. | ||
cataloging_admin_permission = PermissionFactory(collection=collection, cataloging_admin=True) | ||
others_regular_permission = PermissionFactory(collection=collection, cataloging_admin=False) | ||
own_regular_permission = PermissionFactory(user=user, collection=collection, | ||
cataloging_admin=False) | ||
# Goes to homepage. | ||
res = testapp.get('/') | ||
# Fills out login form. | ||
form = res.forms['loginForm'] | ||
form['username'] = user.email | ||
form['password'] = 'myPrecious' | ||
# Submits. | ||
res = form.submit().follow() | ||
assert res.status_code is 200 | ||
# Goes to the right URL for viewing a collection. | ||
res = testapp.get(url_for('collection.view', collection_code=collection.code)) | ||
assert res.status_code is 200 | ||
# Sees a subset of permissions. | ||
assert _('Cataloging Admins') in res | ||
assert _('Permissions') in res | ||
assert _('You will only see all permissions for those collections that you are ' | ||
'cataloging admin for.') in res | ||
assert cataloging_admin_permission.user.email in res | ||
assert others_regular_permission.user.email not in res | ||
assert own_regular_permission.user.email in res | ||
|
||
|
||
def test_non_cataloging_admin_users_sees_only_cataloging_admins_on_unassociated_collections( | ||
user, collection, testapp): | ||
"""Sees cataloging admins' list only when viewing a collection they are not associated with.""" | ||
# Preconditions. | ||
cataloging_admin_permission = PermissionFactory(collection=collection, cataloging_admin=True) | ||
assert user.has_any_permission_for(collection) is False | ||
|
||
# Goes to homepage. | ||
res = testapp.get('/') | ||
# Fills out login form. | ||
form = res.forms['loginForm'] | ||
form['username'] = user.email | ||
form['password'] = 'myPrecious' | ||
# Submits. | ||
res = form.submit().follow() | ||
assert res.status_code is 200 | ||
# Goes to the right URL for viewing a collection. | ||
res = testapp.get(url_for('collection.view', collection_code=collection.code)) | ||
assert res.status_code is 200 | ||
# Sees cataloging admins' list. | ||
assert _('Cataloging Admins') in res | ||
assert cataloging_admin_permission.user.email in res | ||
# Does not see permissions table. | ||
assert _('Permissions') not in res | ||
assert _('You will only see all permissions for those collections that you are ' | ||
'cataloging admin for.') not in res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.