1 | Browsing the access-code related UI components |
---|
2 | ********************************************** |
---|
3 | |
---|
4 | Here we visit the access-code related parts of a WAeUP SIRP site using |
---|
5 | a virtual browser. |
---|
6 | |
---|
7 | :Test-Layer: functional |
---|
8 | |
---|
9 | Preliminaries |
---|
10 | ============= |
---|
11 | |
---|
12 | Before we can do anything, we have to create a university site: |
---|
13 | |
---|
14 | >>> from zope.testbrowser.testing import Browser |
---|
15 | >>> browser = Browser() |
---|
16 | >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
17 | >>> browser.handleErrors = False |
---|
18 | >>> root = getRootFolder() |
---|
19 | |
---|
20 | >>> from waeup.sirp.app import University |
---|
21 | >>> u = University() |
---|
22 | >>> root['myuniversity'] = u |
---|
23 | |
---|
24 | We set a new datacenter storage path: |
---|
25 | |
---|
26 | >>> import os |
---|
27 | >>> browser.open('http://localhost/myuniversity') |
---|
28 | >>> browser.getLink('Data Center').click() |
---|
29 | >>> browser.getLink('Edit settings').click() |
---|
30 | >>> pathsetting = browser.getControl(name='newpath') |
---|
31 | |
---|
32 | >>> cwd = os.getcwd() |
---|
33 | >>> uploadpath = os.path.join(cwd, 'ac_testfiles') |
---|
34 | >>> os.mkdir(uploadpath) |
---|
35 | >>> pathsetting.value = uploadpath |
---|
36 | >>> browser.getControl(name='save').click() |
---|
37 | |
---|
38 | We remove any existing 'accesscodes' dir from datacenter dir: |
---|
39 | |
---|
40 | >>> import shutil |
---|
41 | >>> if os.path.exists(os.path.join(uploadpath, 'accesscodes')): |
---|
42 | ... shutil.rmtree(os.path.join(uploadpath, 'accesscodes')) |
---|
43 | |
---|
44 | |
---|
45 | Access-code management screen |
---|
46 | ============================= |
---|
47 | |
---|
48 | For users that have the right to manage access-code related stuff, the |
---|
49 | home page of a `University` instance provides a link to the |
---|
50 | access-code management screen. In the beginning, there are naturally |
---|
51 | no batches available: |
---|
52 | |
---|
53 | >>> browser.open('http://localhost/myuniversity') |
---|
54 | >>> browser.getLink('Manage access-codes').click() |
---|
55 | >>> print browser.contents |
---|
56 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
57 | ... |
---|
58 | <h2>Access Code Batches</h2> |
---|
59 | ... |
---|
60 | ... The following batches are available: |
---|
61 | ...No batches yet... |
---|
62 | ... |
---|
63 | |
---|
64 | Adding batches |
---|
65 | ============== |
---|
66 | |
---|
67 | We can add a batch of access-codes using a button displayed in the |
---|
68 | action bar: |
---|
69 | |
---|
70 | >>> browser.getLink('Add Scratch Card Batch').click() |
---|
71 | |
---|
72 | The add screen shows a form where we have to enter a prefix, the |
---|
73 | number of access codes to be generated and the costs for each card. |
---|
74 | |
---|
75 | >>> browser.getControl(name='form.batch_prefix').value = 'APP' |
---|
76 | >>> browser.getControl(name='form.entry_num').value = '5' |
---|
77 | >>> browser.getControl(name='form.cost').value = '12.12' |
---|
78 | |
---|
79 | If we click 'cancel' afterwards, the whole process will be cancelled |
---|
80 | and we'll be redirected to the management screen: |
---|
81 | |
---|
82 | >>> browser.getControl('Cancel').click() |
---|
83 | >>> browser.url |
---|
84 | 'http://localhost/myuniversity/accesscodes' |
---|
85 | |
---|
86 | >>> 'Batch creation cancelled' in browser.contents |
---|
87 | True |
---|
88 | |
---|
89 | Now let's try again and this time we finish the procedure by clicking |
---|
90 | 'Create batch' in the form: |
---|
91 | |
---|
92 | >>> browser.getLink('Add Scratch Card Batch').click() |
---|
93 | >>> browser.getControl(name='form.batch_prefix').value = 'APP' |
---|
94 | >>> browser.getControl(name='form.entry_num').value = '5' |
---|
95 | >>> browser.getControl(name='form.cost').value = '12.12' |
---|
96 | >>> browser.getControl('Create batch').click() |
---|
97 | |
---|
98 | We're also redirected to the management screen, with a notice about |
---|
99 | the freshly created batch: |
---|
100 | |
---|
101 | >>> print browser.contents |
---|
102 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
103 | ... |
---|
104 | <h2>Access Code Batches</h2> |
---|
105 | ... |
---|
106 | ... The following batches are available: |
---|
107 | ...APP |
---|
108 | ...- |
---|
109 | ...1 |
---|
110 | ... |
---|
111 | ...5 |
---|
112 | .../ |
---|
113 | ...0 |
---|
114 | ... |
---|
115 | ...12.12... |
---|
116 | ...zope.mgr... |
---|
117 | ... |
---|
118 | |
---|
119 | which means: there exists a batch named ``APP-1`` with 5 entries of |
---|
120 | which 0 have been devalidated, each one costs ``12.12`` and the batch |
---|
121 | was created by ``zope.mgr``. |
---|
122 | |
---|
123 | We create a second batch to see whether searching and related stuff |
---|
124 | works: |
---|
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 | |
---|
132 | Clean up: |
---|
133 | |
---|
134 | >>> shutil.rmtree(uploadpath) |
---|