Skip to content

Commit

Permalink
Merge 6a00e96 into cce944e
Browse files Browse the repository at this point in the history
  • Loading branch information
jainaman224 committed Aug 24, 2017
2 parents cce944e + 6a00e96 commit 17b29ae
Show file tree
Hide file tree
Showing 31 changed files with 2,216 additions and 10 deletions.
6 changes: 4 additions & 2 deletions docs/conf.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Zenodo.
# Copyright (C) 2015, 2016 CERN.
# Copyright (C) 2015, 2016, 2017 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -341,4 +341,6 @@


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {
'python': ('https://docs.python.org/', None)
}
4 changes: 2 additions & 2 deletions requirements.txt
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Zenodo.
# Copyright (C) 2015, 2016 CERN.
# Copyright (C) 2015, 2016, 2017 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand All @@ -27,6 +27,7 @@

# Requirements not on PyPI
-e git+https://github.com/zenodo/zenodo-migrator.git#egg=zenodo-migrator
-e git+https://github.com/jainaman224/invenio-userprofiles.git@researcher_profile#egg=invenio-userprofiles

# PyPI requirements
alabaster==0.7.10
Expand Down Expand Up @@ -144,7 +145,6 @@ invenio-search==1.0.0a9
invenio-search-ui==1.0.0a6
invenio-sipstore==1.0.0a7
invenio-theme==1.0.0b2
invenio-userprofiles==1.0.0a10
invenio-webhooks==1.0.0a4
ipython==5.4.1
ipython-genutils==0.2.0
Expand Down
14 changes: 13 additions & 1 deletion setup.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Zenodo.
# Copyright (C) 2015, 2016 CERN.
# Copyright (C) 2015, 2016, 2017 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -185,11 +185,16 @@
'console_scripts': [
'zenodo = zenodo.cli:cli',
],
'invenio_admin.views': [
'zenodo_profiles_view = '
'zenodo.modules.profiles.admin:researcher_profile_adminview',
],
'invenio_base.apps': [
'zenodo_auditor = zenodo.modules.auditor.ext:ZenodoAuditor',
'zenodo_cache = zenodo.modules.cache.ext:ZenodoCache',
'zenodo_fixtures = zenodo.modules.fixtures.ext:ZenodoFixtures',
'zenodo_pages = zenodo.modules.pages.ext:ZenodoPages',
'zenodo_profiles = zenodo.modules.profiles.ext:ZenodoProfiles',
'zenodo_records = zenodo.modules.records.ext:ZenodoRecords',
'zenodo_deposit = zenodo.modules.deposit.ext:ZenodoDeposit',
'zenodo_xrootd = zenodo.modules.xrootd.ext:ZenodoXRootD',
Expand All @@ -209,17 +214,24 @@
'zenodo_frontpage = zenodo.modules.frontpage.views:blueprint',
'zenodo_openaire = zenodo.modules.openaire.views:blueprint',
'zenodo_pages = zenodo.modules.pages.views:blueprint',
'zenodo_profiles = zenodo.modules.profiles.views:blueprint',
'zenodo_redirector = zenodo.modules.redirector.views:blueprint',
'zenodo_search_ui = zenodo.modules.search_ui.views:blueprint',
'zenodo_theme = zenodo.modules.theme.views:blueprint',
'zenodo_spam = zenodo.modules.spam.views:blueprint',
],
'invenio_base.converters': [
'orcid = zenodo.modules.profiles.utils:OrcidConverter',
],
'invenio_base.api_blueprints': [
'zenodo_rest = zenodo.modules.rest.views:blueprint',
],
'invenio_base.api_converters': [
'file_key = zenodo.modules.deposit.utils:FileKeyConverter',
],
'invenio_db.alembic': [
'zenodo_profiles = zenodo.modules.profiles:alembic',
],
'invenio_i18n.translations': [
'messages = zenodo',
],
Expand Down
54 changes: 51 additions & 3 deletions tests/unit/conftest.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Zenodo.
# Copyright (C) 2015, 2016 CERN.
# Copyright (C) 2015, 2016, 2017 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -42,8 +42,9 @@
from flask_celeryext import create_celery_app
from flask_security import login_user
from fs.opener import opener
from helpers import bearer_auth
from helpers import bearer_auth, publish_and_expunge
from invenio_access.models import ActionUsers
from invenio_accounts.models import User
from invenio_accounts.testutils import create_test_user
from invenio_admin.permissions import action_admin_access
from invenio_communities.models import Community
Expand All @@ -56,7 +57,7 @@
from invenio_indexer.api import RecordIndexer
from invenio_oaiserver.models import OAISet
from invenio_oauth2server.models import Client, Token
from invenio_oauthclient.models import RemoteAccount
from invenio_oauthclient.models import RemoteAccount, UserIdentity
from invenio_pidstore.models import PersistentIdentifier, PIDStatus
from invenio_pidstore.resolver import Resolver
from invenio_records.api import Record
Expand Down Expand Up @@ -1001,3 +1002,50 @@ def g_tester_id(app, db):
)
db.session.commit()
return tester.id


@pytest.fixture
def orcid_user(app, db, users):
"""Fixture that add orcid to user."""
with db.session.begin_nested():
remote_account1 = RemoteAccount(
user_id=users[1]['id'],
client_id=app.config.get(
'ORCID_APP_CREDENTIALS').get('consumer_key'),
extra_data={"orcid": "X123-4567-890X-1234"})
db.session.add(remote_account1)
user_identity1 = UserIdentity(
id_user=users[1]['id'],
id='X123-4567-890X-1234',
method='orcid'
)
db.session.add(user_identity1)

remote_account2 = RemoteAccount(
user_id=users[2]['id'],
client_id=app.config.get(
'ORCID_APP_CREDENTIALS').get('consumer_key'),
extra_data={"orcid": "0000-0002-1694-233X"})
db.session.add(remote_account2)
user_identity2 = UserIdentity(
id_user=users[2]['id'],
id='0000-0002-1694-233X',
method='orcid'
)
db.session.add(user_identity2)
db.session.commit()


@pytest.fixture
def record_indexer(db, es, deposit, deposit_file):
"""Fixture that add record for searching."""
deposit_index_name = 'deposits-records-record-v1.0.0'
records_index_name = 'records-record-v1.0.0'
deposit['creators'][0]['orcid'] = '0000-0002-1694-233X'
deposit_v1 = publish_and_expunge(db, deposit)
recid_v1, record_v1 = deposit_v1.fetch_published()

RecordIndexer().index_by_id(str(record_v1.id))
RecordIndexer().process_bulk_queue()
current_search.flush_and_refresh(index=deposit_index_name)
current_search.flush_and_refresh(index=records_index_name)
85 changes: 85 additions & 0 deletions tests/unit/profiles/test_profiles_models.py
@@ -0,0 +1,85 @@
# -*- coding: utf-8 -*-
#
# This file is part of Zenodo.
# Copyright (C) 2017 CERN.
#
# Zenodo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Zenodo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zenodo. If not, see <http://www.gnu.org/licenses/>.
#
# In applying this licence, CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.

"""Tests for researcher profile models."""

from __future__ import absolute_import, print_function

from invenio_accounts.models import User

from zenodo.modules.profiles import Profile


def test_profiles(app):
"""Test Profile model."""
researcher_profile = Profile()

assert researcher_profile.show_profile is None
assert researcher_profile.allow_contact_owner is None
assert researcher_profile.bio is None
assert researcher_profile.affiliation is None
assert researcher_profile.location is None
assert researcher_profile.website is None
researcher_profile.show_profile = True
researcher_profile.allow_contact_owner = True
researcher_profile.bio = 'Tester bio'
researcher_profile.affiliation = 'Testing world'
researcher_profile.location = 'Testing land'
researcher_profile.website = 'Tester.testing'
assert researcher_profile.show_profile
assert researcher_profile.allow_contact_owner
assert researcher_profile.bio == 'Tester bio'
assert researcher_profile.affiliation == 'Testing world'
assert researcher_profile.location == 'Testing land'
assert researcher_profile.website == 'Tester.testing'


def test_profile_updating(app, db):
"""Test Profile model update."""
with app.app_context():
user = User(email='lollorosso', password='test_password')
db.session.add(user)
db.session.commit()

assert user.researcher_profile is not None

researcher_profile = Profile.get_by_userid(user.id)

researcher_profile.affiliation = 'Testing world'
researcher_profile.location = 'Testing land'
assert researcher_profile.affiliation == 'Testing world'
assert researcher_profile.location == 'Testing land'


def test_delete_cascade(app, db):
"""Test that deletion of user, also removes profile."""
with app.app_context():
with db.session.begin_nested():
user = User(email='test@example.org')
db.session.add(user)
db.session.commit()

assert Profile.get_by_userid(user.id) is not None
db.session.delete(user)
db.session.commit()

assert Profile.get_by_userid(user.id) is None

0 comments on commit 17b29ae

Please sign in to comment.