SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
44662f35
Commit
44662f35
authored
7 years ago
by
Geert Kapteijns
Browse files
Options
Downloads
Patches
Plain Diff
add additional tests for DOIToQueryForm
parent
b96b90b8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
commentaries/forms.py
+12
-12
12 additions, 12 deletions
commentaries/forms.py
commentaries/test_forms.py
+15
-6
15 additions, 6 deletions
commentaries/test_forms.py
with
27 additions
and
18 deletions
commentaries/forms.py
+
12
−
12
View file @
44662f35
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
commentaries/test_forms.py
+
15
−
6
View file @
44662f35
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment