-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_snapshot.py
77 lines (61 loc) · 2.73 KB
/
test_snapshot.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
import json
from doajtest.helpers import DoajTestCase, patch_history_dir
from portality import models
class TestSnapshot(DoajTestCase):
def setUp(self):
super(TestSnapshot, self).setUp()
def tearDown(self):
super(TestSnapshot, self).tearDown()
# snapshotting creates files in the history folder, but these
# are cleaned up in the parent DoajTestCase class so they
# don't have to be cleaned up in each test suite that causes .snapshot()
@patch_history_dir("ARTICLE_HISTORY_DIR")
def test_01_snapshot(self):
# make ourselves an example article
a = models.Article()
b = a.bibjson()
b.title = "Example article with a fulltext url"
b.add_url("http://examplejournal.telfor.rs/Published/Vol1No1/Vol1No1_A5.pdf", urltype="fulltext")
a.save()
# snapshot it
a.snapshot()
hist_files = self.list_today_article_history_files()
assert len(hist_files) == 1
with open(hist_files[0], 'r', encoding="utf-8") as i:
hist = json.loads(i.read())
assert hist
assert hist.get("bibjson", {}).get("title") == "Example article with a fulltext url"
@patch_history_dir("ARTICLE_HISTORY_DIR")
def test_02_merge(self):
# make ourselves an example article
a = models.Article()
b = a.bibjson()
b.title = "Example 2 article with a fulltext url"
b.add_url("http://examplejournal.telfor.rs/Published/Vol1No1/Vol1No1_A5.pdf", urltype="fulltext")
a.save()
# create a replacement article
z = models.Article()
y = z.bibjson()
y.title = "Replacement article for fulltext url"
y.add_url("http://examplejournal.telfor.rs/Published/Vol1No1/Vol1No1_A5.pdf", urltype="fulltext")
# do a merge
z.merge(a)
history_files = self.list_today_article_history_files()
assert len(history_files) == 1
with open(history_files[0], 'r', encoding="utf-8") as i:
hist = json.loads(i.read())
assert hist
assert hist.get("bibjson", {}).get("title") == "Example 2 article with a fulltext url"
@patch_history_dir('JOURNAL_HISTORY_DIR')
def test_03_snapshot_journal(self):
# make ourselves an example journal
j = models.Journal()
b = j.bibjson()
b.title = "Example journal"
# the snapshot is part of the save method
j.save(blocking=True)
history_files = self.list_today_journal_history_files()
assert len(history_files) == 1
with open(history_files[0], 'r', encoding="utf-8") as i:
hist = json.loads(i.read())
assert hist.get("bibjson", {}).get("title") == "Example journal"