-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_update_article.py
194 lines (153 loc) · 9.17 KB
/
test_update_article.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from doajtest.fixtures import JournalFixtureFactory, ArticleFixtureFactory
from doajtest.helpers import DoajTestCase
from portality.bll.exceptions import DuplicateArticleException, ArticleMergeConflict
from portality.models import Account, Article, Journal
from portality.bll.services.article import ArticleService
class TestCreateOrUpdateArticle(DoajTestCase):
# these tests check only scenario with admin account - publisher is not able to call create_article with update_article_id not None
# update_article_id is not None only when create_article is called from admin metadata form
def setUp(self):
super(TestCreateOrUpdateArticle, self).setUp()
self.publisher = Account()
self.publisher.add_role("publisher")
self.publisher.save(blocking=True)
self.admin = Account()
self.admin.add_role("admin")
self.admin.save(blocking=True)
sources = JournalFixtureFactory.make_many_journal_sources(2, True)
self.journal1 = Journal(**sources[0])
self.journal1.set_owner(self.publisher.id)
jbib1 = self.journal1.bibjson()
jbib1.add_identifier(jbib1.P_ISSN, "1111-1111")
jbib1.add_identifier(jbib1.E_ISSN, "2222-2222")
self.journal1.save(blocking=True)
self.publisher.add_journal(self.journal1)
self.journal2 = Journal(**sources[1])
jbib2 = self.journal2.bibjson()
jbib2.add_identifier(jbib2.P_ISSN, "1234-5678")
jbib2.add_identifier(jbib2.E_ISSN, "9876-5432")
self.journal2.save(blocking=True)
self.article10 = Article(
**ArticleFixtureFactory.make_article_source(pissn="1111-1111", eissn="2222-2222", doi="10.0000/article-10",
fulltext="https://www.article10.com"))
self.article10.set_id("articleid10")
self.article10.save(blocking=True)
self.article11 = Article(
**ArticleFixtureFactory.make_article_source(pissn="1111-1111", eissn="2222-2222", doi="10.0000/article-11",
fulltext="https://www.article11.com"))
self.article11.set_id("articleid11")
self.article11.save(blocking=True)
self.article2 = Article(
**ArticleFixtureFactory.make_article_source(pissn="1234-5678", eissn="9876-5432", doi="10.0000/article-2",
fulltext="https://www.article2.com"))
self.article2.set_id("articleid2")
self.article2.save(blocking=True)
def tearDown(self):
super(TestCreateOrUpdateArticle, self).tearDown()
def test_00_no_doi_and_url_changed(self):
ba = self.article10.bibjson()
ba.title = "Updated Article"
# try for admin
resp = ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
assert resp["success"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["update"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["new"] == 0, "expected 1 updated, received: {}".format(resp)
a = Article.pull(self.article10.id)
assert a.bibjson().title == "Updated Article", "Expected `Updated Article`, received: {}" \
.format(a.bibjson().title)
def test_01_new_doi_new_url(self):
ba = self.article10.bibjson()
ba.remove_identifiers(ba.DOI)
ba.remove_urls(ba.FULLTEXT)
ba.add_identifier(ba.DOI, "10.0000/NEW")
ba.add_url("https://www.UPDATED.com", ba.FULLTEXT)
resp = ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
assert resp["success"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["update"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["new"] == 0, "expected 1 updated, received: {}".format(resp)
a = Article.pull(self.article10.id)
assert a.bibjson().get_one_identifier("doi") == "10.0000/NEW", a.bibjson().get_one_identifier("doi")
assert a.bibjson().get_single_url("fulltext") == "https://www.UPDATED.com", a.bibjson().get_single_url("fulltext")
def test_02_old_doi_existing_url_admin(self):
ba = self.article10.bibjson()
ba.remove_urls(ba.FULLTEXT)
# check for url from other article owned by the same publisher
ba.add_url(self.article11.bibjson().get_single_url(ba.FULLTEXT), ba.FULLTEXT)
# try as an admin
with self.assertRaises(ArticleMergeConflict):
ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
# check for url from other article owned by someone else
ba.remove_urls(ba.FULLTEXT)
ba.add_url(self.article2.bibjson().get_single_url(ba.FULLTEXT), ba.FULLTEXT)
# try as an admin
with self.assertRaises(ArticleMergeConflict):
ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
def test_03_existing_doi_old_url_admin(self):
ba = self.article10.bibjson()
ba.remove_identifiers(ba.DOI)
# check for DOI from other article owned by the same publisher
ba.add_identifier(ba.DOI, "10.0000/article-11")
# try as an admin
with self.assertRaises(ArticleMergeConflict):
ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
ba.remove_identifiers(ba.DOI)
# check for DOI from other article owned by someone else
ba.add_identifier(ba.DOI, "10.0000/article-2")
# try as an admin
with self.assertRaises(ArticleMergeConflict):
ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
def test_04_old_doi_new_url(self):
ba = self.article10.bibjson()
ba.remove_urls(ba.FULLTEXT)
ba.add_url("https://updated.com", ba.FULLTEXT)
# try as an admin
resp = ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
assert resp["success"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["update"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["new"] == 0, "expected 1 new, received: {}".format(resp)
art = Article.pull(self.article10.id)
assert art.get_normalised_fulltext() == "//updated.com", "expected //updated.com, received: {}".format(
self.article10.get_normalised_fulltext())
def test_05_new_doi_old_url(self):
ba = self.article10.bibjson()
ba.remove_identifiers(ba.DOI)
ba.add_identifier(ba.DOI, "10.0000/article-UPDATED")
# try as an admin
resp = ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
assert resp["success"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["update"] == 1, "expected 1 updated, received: {}".format(resp)
assert resp["new"] == 0, "expected 1 updated, received: {}".format(resp)
art = Article.pull(self.article10.id)
assert art.get_normalised_doi() == "10.0000/article-UPDATED", \
"expected 10.0000/article-UPDATED, received: {}".format(
self.article10.get_normalised_doi())
def test_06_existing_doi_new_url(self):
ba = self.article10.bibjson()
ba.remove_urls(ba.FULLTEXT)
ba.add_url("https://updated.com", ba.FULLTEXT)
# check for doi from other article of the same publisher
ba.remove_identifiers(ba.DOI)
ba.add_identifier(ba.DOI, self.article11.bibjson().get_one_identifier(ba.DOI))
# try as an admin
with self.assertRaises(DuplicateArticleException):
ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)
def test_07_new_doi_existing_url(self):
ba = self.article10.bibjson()
ba.remove_urls(ba.FULLTEXT)
ba.add_url(self.article11.bibjson().get_single_url(ba.FULLTEXT), ba.FULLTEXT)
# check for doi from other article of the same publisher
ba.remove_identifiers(ba.DOI)
ba.add_identifier(ba.DOI, "10.0000/article-UPDATED")
# try as an admin
with self.assertRaises(DuplicateArticleException):
ArticleService.create_article(self=ArticleService(), account=self.admin, article=self.article10,
update_article_id=self.article10.id)