-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_readonly_journal.py
88 lines (67 loc) · 3.2 KB
/
test_readonly_journal.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
from doajtest.helpers import DoajTestCase
from portality import models
from portality.forms.application_forms import JournalFormFactory
from portality.forms.application_processors import ReadOnlyJournal
from portality import lcc
from doajtest.fixtures import JournalFixtureFactory
#####################################################################
# Mocks required to make some of the lookups work
#####################################################################
def mock_lookup_code(code):
if code == "H": return "Social Sciences"
if code == "HB1-3840": return "Economic theory. Demography"
return None
JOURNAL_SOURCE = JournalFixtureFactory.make_journal_source()
JOURNAL_FORM = JournalFixtureFactory.make_journal_form()
del JOURNAL_FORM["owner"]
del JOURNAL_FORM["editor_group"]
del JOURNAL_FORM["editor"]
######################################################
# Main test class
######################################################
class TestReadOnlyJournal(DoajTestCase):
def setUp(self):
super(TestReadOnlyJournal, self).setUp()
self.old_lookup_code = lcc.lookup_code
lcc.lookup_code = mock_lookup_code
def tearDown(self):
super(TestReadOnlyJournal, self).tearDown()
lcc.lookup_code = self.old_lookup_code
###########################################################
# Tests on the publisher's re-journal form
###########################################################
def test_01_readonly_journal_success(self):
"""Give the read-only journal form a full workout"""
# we start by constructing it from source
formulaic_context = JournalFormFactory.context("readonly")
fc = formulaic_context.processor(source=models.Journal(**JOURNAL_SOURCE))
assert isinstance(fc, ReadOnlyJournal)
assert fc.form is not None
assert fc.source is not None
assert fc.form_data is None
# now construct it from form data (with a known source)
journal_obj = models.Journal(**JOURNAL_SOURCE)
journal_bibjson_obj = journal_obj.bibjson()
fc = formulaic_context.processor(
formdata=JOURNAL_FORM,
source=journal_obj
)
assert isinstance(fc, ReadOnlyJournal)
assert fc.form is not None
assert fc.source is not None
assert fc.form_data is not None
# see that form has the correct info from an object (after all, that's the only point of having the form)
assert fc.form.title.data == journal_bibjson_obj.title
assert fc.form.pissn.data == journal_bibjson_obj.pissn
assert fc.form.eissn.data == journal_bibjson_obj.eissn
# test each of the workflow components individually ...
# run the validation
assert fc.validate(), fc.form.errors
# run the crosswalk (no need to look in detail, xwalks are tested elsewhere)
fc.form2target()
assert fc.target is None # can't edit data using this form
# patch the target with data from the source
fc.patch_target()
assert fc.target is None # can't edit data using this form
# shouldn't be able to finalise, can't edit data using this form
self.assertRaises(Exception, fc.finalise)