Projet

Général

Profil

0001-misc-make-sure-.wipe-is-only-called-on-classes-43651.patch

Frédéric Péters, 11 octobre 2022 11:50

Télécharger (3,67 ko)

Voir les différences:

Subject: [PATCH] misc: make sure .wipe() is only called on classes (#43651)

 tests/test_formdef.py | 11 +++++++++++
 wcs/formdef.py        |  4 ++--
 wcs/qommon/storage.py |  3 ++-
 wcs/sql.py            |  6 +++---
 4 files changed, 18 insertions(+), 6 deletions(-)
tests/test_formdef.py
646 646
    assert formdef.fields[0].label == 'Test'
647 647
    assert formdef.workflow.possible_status[0].items[0].varname == 'blah'
648 648
    assert formdef.workflow.possible_status[0].items[0].formdef.fields[0].varname == 'str'
649

  
650

  
651
def test_wipe_on_object(pub):
652
    FormDef.wipe()
653

  
654
    formdef = FormDef()
655
    formdef.name = 'basic formdef'
656
    formdef.store()
657

  
658
    with pytest.raises(AttributeError):
659
        formdef.wipe()
wcs/formdef.py
44 44
from .qommon.form import Form, HtmlWidget, UploadedFile
45 45
from .qommon.misc import JSONEncoder, get_as_datetime, is_attachment, is_upload, simplify, xml_node_text
46 46
from .qommon.publisher import get_publisher_class
47
from .qommon.storage import Equal, StorableObject, fix_key
47
from .qommon.storage import Equal, StorableObject, classonlymethod, fix_key
48 48
from .qommon.substitution import Substitutions
49 49
from .qommon.template import Template
50 50
from .roles import logged_users_role
......
441 441
        user_roles = set(user.get_roles())
442 442
        return management_roles.intersection(user_roles)
443 443

  
444
    @classmethod
444
    @classonlymethod
445 445
    def wipe(cls):
446 446
        super().wipe()
447 447
        cls.sql_wipe()
wcs/qommon/storage.py
28 28
import time
29 29

  
30 30
import unidecode
31
from django.utils.decorators import classonlymethod
31 32
from django.utils.encoding import force_bytes
32 33
from quixote import get_publisher
33 34

  
......
1069 1070
            return None, None
1070 1071
        return snapshots[0].timestamp, snapshots[0].user_id
1071 1072

  
1072
    @classmethod
1073
    @classonlymethod
1073 1074
    def wipe(cls):
1074 1075
        tmpdir = tempfile.mkdtemp(prefix='wiping', dir=os.path.join(get_publisher().app_dir))
1075 1076
        dirs_to_move = []
wcs/sql.py
58 58
from .publisher import UnpicklerClass
59 59
from .qommon import _, get_cfg
60 60
from .qommon.misc import JSONEncoder, strftime
61
from .qommon.storage import NothingToUpdate, _take, deep_bytes2str
61
from .qommon.storage import NothingToUpdate, _take, classonlymethod, deep_bytes2str
62 62
from .qommon.storage import parse_clause as parse_storage_clause
63 63
from .qommon.substitution import invalidate_substitution_cache
64 64
from .qommon.upload_storage import PicklableUpload
......
2464 2464
        conn.commit()
2465 2465
        cur.close()
2466 2466

  
2467
    @classmethod
2467
    @classonlymethod
2468 2468
    @guard_postgres
2469 2469
    def wipe(cls, drop=False, clause=None):
2470 2470
        conn, cur = get_connection_and_cursor()
......
3042 3042
        conn.commit()
3043 3043
        cur.close()
3044 3044

  
3045
    @classmethod
3045
    @classonlymethod
3046 3046
    @guard_postgres
3047 3047
    def wipe(cls, drop=False):
3048 3048
        conn, cur = get_connection_and_cursor()
3049
-