|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# This file is part of Invenio. |
| 4 | +# Copyright (C) 2016-2018 CERN. |
| 5 | +# |
| 6 | +# Invenio is free software; you can redistribute it and/or modify it |
| 7 | +# under the terms of the MIT License; see LICENSE file for more details. |
| 8 | + |
| 9 | +from flask import Flask, url_for |
| 10 | +from flask_admin import Admin |
| 11 | +from invenio_admin import InvenioAdmin |
| 12 | +from invenio_db import db |
| 13 | + |
| 14 | +from invenio_userprofiles import InvenioUserProfiles |
| 15 | +from invenio_userprofiles.admin import UserProfileView, user_profile_adminview |
| 16 | + |
| 17 | + |
| 18 | +def test_admin(app): |
| 19 | + """Test flask-admin interace.""" |
| 20 | + InvenioUserProfiles(app) |
| 21 | + |
| 22 | + assert isinstance(user_profile_adminview, dict) |
| 23 | + |
| 24 | + assert 'model' in user_profile_adminview |
| 25 | + assert 'modelview' in user_profile_adminview |
| 26 | + |
| 27 | + admin = Admin(app, name="Test") |
| 28 | + |
| 29 | + user_model = user_profile_adminview.pop('model') |
| 30 | + user_view = user_profile_adminview.pop('modelview') |
| 31 | + admin.add_view(user_view(user_model, db.session, |
| 32 | + **user_profile_adminview)) |
| 33 | + |
| 34 | + with app.test_request_context(): |
| 35 | + request_url = url_for('userprofile.index_view') |
| 36 | + |
| 37 | + with app.app_context(): |
| 38 | + with app.test_client() as client: |
| 39 | + res = client.get( |
| 40 | + request_url, |
| 41 | + follow_redirects=True |
| 42 | + ) |
| 43 | + assert res.status_code == 200 |
| 44 | + assert b'Username' in (res.get_data()) |
| 45 | + assert b'Full Name' in (res.get_data()) |
0 commit comments