Mercurial > p > roundup > code
annotate test/mocknull.py @ 5548:fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
As discussed in issue 2550722 there are various cases where selecting
"no selection" on a multilink can result in inappropriate errors from
Roundup:
* If selecting "no selection" produces a null edit (a value was set in
the multilink in an edit with an error, then removed again, along
with all other changes, in the next form submission), so the page is
rendered from the form contents including the "-<id>" value for "no
selection" for the multilink.
* If creating an item with a nonempty value for a multilink has an
error, and the resubmission changes that multilink to "no selection"
(and this in turn has subcases, according to whether the creation
then succeeds or fails on the resubmission, which need fixes in
different places in the Roundup code).
All of these cases have in common that it is expected and OK to have a
"-<id>" value for a submission for a multilink when <id> is not set in
that multilink in the database (because the original attempt to set
<id> in that multilink had an error), so the hyperdb.py logic to give
an error in that case is thus removed. In the subcase of the second
case where the resubmission with "no selection" has an error, the
templating code tries to produce a menu entry for the "-<id>"
multilink value, which also results in an error, hence the
templating.py change to ignore such values in the list for a
multilink.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Thu, 27 Sep 2018 11:33:01 +0000 |
| parents | ad8031290639 |
| children | b1ab8bd18e79 |
| rev | line source |
|---|---|
|
2532
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2 class MockNull: |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 def __init__(self, **kwargs): |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 for key, value in kwargs.items(): |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
5 self.__dict__[key] = value |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
6 |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
7 def __call__(self, *args, **kwargs): return MockNull() |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 def __getattr__(self, name): |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 # This allows assignments which assume all intermediate steps are Null |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
10 # objects if they don't exist yet. |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 # |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
12 # For example (with just 'client' defined): |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 # |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 # client.db.config.TRACKER_WEB = 'BASE/' |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 self.__dict__[name] = MockNull() |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
16 return getattr(self, name) |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
17 |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
18 def __getitem__(self, key): return self |
|
5457
a35d4cc8cd1a
fix MissingValue / MockNull to return False on __bool__ and add a
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5404
diff
changeset
|
19 def __bool__(self): return False |
|
5404
3757449e00c4
Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents:
2686
diff
changeset
|
20 # Python 2 compatibility: |
|
3757449e00c4
Python 3 preparation: use __bool__ instead of __nonzero__.
Joseph Myers <jsm@polyomino.org.uk>
parents:
2686
diff
changeset
|
21 __nonzero__ = __bool__ |
|
5457
a35d4cc8cd1a
fix MissingValue / MockNull to return False on __bool__ and add a
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5404
diff
changeset
|
22 def __contains__(self, key): return False |
|
5461
ad8031290639
Python 3 compatibility for missing / mock value
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5457
diff
changeset
|
23 def __eq__(self, rhs): return False |
|
ad8031290639
Python 3 compatibility for missing / mock value
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5457
diff
changeset
|
24 def __ne__(self, rhs): return False |
|
2532
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 def __str__(self): return '' |
|
24d3b25a9157
*** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 def __repr__(self): return '<MockNull 0x%x>'%id(self) |
|
2686
79fd8537ae3b
.gettext() facility is vital for many roundup objects.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2532
diff
changeset
|
27 def gettext(self, str): return str |
|
79fd8537ae3b
.gettext() facility is vital for many roundup objects.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2532
diff
changeset
|
28 _ = gettext |
