0004-misc-split-admin-pages-tests-block.patch
tests/admin_pages/test_all.py | ||
---|---|---|
2 | 2 | |
3 | 3 |
import logging |
4 | 4 |
import os |
5 |
import re |
|
6 | 5 |
import zipfile |
7 | 6 | |
8 | 7 |
try: |
... | ... | |
36 | 35 |
from wcs.wf.create_formdata import CreateFormdataWorkflowStatusItem, Mapping |
37 | 36 |
from wcs.formdef import FormDef |
38 | 37 |
from wcs.carddef import CardDef |
39 |
from wcs.blocks import BlockDef |
|
40 | 38 |
from wcs import fields |
41 | 39 | |
42 | 40 |
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub |
... | ... | |
1725 | 1723 |
wf2 = Workflow.get(wf2.id) |
1726 | 1724 |
assert wf2.possible_status[-1].items[-1].map_fields_by_varname is True |
1727 | 1725 |
assert wf2.possible_status[-1].items[-1].mappings is None |
1728 | ||
1729 | ||
1730 |
def test_block_new(pub, blocks_feature): |
|
1731 |
create_superuser(pub) |
|
1732 |
create_role() |
|
1733 |
app = login(get_app(pub)) |
|
1734 |
resp = app.get('/backoffice/forms/') |
|
1735 |
resp = resp.click('Fields blocks') |
|
1736 |
resp = resp.click('New field block') |
|
1737 |
resp.form['name'] = 'field block' |
|
1738 |
resp = resp.form.submit() |
|
1739 |
assert resp.location == 'http://example.net/backoffice/forms/blocks/1/' |
|
1740 |
resp = resp.follow() |
|
1741 |
assert '<h2>field block' in resp |
|
1742 |
assert 'There are not yet any fields' in resp |
|
1743 | ||
1744 |
resp.form['label'] = 'foobar' |
|
1745 |
resp.form['type'] = 'string' |
|
1746 |
resp = resp.form.submit() |
|
1747 |
assert resp.location == 'http://example.net/backoffice/forms/blocks/1/' |
|
1748 |
resp = resp.follow() |
|
1749 | ||
1750 |
resp.form['label'] = 'barfoo' |
|
1751 |
resp.form['type'] = 'string' |
|
1752 |
resp = resp.form.submit() |
|
1753 |
assert resp.location == 'http://example.net/backoffice/forms/blocks/1/' |
|
1754 |
resp = resp.follow() |
|
1755 | ||
1756 |
assert len(BlockDef.get(1).fields) == 2 |
|
1757 |
assert str(BlockDef.get(1).fields[0].id) != '1' # don't use integers |
|
1758 | ||
1759 | ||
1760 |
def test_block_options(pub, blocks_feature): |
|
1761 |
create_superuser(pub) |
|
1762 |
create_role() |
|
1763 |
BlockDef.wipe() |
|
1764 |
block = BlockDef() |
|
1765 |
block.name = 'foobar' |
|
1766 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
1767 |
block.store() |
|
1768 | ||
1769 |
app = login(get_app(pub)) |
|
1770 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
1771 |
resp = resp.click(href=re.compile('^settings$')) |
|
1772 |
assert 'readonly' not in resp.form['slug'].attrs |
|
1773 |
resp.form['name'] = 'foo bar' |
|
1774 |
resp = resp.form.submit('submit') |
|
1775 |
assert BlockDef.get(block.id).name == 'foo bar' |
|
1776 | ||
1777 |
FormDef.wipe() |
|
1778 |
formdef = FormDef() |
|
1779 |
formdef.name = 'form title' |
|
1780 |
formdef.fields = [ |
|
1781 |
fields.BlockField(id='0', label='test', type='block:%s' % block.slug), |
|
1782 |
] |
|
1783 |
formdef.store() |
|
1784 | ||
1785 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
1786 |
resp = resp.click(href=re.compile('^settings$')) |
|
1787 |
assert 'readonly' in resp.form['slug'].attrs |
|
1788 |
resp = resp.form.submit('cancel') |
|
1789 |
resp = resp.follow() |
|
1790 | ||
1791 | ||
1792 |
def test_block_export_import(pub, blocks_feature): |
|
1793 |
create_superuser(pub) |
|
1794 |
create_role() |
|
1795 |
BlockDef.wipe() |
|
1796 |
block = BlockDef() |
|
1797 |
block.name = 'foobar' |
|
1798 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
1799 |
block.store() |
|
1800 | ||
1801 |
app = login(get_app(pub)) |
|
1802 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
1803 |
resp = resp.click(href=re.compile('^export$')) |
|
1804 |
xml_export = resp.text |
|
1805 | ||
1806 |
resp = app.get('/backoffice/forms/blocks/') |
|
1807 |
resp = resp.click(href='import') |
|
1808 |
resp = resp.form.submit('cancel') # shouldn't block on missing file |
|
1809 |
resp = resp.follow() |
|
1810 | ||
1811 |
resp = resp.click(href='import') |
|
1812 |
resp = resp.form.submit() |
|
1813 |
assert 'ere were errors processing your form.' in resp |
|
1814 | ||
1815 |
resp.form['file'] = Upload('block', xml_export.encode('utf-8')) |
|
1816 |
resp = resp.form.submit() |
|
1817 |
resp = resp.follow() |
|
1818 |
assert BlockDef.count() == 2 |
|
1819 | ||
1820 |
new_blockdef = [x for x in BlockDef.select() if str(x.id) != str(block.id)][0] |
|
1821 |
assert new_blockdef.name == 'Copy of foobar' |
|
1822 |
assert new_blockdef.slug == 'foobar_1' |
|
1823 |
assert len(new_blockdef.fields) == 1 |
|
1824 |
assert new_blockdef.fields[0].id == '123' |
|
1825 | ||
1826 |
resp = app.get('/backoffice/forms/blocks/') |
|
1827 |
resp = resp.click(href='import') |
|
1828 |
resp.form['file'] = Upload('block', xml_export.encode('utf-8')) |
|
1829 |
resp = resp.form.submit() |
|
1830 |
assert 'Copy of foobar (2)' in [x.name for x in BlockDef.select()] |
|
1831 | ||
1832 |
# import invalid content |
|
1833 |
resp = app.get('/backoffice/forms/blocks/') |
|
1834 |
resp = resp.click(href='import') |
|
1835 |
resp.form['file'] = Upload('block', b'whatever') |
|
1836 |
resp = resp.form.submit() |
|
1837 |
assert 'Invalid File' in resp |
|
1838 | ||
1839 | ||
1840 |
def test_block_delete(pub, blocks_feature): |
|
1841 |
create_superuser(pub) |
|
1842 |
create_role() |
|
1843 |
BlockDef.wipe() |
|
1844 |
FormDef.wipe() |
|
1845 |
block = BlockDef() |
|
1846 |
block.name = 'foobar' |
|
1847 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
1848 |
block.store() |
|
1849 | ||
1850 |
app = login(get_app(pub)) |
|
1851 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
1852 |
resp = resp.click(href=re.compile('^delete$')) |
|
1853 |
assert 'You are about to irrevocably delete this block.' in resp |
|
1854 |
resp = resp.form.submit() |
|
1855 |
resp = resp.follow() |
|
1856 |
assert BlockDef.count() == 0 |
|
1857 | ||
1858 |
# in use |
|
1859 |
BlockDef.wipe() |
|
1860 |
block = BlockDef() |
|
1861 |
block.name = 'foobar' |
|
1862 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
1863 |
block.store() |
|
1864 | ||
1865 |
FormDef.wipe() |
|
1866 |
formdef = FormDef() |
|
1867 |
formdef.name = 'form title' |
|
1868 |
formdef.fields = [ |
|
1869 |
fields.BlockField(id='0', label='test', type='block:%s' % block.slug), |
|
1870 |
] |
|
1871 |
formdef.store() |
|
1872 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
1873 |
resp = resp.click(href=re.compile('^delete$')) |
|
1874 |
assert 'This block is still used' in resp |
|
1875 | ||
1876 | ||
1877 |
def test_block_edit_duplicate_delete_field(pub, blocks_feature): |
|
1878 |
create_superuser(pub) |
|
1879 |
create_role() |
|
1880 |
BlockDef.wipe() |
|
1881 |
block = BlockDef() |
|
1882 |
block.name = 'foobar' |
|
1883 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
1884 |
block.store() |
|
1885 | ||
1886 |
app = login(get_app(pub)) |
|
1887 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
1888 |
resp = resp.click(href=re.compile('123/$')) |
|
1889 |
resp.form['required'].checked = False |
|
1890 |
resp.form['varname'] = 'test' |
|
1891 |
resp = resp.form.submit('submit') |
|
1892 |
resp = resp.follow() |
|
1893 |
assert BlockDef.get(block.id).fields[0].required is False |
|
1894 |
assert BlockDef.get(block.id).fields[0].varname == 'test' |
|
1895 | ||
1896 |
resp = resp.click(href=re.compile('123/duplicate$')) |
|
1897 |
resp = resp.follow() |
|
1898 |
assert len(BlockDef.get(block.id).fields) == 2 |
|
1899 | ||
1900 |
resp = resp.click(href='%s/delete' % BlockDef.get(block.id).fields[1].id) |
|
1901 |
resp = resp.form.submit('submit') |
|
1902 |
resp = resp.follow() |
|
1903 |
assert len(BlockDef.get(block.id).fields) == 1 |
|
1904 | ||
1905 | ||
1906 |
def test_block_use_in_formdef(pub, blocks_feature): |
|
1907 |
create_superuser(pub) |
|
1908 |
create_role() |
|
1909 |
FormDef.wipe() |
|
1910 |
BlockDef.wipe() |
|
1911 |
block = BlockDef() |
|
1912 |
block.name = 'foobar' |
|
1913 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
1914 |
block.store() |
|
1915 | ||
1916 |
formdef = FormDef() |
|
1917 |
formdef.name = 'form title' |
|
1918 |
formdef.fields = [] |
|
1919 |
formdef.store() |
|
1920 | ||
1921 |
app = login(get_app(pub)) |
|
1922 |
resp = app.get('/backoffice/forms/1/fields/') |
|
1923 |
resp.forms[0]['label'] = 'a block field' |
|
1924 |
resp.forms[0]['type'] = 'block:foobar' |
|
1925 |
resp = resp.forms[0].submit().follow() |
|
1926 |
assert 'a block field' in resp.text |
|
1927 |
resp = resp.click('Edit', href='1/') |
|
1928 |
assert resp.form['max_items'].value == '1' |
tests/admin_pages/test_block.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 | ||
3 |
import re |
|
4 | ||
5 |
try: |
|
6 |
import lasso |
|
7 |
except ImportError: |
|
8 |
lasso = None |
|
9 | ||
10 |
import pytest |
|
11 |
from webtest import Upload |
|
12 | ||
13 |
from wcs.qommon.http_request import HTTPRequest |
|
14 |
from wcs.formdef import FormDef |
|
15 |
from wcs.blocks import BlockDef |
|
16 |
from wcs import fields |
|
17 | ||
18 |
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub |
|
19 |
from .test_all import create_superuser, create_role |
|
20 | ||
21 | ||
22 |
def pytest_generate_tests(metafunc): |
|
23 |
if 'pub' in metafunc.fixturenames: |
|
24 |
metafunc.parametrize('pub', ['pickle', 'sql', 'pickle-templates'], indirect=True) |
|
25 | ||
26 | ||
27 |
@pytest.fixture |
|
28 |
def pub(request): |
|
29 |
pub = create_temporary_pub( |
|
30 |
sql_mode=bool('sql' in request.param), |
|
31 |
templates_mode=bool('templates' in request.param) |
|
32 |
) |
|
33 | ||
34 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
|
35 |
pub.set_app_dir(req) |
|
36 |
pub.cfg['identification'] = {'methods': ['password']} |
|
37 |
pub.cfg['language'] = {'language': 'en'} |
|
38 |
pub.write_cfg() |
|
39 | ||
40 |
return pub |
|
41 | ||
42 | ||
43 |
def teardown_module(module): |
|
44 |
clean_temporary_pub() |
|
45 | ||
46 | ||
47 |
def test_block_new(pub, blocks_feature): |
|
48 |
create_superuser(pub) |
|
49 |
create_role() |
|
50 |
app = login(get_app(pub)) |
|
51 |
resp = app.get('/backoffice/forms/') |
|
52 |
resp = resp.click('Fields blocks') |
|
53 |
resp = resp.click('New field block') |
|
54 |
resp.form['name'] = 'field block' |
|
55 |
resp = resp.form.submit() |
|
56 |
assert resp.location == 'http://example.net/backoffice/forms/blocks/1/' |
|
57 |
resp = resp.follow() |
|
58 |
assert '<h2>field block' in resp |
|
59 |
assert 'There are not yet any fields' in resp |
|
60 | ||
61 |
resp.form['label'] = 'foobar' |
|
62 |
resp.form['type'] = 'string' |
|
63 |
resp = resp.form.submit() |
|
64 |
assert resp.location == 'http://example.net/backoffice/forms/blocks/1/' |
|
65 |
resp = resp.follow() |
|
66 | ||
67 |
resp.form['label'] = 'barfoo' |
|
68 |
resp.form['type'] = 'string' |
|
69 |
resp = resp.form.submit() |
|
70 |
assert resp.location == 'http://example.net/backoffice/forms/blocks/1/' |
|
71 |
resp = resp.follow() |
|
72 | ||
73 |
assert len(BlockDef.get(1).fields) == 2 |
|
74 |
assert str(BlockDef.get(1).fields[0].id) != '1' # don't use integers |
|
75 | ||
76 | ||
77 |
def test_block_options(pub, blocks_feature): |
|
78 |
create_superuser(pub) |
|
79 |
create_role() |
|
80 |
BlockDef.wipe() |
|
81 |
block = BlockDef() |
|
82 |
block.name = 'foobar' |
|
83 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
84 |
block.store() |
|
85 | ||
86 |
app = login(get_app(pub)) |
|
87 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
88 |
resp = resp.click(href=re.compile('^settings$')) |
|
89 |
assert 'readonly' not in resp.form['slug'].attrs |
|
90 |
resp.form['name'] = 'foo bar' |
|
91 |
resp = resp.form.submit('submit') |
|
92 |
assert BlockDef.get(block.id).name == 'foo bar' |
|
93 | ||
94 |
FormDef.wipe() |
|
95 |
formdef = FormDef() |
|
96 |
formdef.name = 'form title' |
|
97 |
formdef.fields = [ |
|
98 |
fields.BlockField(id='0', label='test', type='block:%s' % block.slug), |
|
99 |
] |
|
100 |
formdef.store() |
|
101 | ||
102 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
103 |
resp = resp.click(href=re.compile('^settings$')) |
|
104 |
assert 'readonly' in resp.form['slug'].attrs |
|
105 |
resp = resp.form.submit('cancel') |
|
106 |
resp = resp.follow() |
|
107 | ||
108 | ||
109 |
def test_block_export_import(pub, blocks_feature): |
|
110 |
create_superuser(pub) |
|
111 |
create_role() |
|
112 |
BlockDef.wipe() |
|
113 |
block = BlockDef() |
|
114 |
block.name = 'foobar' |
|
115 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
116 |
block.store() |
|
117 | ||
118 |
app = login(get_app(pub)) |
|
119 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
120 |
resp = resp.click(href=re.compile('^export$')) |
|
121 |
xml_export = resp.text |
|
122 | ||
123 |
resp = app.get('/backoffice/forms/blocks/') |
|
124 |
resp = resp.click(href='import') |
|
125 |
resp = resp.form.submit('cancel') # shouldn't block on missing file |
|
126 |
resp = resp.follow() |
|
127 | ||
128 |
resp = resp.click(href='import') |
|
129 |
resp = resp.form.submit() |
|
130 |
assert 'ere were errors processing your form.' in resp |
|
131 | ||
132 |
resp.form['file'] = Upload('block', xml_export.encode('utf-8')) |
|
133 |
resp = resp.form.submit() |
|
134 |
resp = resp.follow() |
|
135 |
assert BlockDef.count() == 2 |
|
136 | ||
137 |
new_blockdef = [x for x in BlockDef.select() if str(x.id) != str(block.id)][0] |
|
138 |
assert new_blockdef.name == 'Copy of foobar' |
|
139 |
assert new_blockdef.slug == 'foobar_1' |
|
140 |
assert len(new_blockdef.fields) == 1 |
|
141 |
assert new_blockdef.fields[0].id == '123' |
|
142 | ||
143 |
resp = app.get('/backoffice/forms/blocks/') |
|
144 |
resp = resp.click(href='import') |
|
145 |
resp.form['file'] = Upload('block', xml_export.encode('utf-8')) |
|
146 |
resp = resp.form.submit() |
|
147 |
assert 'Copy of foobar (2)' in [x.name for x in BlockDef.select()] |
|
148 | ||
149 |
# import invalid content |
|
150 |
resp = app.get('/backoffice/forms/blocks/') |
|
151 |
resp = resp.click(href='import') |
|
152 |
resp.form['file'] = Upload('block', b'whatever') |
|
153 |
resp = resp.form.submit() |
|
154 |
assert 'Invalid File' in resp |
|
155 | ||
156 | ||
157 |
def test_block_delete(pub, blocks_feature): |
|
158 |
create_superuser(pub) |
|
159 |
create_role() |
|
160 |
BlockDef.wipe() |
|
161 |
FormDef.wipe() |
|
162 |
block = BlockDef() |
|
163 |
block.name = 'foobar' |
|
164 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
165 |
block.store() |
|
166 | ||
167 |
app = login(get_app(pub)) |
|
168 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
169 |
resp = resp.click(href=re.compile('^delete$')) |
|
170 |
assert 'You are about to irrevocably delete this block.' in resp |
|
171 |
resp = resp.form.submit() |
|
172 |
resp = resp.follow() |
|
173 |
assert BlockDef.count() == 0 |
|
174 | ||
175 |
# in use |
|
176 |
BlockDef.wipe() |
|
177 |
block = BlockDef() |
|
178 |
block.name = 'foobar' |
|
179 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
180 |
block.store() |
|
181 | ||
182 |
FormDef.wipe() |
|
183 |
formdef = FormDef() |
|
184 |
formdef.name = 'form title' |
|
185 |
formdef.fields = [ |
|
186 |
fields.BlockField(id='0', label='test', type='block:%s' % block.slug), |
|
187 |
] |
|
188 |
formdef.store() |
|
189 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
190 |
resp = resp.click(href=re.compile('^delete$')) |
|
191 |
assert 'This block is still used' in resp |
|
192 | ||
193 | ||
194 |
def test_block_edit_duplicate_delete_field(pub, blocks_feature): |
|
195 |
create_superuser(pub) |
|
196 |
create_role() |
|
197 |
BlockDef.wipe() |
|
198 |
block = BlockDef() |
|
199 |
block.name = 'foobar' |
|
200 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
201 |
block.store() |
|
202 | ||
203 |
app = login(get_app(pub)) |
|
204 |
resp = app.get('/backoffice/forms/blocks/%s/' % block.id) |
|
205 |
resp = resp.click(href=re.compile('123/$')) |
|
206 |
resp.form['required'].checked = False |
|
207 |
resp.form['varname'] = 'test' |
|
208 |
resp = resp.form.submit('submit') |
|
209 |
resp = resp.follow() |
|
210 |
assert BlockDef.get(block.id).fields[0].required is False |
|
211 |
assert BlockDef.get(block.id).fields[0].varname == 'test' |
|
212 | ||
213 |
resp = resp.click(href=re.compile('123/duplicate$')) |
|
214 |
resp = resp.follow() |
|
215 |
assert len(BlockDef.get(block.id).fields) == 2 |
|
216 | ||
217 |
resp = resp.click(href='%s/delete' % BlockDef.get(block.id).fields[1].id) |
|
218 |
resp = resp.form.submit('submit') |
|
219 |
resp = resp.follow() |
|
220 |
assert len(BlockDef.get(block.id).fields) == 1 |
|
221 | ||
222 | ||
223 |
def test_block_use_in_formdef(pub, blocks_feature): |
|
224 |
create_superuser(pub) |
|
225 |
create_role() |
|
226 |
FormDef.wipe() |
|
227 |
BlockDef.wipe() |
|
228 |
block = BlockDef() |
|
229 |
block.name = 'foobar' |
|
230 |
block.fields = [fields.StringField(id='123', required=True, label='Test', type='string')] |
|
231 |
block.store() |
|
232 | ||
233 |
formdef = FormDef() |
|
234 |
formdef.name = 'form title' |
|
235 |
formdef.fields = [] |
|
236 |
formdef.store() |
|
237 | ||
238 |
app = login(get_app(pub)) |
|
239 |
resp = app.get('/backoffice/forms/1/fields/') |
|
240 |
resp.forms[0]['label'] = 'a block field' |
|
241 |
resp.forms[0]['type'] = 'block:foobar' |
|
242 |
resp = resp.forms[0].submit().follow() |
|
243 |
assert 'a block field' in resp.text |
|
244 |
resp = resp.click('Edit', href='1/') |
|
245 |
assert resp.form['max_items'].value == '1' |
|
0 |
- |