source: main/waeup.sirp/branches/accesscodes-with-workflow/src/waeup/sirp/accesscodes/browser.txt @ 6403

Last change on this file since 6403 was 6403, checked in by Henrik Bettermann, 13 years ago

Comment out the code which refers to iold invalidation and disabling methods. Make all tests work again.

File size: 9.7 KB
Line 
1:mod:`waeup.sirp.accesscodes.browser` -- UI components for access-codes
2***********************************************************************
3
4.. module:: waeup.sirp.accesscodes.browser
5
6Here we visit the access-code related parts of a WAeUP SIRP site using
7a virtual browser.
8
9:Test-Layer: functional
10
11Preliminaries
12=============
13
14Before we can do anything, we have to create a university site:
15
16    >>> from zope.testbrowser.testing import Browser
17    >>> browser = Browser()
18    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
19    >>> browser.handleErrors = False
20    >>> root = getRootFolder()
21
22    >>> from waeup.sirp.app import University
23    >>> u = University()
24    >>> root['myuniversity'] = u
25
26We set a new datacenter storage path:
27
28  >>> import os
29  >>> browser.open('http://localhost/myuniversity')
30  >>> browser.getLink('Data Center').click()
31  >>> browser.getLink('Edit settings').click()
32  >>> pathsetting = browser.getControl(name='newpath')
33
34  >>> cwd = os.getcwd()
35  >>> uploadpath = os.path.join(cwd, 'ac_testfiles')
36  >>> os.mkdir(uploadpath)
37  >>> pathsetting.value = uploadpath
38  >>> browser.getControl(name='save').click()
39
40We remove any existing 'accesscodes' dir from datacenter dir:
41
42  >>> import shutil
43  >>> if os.path.exists(os.path.join(uploadpath, 'accesscodes')):
44  ...   shutil.rmtree(os.path.join(uploadpath, 'accesscodes'))
45
46
47Access-code management screen
48=============================
49
50For users that have the right to manage access-code related stuff, the
51home page of a `University` instance provides a link to the
52access-code management screen. In the beginning, there are naturally
53no batches available:
54
55    >>> browser.open('http://localhost/myuniversity')
56    >>> browser.getLink('Access Codes').click()
57    >>> print browser.contents
58    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
59    ...
60    <h2>Access Code Batches</h2>
61    ...
62    ... The following batches are available:
63    ...No batches yet...
64    ...
65
66Adding batches
67==============
68
69We can add a batch of access-codes using a button displayed in the
70action bar:
71
72    >>> browser.getLink('Add Scratch Card Batch').click()
73
74The add screen shows a form where we have to enter a prefix, the
75number of access codes to be generated and the costs for each card.
76
77    >>> browser.getControl(name='form.batch_prefix').value = 'APP'
78    >>> browser.getControl(name='form.entry_num').value = '5'
79    >>> browser.getControl(name='form.cost').value = '12.12'
80
81If we click 'cancel' afterwards, the whole process will be cancelled
82and we'll be redirected to the management screen:
83
84    >>> browser.getControl('Cancel').click()
85    >>> browser.url
86    'http://localhost/myuniversity/accesscodes'
87
88    >>> 'Batch creation cancelled' in browser.contents
89    True
90
91Now let's try again and this time we finish the procedure by clicking
92'Create batch' in the form:
93
94    >>> browser.getLink('Add Scratch Card Batch').click()
95    >>> browser.getControl(name='form.batch_prefix').value = 'APP'
96    >>> browser.getControl(name='form.entry_num').value = '5'
97    >>> browser.getControl(name='form.cost').value = '12.12'
98    >>> browser.getControl('Create batch').click()
99
100We're also redirected to the management screen, with a notice about
101the freshly created batch:
102
103    >>> print browser.contents
104    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
105    ...
106    <h2>Access Code Batches</h2>
107    ...
108    ... The following batches are available:
109    ...APP
110    ...-
111    ...1
112    ...
113    ...5
114    ...
115    ...12.12...
116    ...zope.mgr...
117    ...
118
119which means: there exists a batch named ``APP-1`` with 5 entries of
120which 0 have been devalidated, each one costs ``12.12`` and the batch
121was created by ``zope.mgr``.
122
123We create a second batch to see whether searching and related stuff
124works:
125
126    >>> browser.getLink('Add Scratch Card Batch').click()
127    >>> browser.getControl(name='form.batch_prefix').value = 'APP'
128    >>> browser.getControl(name='form.entry_num').value = '5'
129    >>> browser.getControl(name='form.cost').value = '10.12'
130    >>> browser.getControl('Create batch').click()
131
132And a third one that can be deleted afterwards:
133
134    >>> browser.getLink('Add Scratch Card Batch').click()
135    >>> browser.getControl(name='form.batch_prefix').value = 'BLA'
136    >>> browser.getControl(name='form.entry_num').value = '3'
137    >>> browser.getControl(name='form.cost').value = '19.12'
138    >>> browser.getControl('Create batch').click()
139
140Creating Archive Files
141======================
142
143Once a batch is created, we can archive it. To do so we have to tick
144the respective checkbox and click on 'Archive':
145
146    >>> ctrl = browser.getControl(name='batches')
147    >>> ctrl.getControl(value='APP-2').selected = True
148    >>> browser.getControl(name='archive').click()
149    >>> print browser.contents
150    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
151    ...
152    <li ...>Archived APP-2 (APP-2_archive-...-zope.mgr.csv)</li>
153    ...
154
155If we do not select a batch and try to archive or delete, the system
156will complain:
157
158    >>> browser.getControl(name='archive').click()
159    >>> print browser.contents
160    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
161    ...
162    <li ...>No batch selected.</li>
163    ...
164
165Deleting Batches
166================
167
168We can delete batches. They are automatically archived when doing so:
169
170    >>> ctrl = browser.getControl(name='batches')
171    >>> ctrl.getControl(value='BLA-1').selected = True
172    >>> browser.getControl('Archive and Delete').click()
173    >>> print browser.contents
174    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
175    ...Archived BLA-1 (BLA-1_archive-...-zope.mgr.csv)...
176    ...Deleted batch BLA-1...
177    ...
178
179
180Reimporting Batches
181===================
182
183We can reimport batches using the log files written when a batch was
184created before. So one can reimport the freshly deleted BLA-1
185batch.
186
187To do so we must copy the logfile into the ``imports`` dir of
188accesscodes inside the university's datacenter storage. Otherwisae the
189list of importable files is empty:
190
191    >>> browser.getLink('Reimport Scratch Card Batch').click()
192    >>> print browser.contents
193    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
194    ...
195    ...No import batches available...
196    ...
197
198We can cancel that operation:
199
200    >>> browser.getControl('Cancel').click()
201
202We copy the ``BLA-1`` batch logfile over to the ``imports`` directory:
203
204    >>> ac_storage = os.path.join(uploadpath, 'accesscodes')
205    >>> logfile2 = os.path.join(ac_storage,
206    ...                         sorted(os.listdir(ac_storage))[-3])
207    >>> filename = os.path.basename(logfile2)
208    >>> filename
209    'BLA-1-...-zope.mgr.csv'
210
211    >>> import shutil
212    >>> import_path = os.path.join(ac_storage, 'imports')
213    >>> shutil.copy(logfile2, import_path)
214
215Now the file will be presented as import source:
216
217    >>> browser.getLink('Reimport Scratch Card Batch').click()
218    >>> filename in browser.contents
219    True
220
221If we do not tick a filename to import and click 'Reimport', we will
222be warned:
223
224    >>> browser.getControl('Reimport').click()
225    >>> print browser.contents
226    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
227    ...No file chosen. Action cancelled...
228
229Now let's really reimport the batch:
230
231    >>> browser.getLink('Reimport Scratch Card Batch').click()
232    >>> ctrl = browser.getControl(name='filenames')
233    >>> ctrl.getControl(value=filename).selected = True
234    >>> browser.getControl('Reimport').click()
235
236The batch does exist now again:
237
238    >>> print browser.contents
239    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
240    ...Successfully reimported: BLA-1-...-zope.mgr.csv...
241    ...
242
243If we try to reimport an existing batch, that won't work:
244
245    >>> browser.getLink('Reimport Scratch Card Batch').click()
246    >>> ctrl = browser.getControl(name='filenames')
247    >>> ctrl.getControl(value=filename).selected = True
248    >>> browser.getControl('Reimport').click()
249    >>> print browser.contents
250    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
251    ...This batch already exists: BLA-1-...-zope.mgr.csv...
252    ...
253
254
255Log- and Archive Files
256======================
257
258We store log- and archive-files inside the storage managed by the
259local datacenter. Access-code related files are placed inside an
260``accesscode`` subdir:
261
262    >>> ac_storage = os.path.join(uploadpath, 'accesscodes')
263
264Log files for access-code batches
265---------------------------------
266
267Whenever a batch is created, there is also a log file with all entries
268created:
269
270    >>> sorted(os.listdir(ac_storage))
271    ['APP-1-...-zope.mgr.csv', 'APP-2-...-zope.mgr.csv', ...]
272
273Each logfile name contains the prefix, batch number, date of creation
274and userid of creator.
275
276    >>> logfile1 = os.path.join(ac_storage,
277    ...                         sorted(os.listdir(ac_storage))[0])
278    >>> print open(logfile1, 'rb').read()
279    "serial","ac","cost"
280    "APP","1","12.12"
281    "0","APP-1-<10-DIGITS>"
282    "1","APP-1-<10-DIGITS>"
283    "2","APP-1-<10-DIGITS>"
284    "3","APP-1-<10-DIGITS>"
285    "4","APP-1-<10-DIGITS>"
286
287
288
289Archive files
290-------------
291
292We created an archive file above. An archive file name consists of the
293batch prefix, batch number, the string ``_archive``, creation datetime of
294the archive file and userid of batch creator:
295
296    >>> sorted(os.listdir(ac_storage))
297    [..., 'BLA-1_archive-...-zope.mgr.csv', 'imports']
298
299Archive files eventually also contain infos about invalidation dates
300and have a slightly different format therefore.
301
302    >>> archive_file = os.path.join(ac_storage,
303    ...                             sorted(os.listdir(ac_storage))[-2])
304    >>> print open(archive_file, 'rb').read()
305    "prefix","serial","ac","date"
306    "BLA","19.12","1","3"
307    "BLA","0","BLA-1-<10-DIGITS>"
308    "BLA","1","BLA-1-<10-DIGITS>"
309    "BLA","2","BLA-1-<10-DIGITS>"
310
311Clean up:
312
313    >>> shutil.rmtree(uploadpath)
Note: See TracBrowser for help on using the repository browser.