0001-backoffice-delete-custom-views-on-form-carddef-delet.patch
tests/admin_pages/test_card.py | ||
---|---|---|
100 | 100 | |
101 | 101 | |
102 | 102 |
def test_cards_delete(pub): |
103 |
create_superuser(pub) |
|
104 | ||
103 | 105 |
CardDef.wipe() |
104 | 106 |
carddef = CardDef() |
105 | 107 |
carddef.name = 'card title' |
106 | 108 |
carddef.fields = [] |
107 | 109 |
carddef.store() |
108 |
create_superuser(pub) |
|
109 |
app = login(get_app(pub)) |
|
110 |
carddef2 = CardDef() |
|
111 |
carddef2.name = 'card title' |
|
112 |
carddef2.fields = [] |
|
113 |
carddef2.store() |
|
114 | ||
115 |
FormDef.wipe() |
|
116 |
formdef = FormDef() |
|
117 |
formdef.name = 'form title' |
|
118 |
formdef.fields = [] |
|
119 |
formdef.store() |
|
120 | ||
121 |
pub.custom_view_class.wipe() |
|
122 |
custom_view = pub.custom_view_class() |
|
123 |
custom_view.title = 'foo' |
|
124 |
custom_view.formdef = carddef |
|
125 |
custom_view.store() |
|
126 |
custom_view2 = pub.custom_view_class() |
|
127 |
custom_view2.title = 'foo' |
|
128 |
custom_view2.formdef = carddef2 |
|
129 |
custom_view2.store() |
|
130 |
custom_view3 = pub.custom_view_class() |
|
131 |
custom_view3.title = 'foo' |
|
132 |
custom_view3.formdef = formdef |
|
133 |
custom_view3.store() |
|
110 | 134 | |
111 | 135 |
carddata = carddef.data_class()() |
112 | 136 |
carddata.just_created() |
113 | 137 |
carddata.data = {} |
114 | 138 |
carddata.store() |
115 | 139 | |
140 |
app = login(get_app(pub)) |
|
116 | 141 |
resp = app.get('http://example.net/backoffice/cards/1/') |
117 | 142 |
resp = resp.click('Delete') |
118 | 143 |
if pub.is_using_postgresql(): |
... | ... | |
122 | 147 |
resp = resp.click('Delete') |
123 | 148 | |
124 | 149 |
resp = resp.form.submit('submit') |
125 |
assert CardDef.count() == 0 |
|
150 |
assert CardDef.count() == 1 |
|
151 |
assert CardDef.select()[0].id == carddef2.id |
|
152 |
assert pub.custom_view_class.count() == 2 |
|
153 |
assert pub.custom_view_class.get(custom_view2.id) |
|
154 |
assert pub.custom_view_class.get(custom_view3.id) |
|
126 | 155 | |
127 | 156 |
carddata.remove_self() # don't keep leftovers |
128 | 157 |
tests/admin_pages/test_form.py | ||
---|---|---|
1035 | 1035 |
formdef.name = 'form title' |
1036 | 1036 |
formdef.fields = [] |
1037 | 1037 |
formdef.store() |
1038 |
formdef2 = FormDef() |
|
1039 |
formdef2.name = 'form title' |
|
1040 |
formdef2.fields = [] |
|
1041 |
formdef2.store() |
|
1042 | ||
1043 |
CardDef.wipe() |
|
1044 |
carddef = CardDef() |
|
1045 |
carddef.name = 'Baz' |
|
1046 |
carddef.store() |
|
1047 | ||
1048 |
pub.custom_view_class.wipe() |
|
1049 |
custom_view = pub.custom_view_class() |
|
1050 |
custom_view.title = 'foo' |
|
1051 |
custom_view.formdef = formdef |
|
1052 |
custom_view.store() |
|
1053 |
custom_view2 = pub.custom_view_class() |
|
1054 |
custom_view2.title = 'foo' |
|
1055 |
custom_view2.formdef = formdef2 |
|
1056 |
custom_view2.store() |
|
1057 |
custom_view3 = pub.custom_view_class() |
|
1058 |
custom_view3.title = 'foo' |
|
1059 |
custom_view3.formdef = carddef |
|
1060 |
custom_view3.store() |
|
1038 | 1061 | |
1039 | 1062 |
app = login(get_app(pub)) |
1040 |
resp = app.get('/backoffice/forms/1/')
|
|
1063 |
resp = app.get('/backoffice/forms/%s/' % formdef.id)
|
|
1041 | 1064 | |
1042 | 1065 |
resp = resp.click(href='delete') |
1043 | 1066 |
resp = resp.forms[0].submit() |
1044 | 1067 |
assert resp.location == 'http://example.net/backoffice/forms/' |
1045 | 1068 |
resp = resp.follow() |
1046 |
assert FormDef.count() == 0 |
|
1069 |
assert FormDef.count() == 1 |
|
1070 |
assert FormDef.select()[0].id == formdef2.id |
|
1071 |
assert pub.custom_view_class.count() == 2 |
|
1072 |
assert pub.custom_view_class.get(custom_view2.id) |
|
1073 |
assert pub.custom_view_class.get(custom_view3.id) |
|
1047 | 1074 | |
1048 | 1075 | |
1049 | 1076 |
def test_form_delete_with_data(pub): |
wcs/admin/forms.py | ||
---|---|---|
1247 | 1247 |
r += form.render() |
1248 | 1248 |
return r.getvalue() |
1249 | 1249 |
else: |
1250 |
criterias = [ |
|
1251 |
Equal('formdef_type', self.formdef_class.xml_root_node), |
|
1252 |
Equal('formdef_id', self.formdef.id), |
|
1253 |
] |
|
1254 |
for view in get_publisher().custom_view_class.select(criterias): |
|
1255 |
view.remove_self() |
|
1250 | 1256 |
self.formdef.remove_self() |
1251 | 1257 |
return redirect('..') |
1252 | 1258 | |
1253 |
- |