SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit b96b90b8 authored by Geert Kapteijns's avatar Geert Kapteijns
Browse files

preliminary test for request commentary view

parent 843484e3
No related branches found
No related tags found
No related merge requests found
......@@ -10,16 +10,20 @@ from scipost.models import Contributor
class DOIToQueryForm(forms.Form):
VALID_DOI_REGEXP = r'^(?i)10.\d{4,9}/[-._;()/:A-Z0-9]+$'
doi = forms.RegexField(regex=VALID_DOI_REGEXP, strip=False, widget=forms.TextInput(
doi = forms.CharField(widget=forms.TextInput(
{'label': 'DOI', 'placeholder': 'ex.: 10.21468/00.000.000000'}))
def clean_doi(self):
input_doi = self.cleaned_data['doi']
if Commentary.objects.filter(pub_DOI=input_doi).exists():
error_message = 'There already exists a Commentary Page on this publication.'
raise forms.ValidationError(error_message)
return input_doi
# class DOIToQueryForm(forms.Form):
# VALID_DOI_REGEXP = r'^(?i)10.\d{4,9}/[-._;()/:A-Z0-9]+$'
# doi = forms.RegexField(regex=VALID_DOI_REGEXP, strip=False, widget=forms.TextInput(
# {'label': 'DOI', 'placeholder': 'ex.: 10.21468/00.000.000000'}))
#
# def clean_doi(self):
# input_doi = self.cleaned_data['doi']
# if Commentary.objects.filter(pub_DOI=input_doi).exists():
# error_message = 'There already exists a Commentary Page on this publication.'
# raise forms.ValidationError(error_message)
# return input_doi
class IdentifierToQueryForm(forms.Form):
......
......@@ -7,7 +7,7 @@ from scipost.factories import ContributorFactory, UserFactory
from .factories import UnvettedCommentaryFactory, VettedCommentaryFactory, UnpublishedVettedCommentaryFactory
from .forms import CommentarySearchForm
from .models import Commentary
from .views import RequestCommentary
from .views import RequestCommentary, prefill_using_DOI
from common.helpers.test import add_groups_and_permissions
......@@ -35,6 +35,21 @@ class RequestCommentaryTest(TestCase):
raise NotImplementedError
class PrefillUsingDOITest(TestCase):
def setUp(self):
add_groups_and_permissions()
self.target = reverse('commentaries:prefill_using_DOI')
self.physrev_doi = '10.1103/PhysRevB.92.214427'
def test_submit_valid_physrev_doi(self):
post_data = {'doi': self.physrev_doi}
request = RequestFactory().post(self.target, post_data)
request.user = UserFactory()
response = prefill_using_DOI(request)
self.assertRedirects(response, reverse('commentaries:request_commentary'))
class VetCommentaryRequestsTest(TestCase):
"""Test cases for `vet_commentary_requests` view method"""
......
......@@ -17,10 +17,45 @@ class DOICaller:
def _call_crosslink(self):
url = 'http://api.crossref.org/works/%s' % self.doi_string
self.crossref_data = requests.get(url).json()
self.crossref_data = requests.get(url).json()['message']
def _format_data(self):
data = self.crossref_data
pub_title = data['title'][0]
authorlist = ['{} {}'.format(author['given'], author['family']) for author in data['author']]
journal = data['container-title'][0]
volume = data.get('volume', '')
pages = self._get_pages(data)
pub_data = self._get_pub_date(data)
def _get_pages(self, data):
# For Physical Review
pages = data.get('article-number', '')
# For other journals?
pages = data.get('page', '')
return pages
def _get_pub_date(self, data):
date_parts = data.get('issued', {}).get('date_parts', {})
date_parts = data['issued']['date-parts'][0]
year = date_parts[0]
month = date_parts[1]
day = date_parts[2]
pub_date = "{}-{}-{}".format(year, month, day)
pub_date = ''
try:
pub_date = (str(data['message']['issued']['date-parts'][0][0]) + '-' +
str(data['message']['issued']['date-parts'][0][1]))
try:
pub_date += '-' + str(
data['message']['issued']['date-parts'][0][2])
except (IndexError, KeyError):
pass
except (IndexError, KeyError):
pass
def _collect_data(self):
# read out json here.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment