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
35aba111
Commit
35aba111
authored
7 years ago
by
Geert Kapteijns
Browse files
Options
Downloads
Patches
Plain Diff
move checks for existing commentary and bad request to ArxivQueryForm
parent
47ffc28f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
commentaries/forms.py
+14
-3
14 additions, 3 deletions
commentaries/forms.py
commentaries/test_forms.py
+16
-0
16 additions, 0 deletions
commentaries/test_forms.py
scipost/services.py
+6
-2
6 additions, 2 deletions
scipost/services.py
scipost/test_services.py
+1
-1
1 addition, 1 deletion
scipost/test_services.py
with
37 additions
and
6 deletions
commentaries/forms.py
+
14
−
3
View file @
35aba111
...
@@ -6,7 +6,7 @@ from django.urls import reverse
...
@@ -6,7 +6,7 @@ from django.urls import reverse
from
.models
import
Commentary
from
.models
import
Commentary
from
scipost.services
import
DOICaller
from
scipost.services
import
DOICaller
,
ArxivCaller
from
scipost.models
import
Contributor
from
scipost.models
import
Contributor
...
@@ -48,10 +48,21 @@ class ArxivQueryForm(forms.Form):
...
@@ -48,10 +48,21 @@ class ArxivQueryForm(forms.Form):
identifier
=
forms
.
RegexField
(
regex
=
VALID_ARXIV_IDENTIFIER_REGEX
,
strip
=
True
)
identifier
=
forms
.
RegexField
(
regex
=
VALID_ARXIV_IDENTIFIER_REGEX
,
strip
=
True
)
# identifierpattern_new = re.compile("^[0-9]{4,}.[0-9]{4,5}v[0-9]{1,2}$")
def
clean_identifier
(
self
):
# identifierpattern_old = re.compile("^[-.a-z]+/[0-9]{7,}v[0-9]{1,2}$")
identifier
=
self
.
cleaned_data
[
'
identifier
'
]
if
Commentary
.
objects
.
filter
(
arxiv_identifier
=
identifier
).
exists
():
error_message
=
'
There already exists a Commentary Page on this arXiv preprint.
'
raise
forms
.
ValidationError
(
error_message
)
caller
=
ArxivCaller
(
identifier
)
if
caller
.
is_valid
:
self
.
arxiv_data
=
ArxivCaller
(
identifier
).
data
else
:
error_message
=
'
Could not find a resource for that arXiv identifier.
'
raise
forms
.
ValidationError
(
error_message
)
return
identifier
# class IdentifierToQueryForm(forms.Form):
# class IdentifierToQueryForm(forms.Form):
...
...
This diff is collapsed.
Click to expand it.
commentaries/test_forms.py
+
16
−
0
View file @
35aba111
...
@@ -12,6 +12,9 @@ from common.helpers.test import add_groups_and_permissions
...
@@ -12,6 +12,9 @@ from common.helpers.test import add_groups_and_permissions
class
TestArxivQueryForm
(
TestCase
):
class
TestArxivQueryForm
(
TestCase
):
def
setUp
(
self
):
add_groups_and_permissions
()
def
test_new_arxiv_identifier_is_valid
(
self
):
def
test_new_arxiv_identifier_is_valid
(
self
):
new_identifier_data
=
{
'
identifier
'
:
'
1612.07611v1
'
}
new_identifier_data
=
{
'
identifier
'
:
'
1612.07611v1
'
}
form
=
ArxivQueryForm
(
new_identifier_data
)
form
=
ArxivQueryForm
(
new_identifier_data
)
...
@@ -37,6 +40,19 @@ class TestArxivQueryForm(TestCase):
...
@@ -37,6 +40,19 @@ class TestArxivQueryForm(TestCase):
form
=
ArxivQueryForm
(
data
)
form
=
ArxivQueryForm
(
data
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertFalse
(
form
.
is_valid
())
def
test_arxiv_identifier_that_already_has_commentary_page_is_invalid
(
self
):
unvetted_commentary
=
UnvettedCommentaryFactory
()
invalid_data
=
{
'
identifier
'
:
unvetted_commentary
.
arxiv_identifier
}
form
=
ArxivQueryForm
(
invalid_data
)
self
.
assertFalse
(
form
.
is_valid
())
error_message
=
form
.
errors
[
'
identifier
'
][
0
]
self
.
assertRegexpMatches
(
error_message
,
re
.
compile
(
'
already exist
'
))
def
test_valid_but_non_existent_identifier_is_invalid
(
self
):
invalid_data
=
{
'
identifier
'
:
'
1613.07611v1
'
}
form
=
ArxivQueryForm
(
invalid_data
)
self
.
assertFalse
(
form
.
is_valid
())
class
TestDOIToQueryForm
(
TestCase
):
class
TestDOIToQueryForm
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
This diff is collapsed.
Click to expand it.
scipost/services.py
+
6
−
2
View file @
35aba111
...
@@ -77,9 +77,10 @@ class ArxivCaller:
...
@@ -77,9 +77,10 @@ class ArxivCaller:
def
_call_arxiv
(
self
):
def
_call_arxiv
(
self
):
url
=
self
.
query_base_url
%
self
.
identifier
url
=
self
.
query_base_url
%
self
.
identifier
request
=
requests
.
get
(
url
)
request
=
requests
.
get
(
url
)
if
request
.
ok
:
arxiv_data
=
feedparser
.
parse
(
request
.
content
)[
'
entries
'
][
0
]
if
self
.
_search_result_present
(
arxiv_data
):
self
.
is_valid
=
True
self
.
is_valid
=
True
self
.
_arxiv_data
=
feedparser
.
parse
(
request
.
content
)[
'
entries
'
][
0
]
self
.
_arxiv_data
=
arxiv_data
else
:
else
:
self
.
is_valid
=
False
self
.
is_valid
=
False
...
@@ -97,6 +98,9 @@ class ArxivCaller:
...
@@ -97,6 +98,9 @@ class ArxivCaller:
'
pub_abstract
'
:
abstract
,
'
pub_abstract
'
:
abstract
,
}
}
def
_search_result_present
(
self
,
data
):
return
'
title
'
in
data
# I'm going to revamp this whole thing...
# I'm going to revamp this whole thing...
class
BaseCaller
(
object
):
class
BaseCaller
(
object
):
...
...
This diff is collapsed.
Click to expand it.
scipost/test_services.py
+
1
−
1
View file @
35aba111
...
@@ -24,7 +24,7 @@ class ArxivCallerTest(TestCase):
...
@@ -24,7 +24,7 @@ class ArxivCallerTest(TestCase):
def
valid_but_nonexistent_identifier
(
self
):
def
valid_but_nonexistent_identifier
(
self
):
caller
=
ArxivCaller
(
'
1613.07611v1
'
)
caller
=
ArxivCaller
(
'
1613.07611v1
'
)
self
.
assert
False
(
caller
.
is_valid
)
self
.
assert
Equal
(
caller
.
is_valid
,
False
)
class
DOICallerTest
(
TestCase
):
class
DOICallerTest
(
TestCase
):
...
...
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