SciPost Code Repository

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

add additional tests for DOIToQueryForm

parent b96b90b8
No related branches found
No related tags found
No related merge requests found
......@@ -9,21 +9,21 @@ from .models import Commentary
from scipost.models import Contributor
# class DOIToQueryForm(forms.Form):
# doi = forms.CharField(widget=forms.TextInput(
# {'label': 'DOI', 'placeholder': 'ex.: 10.21468/00.000.000000'}))
class DOIToQueryForm(forms.Form):
doi = forms.CharField(widget=forms.TextInput(
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'}))
# 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
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):
......
......@@ -14,12 +14,6 @@ from common.helpers.test import add_groups_and_permissions
class TestDOIToQueryForm(TestCase):
def setUp(self):
add_groups_and_permissions()
doi_string = "10.21468/SciPostPhys.2.2.010"
self.valid_form_data = {'doi': doi_string}
def test_valid_doi_is_valid(self):
form = DOIToQueryForm(self.valid_form_data)
self.assertTrue(form.is_valid())
def test_invalid_doi_is_invalid(self):
invalid_data = {'doi': 'blablab'}
......@@ -34,6 +28,21 @@ class TestDOIToQueryForm(TestCase):
error_message = form.errors['doi'][0]
self.assertRegexpMatches(error_message, re.compile('already exist'))
def test_physrev_doi_is_valid(self):
physrev_doi = "10.21468/SciPostPhys.2.2.010"
form = DOIToQueryForm({'doi': physrev_doi})
self.assertTrue(form.is_valid())
def test_scipost_doi_is_valid(self):
scipost_doi = "10.21468/SciPostPhys.2.2.010"
form = DOIToQueryForm({'doi': scipost_doi})
self.assertTrue(form.is_valid())
def test_old_doi_is_valid(self):
old_doi = "10.1088/0022-3719/7/6/005"
form = DOIToQueryForm({'doi': old_doi})
self.assertTrue(form.is_valid())
class TestVetCommentaryForm(TestCase):
def setUp(self):
......
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