-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_upgrade.py
79 lines (56 loc) · 2.2 KB
/
test_upgrade.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
import json
import time
import re
from collections import OrderedDict
from doajtest.helpers import DoajTestCase
from portality import models
from portality.upgrade import do_upgrade
from portality.lib.paths import rel2abs
def operation(journal):
j = models.Journal.pull(journal.id)
bj = j.bibjson()
bj.title = "Updated Title"
j.save()
return j
class TestUpgrade(DoajTestCase):
def test_upgrade(self):
# populate the index with some journals with title
saved_journals = {}
for i in range(5):
j = models.Journal()
j.set_in_doaj(True)
bj = j.bibjson()
bj.title = "Test Journal"
bj.add_identifier(bj.P_ISSN, "{x}000-0000".format(x=i))
bj.publisher = "Test Publisher {x}".format(x=i)
bj.add_url("http://homepage.com/{x}".format(x=i), "homepage")
j.save()
saved_journals[j.id] = j.last_updated
# and with some journals without title
for i in range(5):
j = models.Journal()
j.set_in_doaj(True)
bj = j.bibjson()
bj.add_identifier(bj.P_ISSN, "{x}000-0001".format(x=i))
bj.title = "Journal to Change"
bj.publisher = "Test Publisher {x}".format(x=i)
bj.add_url("http://homepage.com/{x}".format(x=i), "homepage")
j.save()
saved_journals[j.id] = j.last_updated
# make sure the last updated dates will be suitably different after migration
time.sleep(1.5)
path =rel2abs(__file__, ".", "resources", "migrate.json")
with open(path) as f:
instructions = json.loads(f.read(), object_pairs_hook=OrderedDict)
do_upgrade(instructions,None)
p = re.compile('[0-4]000-0001')
for id in saved_journals:
j = models.Journal.pull(id)
bj = j.bibjson()
pissn = bj.get_one_identifier(bj.P_ISSN)
if not p.match(pissn):
assert bj.title == "Test Journal"
assert j.last_updated == saved_journals[j.id]
else:
assert bj.title == "Updated Title"
assert not j.last_updated == saved_journals[j.id]