-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_forms_application_processors_public.py
123 lines (88 loc) · 4.39 KB
/
test_forms_application_processors_public.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
from werkzeug.datastructures import MultiDict
from wtforms import Form, StringField, validators
from portality import constants
from doajtest.helpers import DoajTestCase
from portality import models, core
from portality.lib.formulaic import FormProcessor
from portality.forms.application_forms import ApplicationFormFactory
from portality.forms.application_processors import NewApplication
from doajtest.fixtures.v2.journals import JournalFixtureFactory
from doajtest.fixtures.v2.applications import ApplicationFixtureFactory
#####################################################################
# Source objects to be used for testing
#####################################################################
JOURNAL_SOURCE = JournalFixtureFactory.make_journal_source(in_doaj=True)
APPLICATION_SOURCE = ApplicationFixtureFactory.make_application_source()
APPLICATION_FORM = ApplicationFixtureFactory.make_application_form()
######################################################
# Extensions of base form context classes for use in
# testing
######################################################
TEST_SOURCE = {"one" : "one", "two" : "two"}
TEST_SOURCE2 = {"one" : "three", "two" : "four"}
class FailValidation(object):
def __init__(self, *args, **kwargs):
pass
def __call__(self, form, field):
raise validators.ValidationError("validation failed")
######################################################
# Main test class
######################################################
class TestPublicApplicationProcessorPublic(DoajTestCase):
def setUp(self):
super(TestPublicApplicationProcessorPublic, self).setUp()
def tearDown(self):
super(TestPublicApplicationProcessorPublic, self).tearDown()
###########################################################
# Tests on the public application form in detail
# (other form contexts will get their own files)
###########################################################
def test_07_public_init(self):
"""Test that we can build the most basic kind of form in its initial condition - a blank form"""
# make ourselves a form context from the source
fc = ApplicationFormFactory.context("public")
processor = fc.processor()
# first check that we got the kind of object we expected
assert isinstance(processor, NewApplication)
# we should have populated the source and form aspects of the object
assert processor.form_data is None
assert processor.source is None
assert processor.form is not None
def test_08_public_from_formdata(self):
"""Test that we can build the most basic kind of form from form data"""
formdata = MultiDict(APPLICATION_FORM)
fc = ApplicationFormFactory.context("public")
processor = fc.processor(formdata=formdata)
# first check that we got the kind of object we expected
assert isinstance(processor, NewApplication)
# we should have populated the form_data and form aspects of the object
assert processor.form_data is not None
assert processor.form is not None
assert processor.source is None
def test_09_public_form_workflow(self):
"""Test that the active functions on the public application form work"""
old_enable_email = core.app.config.get('ENABLE_EMAIL')
core.app.config['ENABLE_EMAIL'] = False
account = models.Account()
account.set_name("Test Account")
account.set_email("account@example.com")
account.save(blocking=True)
# create our form from the data
formdata = MultiDict(APPLICATION_FORM)
fc = ApplicationFormFactory.context("public")
processor = fc.processor(formdata=formdata)
# pre validate (should do nothing)
processor.pre_validate()
processor.validate()
# crosswalk
processor.form2target()
assert processor.target is not None
# patch the target (should do nothing)
processor.patch_target()
# now, finalise (which will run all the above stuff again)
processor.finalise(account)
assert processor.target is not None
assert processor.target.application_status == constants.APPLICATION_STATUS_PENDING
assert processor.target.date_applied is not None
assert processor.target.owner == account.id
core.app.config['ENABLE_EMAIL'] = old_enable_email