forked from cos-archives/osf-ui-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration_tests.py
251 lines (193 loc) · 7.86 KB
/
registration_tests.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import datetime as dt
import unittest
from pages import helpers
class RegistrationTests(unittest.TestCase):
"""This test case is for testing the act of creating a registration, and
consistency between a registration and its original node.
"""
def _project(self):
""" Create and return a top-level project.
The ``current_url`` of the driver is the project's overview.
"""
return helpers.get_new_project('New Project')
def _subproject(self):
""" Create and return a project which is the child of a project.
The ``current_url`` of the driver is the project's overview.
"""
return self._project().add_component(
title='New Subproject',
component_type='Project',
)
def _test_registration_list(self, page):
""" Given a project, register it and verify that the new registration is
in the project's registration list
"""
_url = page.driver.current_url
page = page.add_registration(
registration_type='Open-Ended Registration',
meta=('sample narrative', )
)
page.driver.get(_url)
self.assertEqual(len(page.registrations), 1)
r = page.registrations
page.close()
return r
def test_project_registration_listed(self):
""" After registering a project, the registration should be listed in
the project's Registrations pane. """
registrations = self._test_registration_list(page=self._project())
self.assertEqual(len(registrations), 1)
def test_subproject_registration_listed(self):
""" Subproject variant of ``self.test_project_registration_listed`` """
registrations = self._test_registration_list(page=self._subproject())
self.assertEqual(len(registrations), 1)
def _test_registration_list_title(self, page):
""" Given a project, register it and verify that that registration in
the project's registration list has the correct title.
"""
title = page.title
registrations = self._test_registration_list(page)
self.assertEqual(
registrations[0].title,
title
)
def test_project_registration_list_title(self):
""" Project variant of ``self._test_registration_list_title``
"""
self._test_registration_list_title(self._project())
def test_subproject_registration_list_title(self):
""" Subproject variant of ``self._test_registration_list_title``
"""
self._test_registration_list_title(self._subproject())
def _test_registration_list_date(self, page):
""" Given a project, register it and verify that the registration in
the project's registration list has the correct date.
"""
date_created = page.date_created
registrations = self._test_registration_list(page)
self.assertAlmostEqual(
registrations[0].date,
date_created,
delta=dt.timedelta(minutes=2)
)
def test_project_registration_list_date(self):
""" Project variant of ``self._test_registration_list_date`` """
self._test_registration_list_date(self._project())
def test_subproject_registration_list_date(self):
""" Subproject variant of ``self._test_registration_list_date``
"""
self._test_registration_list_date(self._subproject())
def _test_registration_matches(self, page, attribute):
""" Given a project, register it and verify that the attribute provided
matches between the project and its registration.
Note that the value of the project's attribute is stored before the
project is registered, as the act of registration may otherwise change
the state - for example, the registration of a project should include
its log *before* the project was registered, while the project's log
should immediately be updated to include the creation of the
registration.
"""
parent_value = getattr(page, attribute)
page = page.add_registration(
registration_type='Open-Ended Registration',
meta=('sample narrative', )
)
self.assertEqual(
getattr(page, attribute),
parent_value,
)
page.close()
# NOTE: This test only applies to subprojects
def test_subproject_registration_parent_title(self):
""" Verify that a registration's parent project title matches the
original project """
# As of 9 Sep 2013, registrations of subprojects do not preserve the
# parent project in the header.
self._test_registration_matches(
page=self._subproject(),
attribute='parent_title'
)
def test_project_registration_components(self):
""" Verify that a registration's (non-empty) component list matches the
original project """
page = self._project()
# add component
page = page.add_component(
title='Test Component',
component_type='Other',
)
page = page.parent_project()
# add a subproject
page = page.add_component(
title='Test Subproject',
component_type='Project',
)
page = page.parent_project()
self._test_registration_matches(
page=page,
attribute='component_names'
)
def test_subproject_registration_components(self):
""" Subproject variant of ``self._test_project_registration_components``
"""
page = self._project()
page = page.add_component(
title='Subproject',
component_type='Project',
)
# add component
page = page.add_component(
title='Test Component',
component_type='Other',
)
page = page.parent_project()
self._test_registration_matches(
page=page,
attribute='component_names'
)
def test_project_registration_wiki_home(self):
""" Verify that a registration's wiki homepage content matches the
original project """
page = self._project()
page.set_wiki_content('Test wiki content!')
self._test_registration_matches(
page=page,
attribute='wiki_home_content'
)
def test_subproject_registration_wiki_home(self):
""" Subproject variant of ``self._test_project_registration_wiki_home``
"""
page = self._subproject()
page.set_wiki_content('Test wiki content!')
self._test_registration_matches(
page=page,
attribute='wiki_home_content'
)
def _test_registration_logged(self, page):
""" Given a project, register it and verify that the action appears in
the original project's logs.
"""
user = page.contributors[0].full_name
_url = page.driver.current_url
page = page.add_registration(
registration_type='Open-Ended Registration',
meta=('test narrative', )
)
page.driver.get(_url)
self.assertEqual(
page.logs[0].text,
u'{user} registered project {title}'.format(
user=user,
title=page.title
)
)
page.close()
def test_project_registration_logged(self):
""" Project variant of ``self._test_registration_logged`` """
# As of 9 Sep 2013, the log reads "component" here instead of "project"
self._test_registration_logged(self._project())
def test_subproject_registration_logged(self):
""" Subproject variant of ``self._test_registration_logged`` """
# TODO: This fails right now because a subproject is referred to as a
# "node" in the log.
self._test_registration_logged(self._subproject())