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
55cac3bd
Commit
55cac3bd
authored
7 years ago
by
Geert Kapteijns
Browse files
Options
Downloads
Patches
Plain Diff
add tests for DOICaller
parent
44662f35
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scipost/services.py
+20
-19
20 additions, 19 deletions
scipost/services.py
scipost/test_services.py
+24
-6
24 additions, 6 deletions
scipost/test_services.py
with
44 additions
and
25 deletions
scipost/services.py
+
20
−
19
View file @
55cac3bd
...
...
@@ -2,6 +2,7 @@
import
feedparser
import
requests
import
re
import
datetime
from
django.template
import
Template
,
Context
from
.behaviors
import
ArxivCallable
...
...
@@ -26,8 +27,16 @@ class DOICaller:
journal
=
data
[
'
container-title
'
][
0
]
volume
=
data
.
get
(
'
volume
'
,
''
)
pages
=
self
.
_get_pages
(
data
)
pub_dat
a
=
self
.
_get_pub_date
(
data
)
pub_dat
e
=
self
.
_get_pub_date
(
data
)
self
.
data
=
{
'
pub_title
'
:
pub_title
,
'
authorlist
'
:
authorlist
,
'
journal
'
:
journal
,
'
volume
'
:
volume
,
'
pages
'
:
pages
,
'
pub_date
'
:
pub_date
,
}
def
_get_pages
(
self
,
data
):
# For Physical Review
...
...
@@ -37,25 +46,17 @@ class DOICaller:
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
date_parts
=
data
.
get
(
'
issued
'
,
{}).
get
(
'
date-parts
'
,
{})
if
date_parts
:
date_parts
=
date_parts
[
0
]
year
=
date_parts
[
0
]
month
=
date_parts
[
1
]
day
=
date_parts
[
2
]
pub_date
=
datetime
.
date
(
year
,
month
,
day
).
isoformat
()
else
:
pub_date
=
''
return
pub_date
...
...
This diff is collapsed.
Click to expand it.
scipost/test_services.py
+
24
−
6
View file @
55cac3bd
...
...
@@ -47,9 +47,27 @@ class ArxivCallerTest(TestCase):
class
DOICallerTest
(
TestCase
):
def
setUp
(
self
):
self
.
doi_string
=
'
10.1103/PhysRevB.92.214427
'
self
.
caller
=
DOICaller
(
self
.
doi_string
)
def
test_collects_data
(
self
):
print
(
self
.
caller
.
crossref_data
)
def
test_works_for_physrev_doi
(
self
):
caller
=
DOICaller
(
'
10.1103/PhysRevB.92.214427
'
)
correct_data
=
{
'
pub_date
'
:
'
2015-12-18
'
,
'
journal
'
:
'
Physical Review B
'
,
'
pages
'
:
''
,
'
authorlist
'
:
[
'
R. Vlijm
'
,
'
M. Ganahl
'
,
'
D. Fioretto
'
,
'
M. Brockmann
'
,
'
M. Haque
'
,
'
H. G. Evertz
'
,
'
J.-S. Caux
'
],
'
volume
'
:
'
92
'
,
'
pub_title
'
:
'
Quasi-soliton scattering in quantum spin chains
'
}
self
.
assertEqual
(
caller
.
data
,
correct_data
)
def
test_works_for_scipost_doi
(
self
):
caller
=
DOICaller
(
'
10.21468/SciPostPhys.2.2.012
'
)
correct_data
=
{
'
pub_date
'
:
'
2017-04-04
'
,
'
journal
'
:
'
SciPost Physics
'
,
'
pub_title
'
:
'
One-particle density matrix of trapped one-dimensional impenetrable bosons from conformal invariance
'
,
'
pages
'
:
''
,
'
volume
'
:
'
2
'
,
'
authorlist
'
:
[
'
Yannis Brun
'
,
'
Jerome Dubail
'
]
}
self
.
assertEqual
(
caller
.
data
,
correct_data
)
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