@@ -101,6 +102,9 @@
Existing Publications:
({{ PUBLICATION_TYPES[pub['type']] }})
{{ pub['citation'] }}
{{ date_format(pub['date']) }}
+ {% if pub.get('abstract', '') %}
+
Abstract: {{ pub['abstract'] }}
+ {% end %}
{% if pub['downloads'] %}
Download:
@@ -189,8 +193,11 @@ Existing Publications:
}
const pub_id = pub.find('input[name="pub_id"]').val();
+ const abstract_text = Array.from(pub.find('.abstract').map(function(){return $(this).text()})).join('');
+
console.log('title:'+title);
console.log('authors:');console.log(authors);
+ console.log('abstract:');console.log(abstract_text);
console.log('pub_type:'+pub_type);
console.log('citation:'+citation);
console.log('date:'+date);
@@ -203,6 +210,7 @@ Existing Publications:
$('.new textarea[name="new_authors"]').val(authors.join('\n'));
$('.new input[name="new_date"]').val(date);
$('.new select[name="new_type"]').val(pub_type);
+ $('.new textarea[name="new_abstract"]').val(abstract_text);
$('.new textarea[name="new_citation"]').val(citation);
$('.new textarea[name="new_downloads"]').val(downloads.join('\n'));
$('.new input[name="new_projects"]').val(projects);
diff --git a/pubs/utils.py b/pubs/utils.py
index d029c8b..7d1372b 100644
--- a/pubs/utils.py
+++ b/pubs/utils.py
@@ -37,12 +37,13 @@ def create_indexes(db_url, db_name, background=True):
weights={'title': 10, 'authors': 5, 'citation': 1},
name='text_index', background=background)
-def validate(title, authors, pub_type, citation, date, downloads, projects, sites):
+def validate(title, authors, pub_type, abstract, citation, date, downloads, projects, sites):
assert isinstance(title, str)
assert isinstance(authors, list)
for a in authors:
assert isinstance(a, str)
assert pub_type in PUBLICATION_TYPES
+ assert isinstance(abstract, str)
assert isinstance(citation, str)
assert isinstance(date, str)
date_format(date)
@@ -56,23 +57,24 @@ def validate(title, authors, pub_type, citation, date, downloads, projects, site
for s in sites:
assert s in SITES
-async def add_pub(db, title, authors, pub_type, citation, date, downloads, projects, sites=None):
+async def add_pub(db, title, authors, pub_type, abstract, citation, date, downloads, projects, sites=None):
if not sites:
sites = []
- validate(title, authors, pub_type, citation, date, downloads, projects, sites)
+ validate(title, authors, pub_type, abstract, citation, date, downloads, projects, sites)
data = {
"title": title,
"authors": authors,
"type": pub_type,
"citation": citation,
"date": date,
+ "abstract": abstract,
"downloads": downloads,
"projects": projects,
"sites": sites,
}
await db.publications.insert_one(data)
-async def edit_pub(db, mongo_id, title=None, authors=None, pub_type=None, citation=None, date=None, downloads=None, projects=None, sites=None):
+async def edit_pub(db, mongo_id, title=None, authors=None, pub_type=None, abstract=None, citation=None, date=None, downloads=None, projects=None, sites=None):
match = {'_id': ObjectId(mongo_id)}
update = {}
if title:
@@ -86,6 +88,9 @@ async def edit_pub(db, mongo_id, title=None, authors=None, pub_type=None, citati
if pub_type:
assert pub_type in PUBLICATION_TYPES
update['type'] = pub_type
+ if abstract:
+ assert isinstance(abstract, str)
+ update['abstract'] = abstract
if citation:
assert isinstance(citation, str)
update['citation'] = citation
@@ -139,7 +144,7 @@ def parse_csv(row):
if isinstance(p['authors'], str):
p['authors'] = [p['authors']]
try:
- validate(p['title'], p['authors'], p['type'], p['citation'], p['date'], p['downloads'], p['projects'], p['sites'])
+ validate(p['title'], p['authors'], p['type'], p.get('abstract', ''), p['citation'], p['date'], p['downloads'], p['projects'], p['sites'])
except AssertionError:
raise Exception(f'Error validating pub with title {p["title"][:100]}')
diff --git a/requirements.txt b/requirements.txt
index 6b7ffcc..7554c44 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,4 +10,4 @@ motor
pymysql
unidecode
beautifulsoup4
--e git+https://github.com/WIPACrepo/rest-tools@v0.2.0#egg=rest_tools
+wipac-rest-tools
diff --git a/tests/test_main.py b/tests/test_main.py
index b5dc76e..426b260 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -10,7 +10,7 @@
async def get_pubs(*args, **kwargs):
- s = AsyncSession(retries=0)
+ s = AsyncSession(retries=0, backoff_factor=1)
r = await asyncio.wrap_future(s.get(*args, **kwargs))
r.raise_for_status()
soup = BeautifulSoup(r.content, 'html.parser')
@@ -27,7 +27,7 @@ async def test_no_pubs(server):
async def test_single_pub(server):
db, url = server
- await add_pub(db, title='Test Title', authors=['auth'],
+ await add_pub(db, title='Test Title', authors=['auth'], abstract="An abstract",
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
@@ -35,21 +35,22 @@ async def test_single_pub(server):
assert len(pubs) == 1
assert pubs[0].select('.title')[0].string == 'Test Title'
assert pubs[0].select('.author')[0].string == 'auth'
+ assert pubs[0].select('.abstract')[0].string == 'An abstract'
assert pubs[0].select('.project')[0].string == 'IceCube'
@pytest.mark.asyncio
async def test_multiple_pubs(server):
db, url = server
- await add_pub(db, title='Test Title', authors=['auth'],
+ await add_pub(db, title='Test Title', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth'],
+ await add_pub(db, title='Test Title2', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title3', authors=['auth'],
+ await add_pub(db, title='Test Title3', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
@@ -64,11 +65,11 @@ async def test_multiple_pubs(server):
async def test_project(server):
db, url = server
- await add_pub(db, title='Test Title', authors=['auth'],
+ await add_pub(db, title='Test Title', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth'],
+ await add_pub(db, title='Test Title2', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['hawc'])
@@ -81,15 +82,15 @@ async def test_project(server):
async def test_multi_project(server):
db, url = server
- await add_pub(db, title='Test Title', authors=['auth'],
+ await add_pub(db, title='Test Title', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth'],
+ await add_pub(db, title='Test Title2', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['hawc'])
- await add_pub(db, title='Test Title3', authors=['auth'],
+ await add_pub(db, title='Test Title3', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube','hawc'])
@@ -102,11 +103,11 @@ async def test_multi_project(server):
async def test_hide_projects(server):
db, url = server
- await add_pub(db, title='Test Title', authors=['auth'],
+ await add_pub(db, title='Test Title', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth'],
+ await add_pub(db, title='Test Title2', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['hawc'])
@@ -124,15 +125,15 @@ async def test_hide_projects(server):
async def test_dates(server):
db, url = server
- await add_pub(db, title='Test Title1', authors=['auth'],
+ await add_pub(db, title='Test Title1', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date='2020-01-02',
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth'],
+ await add_pub(db, title='Test Title2', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date='2020-02-03',
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title3', authors=['auth'],
+ await add_pub(db, title='Test Title3', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date='2020-03-04',
downloads=[], projects=['icecube'])
@@ -160,15 +161,15 @@ async def test_dates(server):
async def test_types(server):
db, url = server
- await add_pub(db, title='Test Title1', authors=['auth'],
+ await add_pub(db, title='Test Title1', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth'],
+ await add_pub(db, title='Test Title2', authors=['auth'], abstract='',
pub_type="proceeding", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title3', authors=['auth'],
+ await add_pub(db, title='Test Title3', authors=['auth'], abstract='',
pub_type="thesis", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
@@ -193,15 +194,15 @@ async def test_types(server):
async def test_title(server):
db, url = server
- await add_pub(db, title='Test Title1', authors=['auth'],
+ await add_pub(db, title='Test Title1', authors=['auth'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth'],
+ await add_pub(db, title='Test Title2', authors=['auth'], abstract='',
pub_type="proceeding", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title3', authors=['auth'],
+ await add_pub(db, title='Test Title3', authors=['auth'], abstract='',
pub_type="thesis", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
@@ -213,15 +214,15 @@ async def test_title(server):
async def test_authors(server):
db, url = server
- await add_pub(db, title='Test Title1', authors=['auth1'],
+ await add_pub(db, title='Test Title1', authors=['auth1'], abstract='',
pub_type="journal", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title2', authors=['auth2'],
+ await add_pub(db, title='Test Title2', authors=['auth2'], abstract='',
pub_type="proceeding", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
- await add_pub(db, title='Test Title3', authors=['auth1', 'auth3'],
+ await add_pub(db, title='Test Title3', authors=['auth1', 'auth3'], abstract='',
pub_type="thesis", citation="TestJournal", date=nowstr(),
downloads=[], projects=['icecube'])
diff --git a/tests/test_util.py b/tests/test_util.py
index 7af16f5..824907a 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -1,6 +1,6 @@
import asyncio
-from rest_tools.server import from_environment
+from wipac_dev_tools import from_environment
import pytest
from bson.objectid import ObjectId
@@ -41,13 +41,14 @@ async def test_add_pub(mocker, sites):
'authors': ['auth1', 'auth2'],
'type': 'journal',
'citation': 'citation',
+ 'abstract': '',
'date': '2020-11-03T00:00:00',
'downloads': ['down1', 'down2'],
'projects': ['icecube', 'hawc'],
'sites': sites if sites else []
}
await pubs.utils.add_pub(db, title=args['title'], authors=args['authors'], pub_type=args['type'],
- citation=args['citation'], date=args['date'], downloads=args['downloads'],
+ abstract=args['abstract'], citation=args['citation'], date=args['date'], downloads=args['downloads'],
projects=args['projects'], sites=sites)
db.publications.insert_one.assert_called_once_with(args)
@@ -55,29 +56,31 @@ async def test_add_pub(mocker, sites):
@pytest.mark.parametrize('title', ['title', 123])
@pytest.mark.parametrize('authors', [['auth1', 'auth2'], [12], 'author'])
@pytest.mark.parametrize('pub_type', ['journal', 'foo', 12])
+@pytest.mark.parametrize('abstract', [12])
@pytest.mark.parametrize('citation', ['citation', 12])
@pytest.mark.parametrize('date', ['2020-11-03T00:00:00', '2020-1111', 2020])
@pytest.mark.parametrize('downloads', [['down1', 'down2'], [12], 'down'])
@pytest.mark.parametrize('projects', [['icecube','hawc'], [12], 12])
@pytest.mark.parametrize('sites', [[12], 12])
@pytest.mark.asyncio
-async def test_add_pub_err(mocker, title, authors, pub_type, citation, date, downloads, projects, sites):
+async def test_add_pub_err(mocker, title, authors, pub_type, abstract, citation, date, downloads, projects, sites):
db = mocker.AsyncMock()
with pytest.raises(Exception):
- await pubs.utils.add_pub(db, title=title, authors=authors, pub_type=pub_type,
+ await pubs.utils.add_pub(db, title=title, authors=authors, pub_type=pub_type, abstract=abstract,
citation=citation, date=date, downloads=downloads, projects=projects, sites=sites)
@pytest.mark.parametrize('title', ['title', None])
@pytest.mark.parametrize('authors', [['auth1', 'auth2'], None])
@pytest.mark.parametrize('pub_type', ['journal', None])
+@pytest.mark.parametrize('abstract', ['This is an abstract', '', None])
@pytest.mark.parametrize('citation', ['citation', None])
@pytest.mark.parametrize('date', ['2020-11-03T00:00:00', None])
@pytest.mark.parametrize('downloads', [['down1', 'down2'], None])
@pytest.mark.parametrize('projects', [['icecube','hawc'], None])
@pytest.mark.parametrize('sites', [['icecube', 'wipac'], None])
@pytest.mark.asyncio
-async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downloads, projects, sites):
+async def test_edit_pub(mocker, title, authors, pub_type, abstract, citation, date, downloads, projects, sites):
mongo_id = ObjectId()
args = {}
if title:
@@ -86,6 +89,8 @@ async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downlo
args['authors'] = authors
if pub_type:
args['type'] = pub_type
+ if abstract:
+ args['abstract'] = abstract
if citation:
args['citation'] = citation
if date:
@@ -98,7 +103,7 @@ async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downlo
args['sites'] = sites
db = mocker.AsyncMock()
- await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type,
+ await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type, abstract=abstract,
citation=citation, date=date, downloads=downloads, projects=projects, sites=sites)
db.publications.update_one.assert_called_once_with({'_id': mongo_id}, {'$set': args})
@@ -106,18 +111,19 @@ async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downlo
@pytest.mark.parametrize('title', [123, None])
@pytest.mark.parametrize('authors', [[12], 'author', None])
@pytest.mark.parametrize('pub_type', ['foo', 12, None])
+@pytest.mark.parametrize('abstract', [12, None])
@pytest.mark.parametrize('citation', [12, None])
@pytest.mark.parametrize('date', ['2020-1111', 2020, None])
@pytest.mark.parametrize('downloads', [[12], 'down', None])
@pytest.mark.parametrize('projects', [[12], 12, None])
@pytest.mark.parametrize('sites', [[12], 12])
@pytest.mark.asyncio
-async def test_edit_pub_err(mocker, title, authors, pub_type, citation, date, downloads, projects, sites):
+async def test_edit_pub_err(mocker, title, authors, pub_type, abstract, citation, date, downloads, projects, sites):
mongo_id = ObjectId()
db = mocker.AsyncMock()
with pytest.raises(Exception):
- await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type,
+ await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type, abstract=abstract,
citation=citation, date=date, downloads=downloads, projects=projects, sites=sites)
@pytest.mark.asyncio
@@ -131,12 +137,20 @@ async def test_import_file_json(mocker):
"date":"2020-11-03T00:00:00","downloads":["baz"],"projects":["icecube"],"sites":["icecube","wipac"]}]'''
await pubs.utils.try_import_file(db, json_data)
+ json_data = '''[{"title":"foo","authors":["bar"],"type":"journal","citation":"cite","abstract":"This is an abstract",
+"date":"2020-11-03T00:00:00","downloads":["baz"],"projects":["icecube"],"sites":["icecube","wipac"]}]'''
+ await pubs.utils.try_import_file(db, json_data)
+
@pytest.mark.asyncio
async def test_import_file_csv(mocker):
db = mocker.AsyncMock()
csv_data = '''title,authors,type,citation,date,downloads,projects,sites
foo,bar,journal,cite,2020-11-03T00:00:00,baz,icecube,"icecube,wipac"'''
await pubs.utils.try_import_file(db, csv_data)
+
+ csv_data = '''title,authors,type,abstract,citation,date,downloads,projects,sites
+foo,bar,journal,"this is an abstract",cite,2020-11-03T00:00:00,baz,icecube,"icecube,wipac"'''
+ await pubs.utils.try_import_file(db, csv_data)
@pytest.mark.asyncio
async def test_import_file_csv_authors(mocker):
diff --git a/tests/util.py b/tests/util.py
index 1b5aaf3..72f30a6 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -4,7 +4,8 @@
import os
import pytest
-from rest_tools.server import from_environment
+import pytest_asyncio
+from wipac_dev_tools import from_environment
import motor.motor_asyncio
from pubs.server import create_server
@@ -21,7 +22,7 @@ def port():
s.close()
return ephemeral_port
-@pytest.fixture
+@pytest_asyncio.fixture
async def mongo_client(monkeypatch):
if 'DB_URL' not in os.environ:
monkeypatch.setenv('DB_URL', 'mongodb://localhost/pub_db_test')
@@ -41,12 +42,12 @@ async def mongo_client(monkeypatch):
finally:
await ret.publications.drop()
-@pytest.fixture
+@pytest_asyncio.fixture
async def server(monkeypatch, port, mongo_client):
monkeypatch.setenv('DEBUG', 'True')
monkeypatch.setenv('PORT', str(port))
s = create_server()
- yield mongo_client, f'http://localhost:{port}'
+ yield (mongo_client, f'http://localhost:{port}')
await s.stop()