def test_get_my_doc_meta_with_category(client, admin, monkeypatch): login(client, admin) monkeypatch.setattr('app.task.views.DOCUMENT_PER_PAGE', 3) with captured_templates(client.application) as templates: assert client.get( url_for('task.my_doc_meta', category=Category.FLIP.value)).status_code == 200 template, context = templates.pop() assert template.name == 'task/document_dashboard.html' assert context['current_category'] == Category.FLIP.value assert set(get_ids(context['documents'].items)) == set( get_ids( DocumentMeta.objects(create_by=admin, category=Category.FLIP.value).order_by( '-priority', '-update_at').all()[:3])) assert client.get( url_for('task.my_doc_meta', category=Category.SHORT_TERM.value, page=2)).status_code == 200 template, context = templates.pop() assert template.name == 'task/document_dashboard.html' assert context['current_category'] == Category.SHORT_TERM.value assert set(get_ids(context['documents'].items)) == set( get_ids( DocumentMeta.objects( create_by=admin, category=Category.SHORT_TERM.value).order_by( '-priority', '-update_at').all()[3:6]))
def test_get_reset_password(client): with captured_templates(client.application) as templates: assert client.get(url_for('account.reset_password', token='valid')).status_code == 200 template, context = templates.pop() assert template.name == 'account/reset_password.html' assert isinstance(context['form'], ResetPasswordForm)
def test_post_update_doc_meta_failure(client, admin, doc): login(client, admin) data = { 'theme': 'duplicate', 'category': Category.SHORT_TERM.value, 'url': 'https://www.helloword.com', 'priority': 1 } assert client.post(url_for('task.update_doc_meta', doc_meta_id=INVALID_OBJECT_ID), data=data).status_code == 404 doc.reload() assert doc.url == 'https://www.test.com' with captured_templates(client.application) as templates: assert client.post(url_for('task.update_doc_meta', doc_meta_id=str(doc.id)), data=data).status_code == 200 template, context = templates.pop() assert template.name == 'task/manage_document.html' form = context['form'] assert not form.validate() doc.reload() assert doc.url == 'https://www.test.com'
def test_post_update_doc_meta_success(client, admin, doc): login(client, admin) with captured_templates(client.application) as templates: assert client.get( url_for('task.update_doc_meta', doc_meta_id=str(doc.id))).status_code == 200 template, context = templates.pop() assert template.name == 'task/manage_document.html' assert context['action'] == 'Update' assert context['data_type'] == str(doc) form = context['form'] assert isinstance(form, DocMetaForm) form.theme.data = 'new theme' form.category.data = Category.LONG_TERM.value form.url.data = 'https://www.newtest.com' form.priority.data = 3 assert redirect_to(client.post(url_for('task.update_doc_meta', doc_meta_id=str(doc.id)), data=form.data)) == \ real_url('task.update_doc_meta', doc_meta_id=str(doc.id)) doc.reload() assert doc.theme == 'new theme' assert doc.category == Category.LONG_TERM.value assert doc.url == 'https://www.newtest.com' assert doc.priority == 3
def test_get_reset_password_request(client, admin): login(client, admin) with captured_templates(client.application) as templates: assert client.get( url_for('account.reset_password_request')).status_code == 200 template, context = templates.pop() assert template.name == 'account/reset_password.html' assert isinstance(context['form'], RequestResetPasswordForm)
def test_get_manage(client, admin): login(client, admin) with captured_templates(client.application) as templates: assert client.get(url_for('account.manage')).status_code == 200 template, context = templates.pop() assert template.name == 'account/manage.html' assert context['user'] == admin assert context['form'] is None
def test_login_success(client, admin): with captured_templates(client.application) as templates: assert client.get(url_for('account.login')).status_code == 200 template, context = templates.pop() assert template.name == 'account/login.html' assert isinstance(context['form'], LoginForm) assert current_user.is_anonymous login(client, admin) assert not current_user.is_anonymous assert current_user == admin
def test_get_user_info(client, admin): login(client, admin) with captured_templates(client.application) as templates: assert client.get(url_for('admin.user_info', user_id=str(admin.id))).status_code == 200 template, context = templates.pop() assert template.name == 'admin/manage_user.html' assert context['user'] == admin assert client.get(url_for('admin.user_info', user_id=INVALID_OBJECT_ID)).status_code == 404
def test_get_unconfirmed(client, admin): login(client, admin) admin.confirmed = False admin.save() with captured_templates(client.application) as templates: assert client.get(url_for('account.unconfirmed')).status_code == 200 template, context = templates.pop() assert template.name == 'account/unconfirmed.html' admin.confirmed = True admin.save() assert redirect_to(client.get( url_for('account.unconfirmed'))) == real_url('main.index')
def test_get_my_doc_meta_with_search(client, admin, monkeypatch): login(client, admin) monkeypatch.setattr('app.task.views.DOCUMENT_PER_PAGE', 3) with captured_templates(client.application) as templates: # search empty string to return all documents assert client.get(url_for('task.my_doc_meta', search='')).status_code == 200 template, context = templates.pop() assert template.name == 'task/document_dashboard.html' assert context['current_search'] == '' assert set(get_ids(context['documents'].items)) == set( get_ids( DocumentMeta.objects(create_by=admin).order_by( '-priority', '-update_at').all()[:3]))
def test_get_join_from_invite(client): new_user = User(email='*****@*****.**') new_user.save() token = new_user.generate_confirmation_token() with captured_templates(client.application) as templates: assert client.get( url_for( 'account.join_from_invite', user_id=str(new_user.id), token=token)).status_code == 200 template, context = templates.pop() assert template.name == 'account/join_invite.html' assert isinstance(context['form'], CreatePasswordForm) new_user.delete()
def test_post_change_password_failure(client, admin): login(client, admin) data = { 'old_password': '******', 'new_password': '******', 'new_password2': 't12345' } with captured_templates(client.application) as templates: assert client.post( url_for('account.change_password'), data=data).status_code == 200 template, context = templates.pop() assert template.name == 'account/manage.html' assert isinstance(context['form'], ChangePasswordForm) admin.reload() assert not admin.verify_password(data['new_password']) assert admin.verify_password('test')
def test_post_change_user_email(client, admin): login(client, admin) data = {'email': '*****@*****.**'} with captured_templates(client.application) as templates: assert client.post( url_for('admin.change_user_email', user_id=str(admin.id)), data=data).status_code == 200 template, context = templates.pop() assert template.name == 'admin/manage_user.html' assert context['user'] == admin assert isinstance(context['form'], ChangeUserEmailForm) admin.reload() assert admin.email == data['email'] assert client.post( url_for('admin.change_user_email', user_id=INVALID_OBJECT_ID)).status_code == 404
def test_post_change_account_type(client, admin, user): login(client, admin) admin_role = Role.objects(name='Administrator').first() data = {'role': str(admin_role.id)} with captured_templates(client.application) as templates: assert client.post( url_for('admin.change_account_type', user_id=str(user.id)), data=data).status_code == 200 template, context = templates.pop() assert template.name == 'admin/manage_user.html' assert context['user'] == user assert isinstance(context['form'], ChangeAccountTypeForm) user.reload() assert user.role == admin_role assert redirect_to(client.post(url_for('admin.change_account_type', user_id=str(admin.id)), data=data)) == \ real_url('admin.user_info', user_id=admin.id) assert client.post( url_for('admin.change_account_type', user_id=INVALID_OBJECT_ID), data=data).status_code == 404
def test_get_register(client): with captured_templates(client.application) as templates: assert client.get(url_for('account.register')).status_code == 200 template, context = templates.pop() assert template.name == 'account/register.html' assert isinstance(context['form'], RegistrationForm)