Projet

Général

Profil

0001-ctl-add-exclude-option-to-wipe-data-31942.patch

Emmanuel Cazenave, 02 avril 2019 18:38

Télécharger (3,51 ko)

Voir les différences:

Subject: [PATCH] ctl: add --exclude option to wipe-data (#31942)

 tests/test_ctl.py    | 32 +++++++++++++++++++++++++++++---
 wcs/ctl/wipe_data.py |  4 ++++
 2 files changed, 33 insertions(+), 3 deletions(-)
tests/test_ctl.py
107 107
    formdata_2.store()
108 108
    assert form_2.data_class().count() == 1
109 109

  
110
    form_3 = FormDef()
111
    form_3.name = 'example3'
112
    form_3.fields = [StringField(id='0', label='First Name'),
113
                     StringField(id='1', label='Last Name')]
114
    form_3.store()
115
    form_3.data_class().wipe()
116
    formdata_3 = form_3.data_class()()
117
    formdata_3.data = {'0': 'John', '1': 'Doe'}
118
    formdata_3.store()
119
    assert form_3.data_class().count() == 1
120

  
110 121
    wipe_cmd = CmdWipeData()
111 122

  
112 123
    # check command options
......
117 128
    assert form_1.url_name in args
118 129
    assert form_2.url_name in args
119 130

  
120
    sub_options_class = collections.namedtuple('Options', ['all'])
121
    sub_options = sub_options_class(False)
131
    options, args = wipe_cmd.parse_args(['--exclude', form_1.url_name])
132
    assert options.exclude
133
    assert form_1.url_name in args
134

  
135
    sub_options_class = collections.namedtuple('Options', ['all', 'exclude'])
136
    sub_options = sub_options_class(False, False)
122 137

  
123 138
    # test with no options
124 139
    wipe_cmd.wipe(pub, sub_options, [])
125 140
    assert form_1.data_class().count() == 1
126 141
    assert form_2.data_class().count() == 1
142
    assert form_3.data_class().count() == 1
127 143

  
128 144
    # wipe one form formdatas
129 145
    wipe_cmd.wipe(pub, sub_options, [form_1.url_name])
130 146
    assert form_1.data_class().count() == 0
131 147
    assert form_2.data_class().count() == 1
148
    assert form_3.data_class().count() == 1
149

  
150
    # wipe with exclusion
151
    sub_options = sub_options_class(False, True)
152
    wipe_cmd.wipe(pub, sub_options, ['example2'])
153
    assert form_1.data_class().count() == 0
154
    assert form_2.data_class().count() == 1
155
    assert form_3.data_class().count() == 0
132 156

  
133 157
    # wipe all formdatas
134
    sub_options = sub_options_class(True)
158
    sub_options = sub_options_class(True, False)
135 159
    wipe_cmd.wipe(pub, sub_options, [])
136 160
    assert form_1.data_class().count() == 0
137 161
    assert form_2.data_class().count() == 0
162
    assert form_3.data_class().count() == 0
163

  
138 164

  
139 165
def test_trigger_jumps(pub):
140 166
    Workflow.wipe()
wcs/ctl/wipe_data.py
26 26
        Command.__init__(self, [
27 27
                make_option('--all', metavar='ALL', action='store_true',
28 28
                            dest='all'),
29
                make_option('--exclude', metavar='EXCLUDE', action='store_true',
30
                            dest='exclude'),
29 31
                make_option('--vhost', metavar='VHOST', action='store',
30 32
                            dest='vhost'),
31 33
                ])
......
48 50

  
49 51
        if options.all:
50 52
            formdefs = FormDef.select()
53
        elif options.exclude and args:
54
            formdefs = [f for f in FormDef.select() if f.internal_identifier not in args]
51 55
        elif args:
52 56
            formdefs = [FormDef.get_by_urlname(arg) for arg in args]
53 57
        else:
54
-