0001-categories-change-on-disk-storage-to-be-XML-4739.patch
tests/test_categories.py | ||
---|---|---|
1 |
import os |
|
2 |
import pickle |
|
1 | 3 |
import shutil |
2 | 4 |
import tempfile |
3 | 5 |
from cStringIO import StringIO |
... | ... | |
87 | 89 |
assert test.id == test2.id |
88 | 90 |
assert test.name == test2.name |
89 | 91 |
assert test.description == test2.description |
92 | ||
93 | ||
94 |
def test_load_old_pickle(): |
|
95 |
Category.wipe() |
|
96 | ||
97 |
test = Category() |
|
98 |
test.id = 1 |
|
99 |
test.name = 'Test' |
|
100 |
test.description = 'Hello world' |
|
101 | ||
102 |
os.mkdir(os.path.join(pub.app_dir, 'categories')) |
|
103 |
fd = file(os.path.join(pub.app_dir, 'categories', '1'), 'w') |
|
104 |
pickle.dump(test, fd) |
|
105 |
fd.close() |
|
106 | ||
107 |
test2 = Category.get(1) |
|
108 |
assert test.id == test2.id |
|
109 |
assert test.name == test2.name |
|
110 |
assert test.description == test2.description |
wcs/categories.py | ||
---|---|---|
22 | 22 |
from qommon.storage import StorableObject |
23 | 23 |
from qommon.misc import simplify, is_user_admin, indent_xml |
24 | 24 |
from qommon.substitution import Substitutions |
25 |
from qommon.xml_storage import XmlStorableObject |
|
25 | 26 | |
26 |
class Category(StorableObject): |
|
27 |
class Category(XmlStorableObject):
|
|
27 | 28 |
_names = 'categories' |
28 | 29 |
name = None |
29 | 30 |
url_name = None |
wcs/qommon/xml_storage.py | ||
---|---|---|
1 |
# w.c.s. - web application for online forms |
|
2 |
# Copyright (C) 2005-2014 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 |
from .storage import StorableObject |
|
18 | ||
19 | ||
20 |
class XmlStorableObject(StorableObject): |
|
21 |
@classmethod |
|
22 |
def storage_load(cls, fd): |
|
23 |
first_byte = fd.read(1) |
|
24 |
fd.seek(0) |
|
25 |
if first_byte == '<': |
|
26 |
return cls.import_from_xml(fd, include_id=True) |
|
27 |
else: |
|
28 |
return StorableObject.storage_load(fd) |
|
29 | ||
30 |
@classmethod |
|
31 |
def storage_dumps(cls, object): |
|
32 |
return object.export_to_xml_string(include_id=True) |
|
0 |
- |