Projet

Général

Profil

0001-wcs-explicit-id-from-URL-choice-for-card-cell-60957.patch

Lauréline Guérin, 28 janvier 2022 14:56

Télécharger (10,4 ko)

Voir les différences:

Subject: [PATCH] wcs: explicit "id from URL" choice for card cell (#60957)

 combo/apps/wcs/forms.py |  7 +++-
 tests/test_wcs.py       | 71 +++++++++++++++++++++++++++++++----------
 2 files changed, 61 insertions(+), 17 deletions(-)
combo/apps/wcs/forms.py
99 99
            del self.fields['custom_schema']
100 100

  
101 101
        self.fields['related_card_path'].choices = [
102
            ('', _('Other Card Identifiers'))
102
            ('--', _('Identifier from page URL')),
103
            ('', _('Other Card Identifiers')),
103 104
        ] + self.instance.get_related_card_paths()
105
        if not self.instance.card_ids and not self.instance.related_card_path:
106
            self.initial['related_card_path'] = '--'
104 107

  
105 108
    def save(self, *args, **kwargs):
106 109
        super().save(*args, **kwargs)
......
108 111
            self.instance.custom_schema = {}
109 112
        if self.instance.related_card_path:
110 113
            self.instance.card_ids = ''
114
        if self.instance.related_card_path == '--':
115
            self.instance.related_card_path = ''
111 116
        self.instance.without_user = not self.cleaned_data['with_user']
112 117
        self.instance.save()
113 118
        return self.instance
tests/test_wcs.py
1909 1909
    cell.refresh_from_db()
1910 1910
    assert cell.custom_schema == {}
1911 1911

  
1912
    assert cell.related_card_path == ''
1913
    assert cell.card_ids == ''
1914
    resp = app.get('/manage/pages/%s/' % page.pk)
1915
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].value == '--'
1916
    resp.forms[0]['c%s-card_ids' % cell.get_reference()].value = '42'
1917
    resp.forms[0].submit().follow()
1918
    cell.refresh_from_db()
1919
    assert cell.related_card_path == ''
1920
    assert cell.card_ids == ''
1921
    resp = app.get('/manage/pages/%s/' % page.pk)
1922
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].value == '--'
1923
    resp.forms[0]['c%s-related_card_path' % cell.get_reference()].value = ''
1924
    resp.forms[0]['c%s-card_ids' % cell.get_reference()].value = '42'
1925
    resp.forms[0].submit().follow()
1926
    cell.refresh_from_db()
1927
    assert cell.related_card_path == ''
1928
    assert cell.card_ids == '42'
1929

  
1912 1930

  
1913 1931
def test_card_cell_custom_schema_migration():
1914 1932
    cell = WcsCardInfosCell()
......
2119 2137
    resp = app.get('/manage/pages/%s/' % page.pk)
2120 2138
    # but only one cell on the page, no relations to follow
2121 2139
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2122
        ('', True, 'Other Card Identifiers')
2140
        ('--', True, 'Identifier from page URL'),
2141
        ('', False, 'Other Card Identifiers'),
2123 2142
    ]
2124 2143

  
2125 2144
    # add a second cell, related to the first card model
......
2129 2148
    resp = app.get('/manage/pages/%s/' % page.pk)
2130 2149
    # still no relation to follow
2131 2150
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2132
        ('', True, 'Other Card Identifiers')
2151
        ('--', True, 'Identifier from page URL'),
2152
        ('', False, 'Other Card Identifiers'),
2133 2153
    ]
2134 2154
    # no cell with id and slug
2135 2155
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2136
        ('', True, 'Other Card Identifiers')
2156
        ('--', True, 'Identifier from page URL'),
2157
        ('', False, 'Other Card Identifiers'),
2137 2158
    ]
2138 2159

  
2139 2160
    # set a slug on first cell
......
2142 2163
    resp = app.get('/manage/pages/%s/' % page.pk)
2143 2164
    # still no relation to follow
2144 2165
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2145
        ('', True, 'Other Card Identifiers')
2166
        ('--', True, 'Identifier from page URL'),
2167
        ('', False, 'Other Card Identifiers'),
2146 2168
    ]
2147 2169
    # multiple relations to follow
2148 2170
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2149
        ('', True, 'Other Card Identifiers'),
2171
        ('--', True, 'Identifier from page URL'),
2172
        ('', False, 'Other Card Identifiers'),
2150 2173
        ('sluga/cardb', False, 'sluga/cardb'),
2151 2174
        ('sluga/cardsb', False, 'sluga/cardsb'),
2152 2175
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
......
2161 2184
    resp = app.get('/manage/pages/%s/' % page.pk)
2162 2185
    # still no relation to follow
2163 2186
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2164
        ('', True, 'Other Card Identifiers')
2187
        ('--', False, 'Identifier from page URL'),
2188
        ('', True, 'Other Card Identifiers'),
2165 2189
    ]
2166 2190
    # can not user cell with multiple ids as reference
2167 2191
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2168
        ('', True, 'Other Card Identifiers')
2192
        ('--', True, 'Identifier from page URL'),
2193
        ('', False, 'Other Card Identifiers'),
2169 2194
    ]
2170 2195

  
2171 2196
    # define a slug on second cell
......
2176 2201
    resp = app.get('/manage/pages/%s/' % page.pk)
2177 2202
    # multiple relations to follow
2178 2203
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2179
        ('', True, 'Other Card Identifiers'),
2204
        ('--', True, 'Identifier from page URL'),
2205
        ('', False, 'Other Card Identifiers'),
2180 2206
        ('slugb/reverse:cardb', False, 'slugb/cardb (reverse)'),
2181 2207
        ('slugb/reverse:cardsb', False, 'slugb/cardsb (reverse)'),
2182 2208
        ('slugb/reverse:blockb_cardb', False, 'slugb/blockb_cardb (reverse)'),
2183 2209
    ]
2184 2210
    # still multiple relations to follow
2185 2211
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2186
        ('', True, 'Other Card Identifiers'),
2212
        ('--', True, 'Identifier from page URL'),
2213
        ('', False, 'Other Card Identifiers'),
2187 2214
        ('sluga/cardb', False, 'sluga/cardb'),
2188 2215
        ('sluga/cardsb', False, 'sluga/cardsb'),
2189 2216
        ('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
......
2202 2229
    resp = app.get('/manage/pages/%s/' % page.pk)
2203 2230
    # no more relation to follow
2204 2231
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2205
        ('', True, 'Other Card Identifiers')
2232
        ('--', True, 'Identifier from page URL'),
2233
        ('', False, 'Other Card Identifiers'),
2206 2234
    ]
2207 2235
    # still multiple relations to follow
2208 2236
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2237
        ('--', False, 'Identifier from page URL'),
2209 2238
        ('', False, 'Other Card Identifiers'),
2210 2239
        ('sluga/cardb', True, 'sluga/cardb'),
2211 2240
        ('sluga/cardsb', False, 'sluga/cardsb'),
......
2214 2243
        ('sluga/cardc/cardsb', False, 'sluga/cardc/cardsb'),
2215 2244
        ('sluga/cardc/blockb_cardb', False, 'sluga/cardc/blockb_cardb'),
2216 2245
    ]
2246
    resp.forms[1].submit()
2247
    cell2.refresh_from_db()
2248
    assert cell2.related_card_path == 'sluga/cardb'
2249
    assert cell2.card_ids == ''
2217 2250

  
2218 2251
    # check circular relations
2219 2252
    cell.slug = 'sluge'
......
2225 2258
    cell2.save()
2226 2259
    resp = app.get('/manage/pages/%s/' % page.pk)
2227 2260
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2228
        ('', True, 'Other Card Identifiers'),
2261
        ('--', True, 'Identifier from page URL'),
2262
        ('', False, 'Other Card Identifiers'),
2229 2263
        ('slugd/cardd-foo/carde-foo', False, 'slugd/cardd-foo/carde-foo'),
2230 2264
        ('slugd/carde-foo', False, 'slugd/carde-foo'),
2231 2265
    ]
2232 2266
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2233
        ('', True, 'Other Card Identifiers'),
2267
        ('--', True, 'Identifier from page URL'),
2268
        ('', False, 'Other Card Identifiers'),
2234 2269
        ('sluge/cardd-bar', False, 'sluge/cardd-bar'),
2235 2270
        ('sluge/reverse:carde-foo', False, 'sluge/carde-foo (reverse)'),
2236 2271
    ]
......
2244 2279
    cell2.save()
2245 2280
    resp = app.get('/manage/pages/%s/' % page.pk)
2246 2281
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2247
        ('', True, 'Other Card Identifiers'),
2282
        ('--', True, 'Identifier from page URL'),
2283
        ('', False, 'Other Card Identifiers'),
2248 2284
        ('slugd-bis/cardd-foo', False, 'slugd-bis/cardd-foo'),
2249 2285
        ('slugd-bis/reverse:cardd-foo', False, 'slugd-bis/cardd-foo (reverse)'),
2250 2286
        ('slugd-bis/carde-foo/cardd-bar', False, 'slugd-bis/carde-foo/cardd-bar'),
2251 2287
        ('slugd-bis/carde-foo/reverse:carde-foo', False, 'slugd-bis/carde-foo/carde-foo (reverse)'),
2252 2288
    ]
2253 2289
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2254
        ('', True, 'Other Card Identifiers'),
2290
        ('--', True, 'Identifier from page URL'),
2291
        ('', False, 'Other Card Identifiers'),
2255 2292
        ('slugd/cardd-foo', False, 'slugd/cardd-foo'),
2256 2293
        ('slugd/reverse:cardd-foo', False, 'slugd/cardd-foo (reverse)'),
2257 2294
        ('slugd/carde-foo/cardd-bar', False, 'slugd/carde-foo/cardd-bar'),
......
2267 2304
    cell2.save()
2268 2305
    resp = app.get('/manage/pages/%s/' % page.pk)
2269 2306
    assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
2270
        ('', True, 'Other Card Identifiers'),
2307
        ('--', True, 'Identifier from page URL'),
2308
        ('', False, 'Other Card Identifiers'),
2271 2309
        ('sluge-bis/cardd-bar/carde-foo', False, 'sluge-bis/cardd-bar/carde-foo'),
2272 2310
    ]
2273 2311
    assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
2274
        ('', True, 'Other Card Identifiers'),
2312
        ('--', True, 'Identifier from page URL'),
2313
        ('', False, 'Other Card Identifiers'),
2275 2314
        ('sluge/cardd-bar/carde-foo', False, 'sluge/cardd-bar/carde-foo'),
2276 2315
    ]
2277 2316

  
2278
-