0001-ctl-add-command-to-delete-formdata-13669.patch
tests/test_formdata.py | ||
---|---|---|
3 | 3 |
import sys |
4 | 4 |
import shutil |
5 | 5 |
import time |
6 |
import collections |
|
6 | 7 | |
7 | 8 |
from quixote import cleanup |
8 | 9 |
from quixote.http_request import Upload |
... | ... | |
549 | 550 |
formdata.data = {'bo1': 'test'} |
550 | 551 |
substvars = formdata.get_substitution_variables() |
551 | 552 |
assert substvars.get('form_var_backoffice_blah') == 'test' |
553 | ||
554 | ||
555 |
def test_delete_formdata(pub): |
|
556 |
from wcs.ctl.delete_formdata import DeleteFormdata |
|
557 |
formdef = FormDef() |
|
558 |
formdef.name = 'example' |
|
559 |
formdef.fields = [fields.StringField(id='0', label='Your Name'), |
|
560 |
fields.EmailField(id='1', label='Email')] |
|
561 |
formdef.store() |
|
562 |
formdef.data_class().wipe() |
|
563 |
formdata = formdef.data_class()() |
|
564 |
formdata.data = {'0': 'John Doe', '1': 'john@example.net'} |
|
565 |
formdata.store() |
|
566 | ||
567 |
formdata2 = formdef.data_class()() |
|
568 |
formdata2.data = {'0': 'Foo Bar', '1': 'foot@bar.net'} |
|
569 |
formdata2.store() |
|
570 |
assert formdef.data_class().count() == 2 |
|
571 | ||
572 |
delete_cmd = DeleteFormdata() |
|
573 |
base_options = {} |
|
574 |
sub_options_class = collections.namedtuple('Options', ['hostname']) |
|
575 |
sub_options = sub_options_class(False) |
|
576 |
delete_cmd.delete_formdata(pub, 'example.net') |
|
577 |
assert formdef.data_class().count() == 0 |
wcs/ctl/delete_formdata.py | ||
---|---|---|
1 |
# w.c.s. - web application for online forms |
|
2 |
# Copyright (C) 2005-2010 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software; you can redistribute it and/or modify |
|
5 |
# it under the terms of the GNU General Public License as published by |
|
6 |
# the Free Software Foundation; either version 2 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU General Public License |
|
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
import os |
|
18 | ||
19 |
from qommon.ctl import Command, make_option |
|
20 | ||
21 | ||
22 |
class DeleteFormdata(Command): |
|
23 |
name = 'delete_formdata' |
|
24 | ||
25 |
def __init__(self): |
|
26 |
Command.__init__(self, [ |
|
27 |
make_option('--hostname', metavar='HOSTNAME', action='store', |
|
28 |
dest='hostname'), |
|
29 |
]) |
|
30 | ||
31 |
def execute(self, base_options, sub_options, args): |
|
32 |
import publisher |
|
33 | ||
34 |
publisher.WcsPublisher.configure(self.config) |
|
35 |
publisher = publisher.WcsPublisher.create_publisher( |
|
36 |
register_cron=False, register_tld_names=False) |
|
37 |
publisher.app_dir = os.path.join(publisher.app_dir, ) |
|
38 |
publisher.set_config() |
|
39 |
self.delete_formdata(publisher, sub_options.hostname) |
|
40 | ||
41 |
def delete_formdata(self, pub, hostname): |
|
42 |
from wcs.formdef import FormDef |
|
43 |
app_dir = pub.app_dir |
|
44 |
for formdef in FormDef.select(): |
|
45 |
formdata = formdef.data_class() |
|
46 |
formdata.wipe() |
|
47 | ||
48 |
DeleteFormdata.register() |
|
0 |
- |