18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
19 """This modules defines func / methods for creating test repositories""" |
19 """This modules defines func / methods for creating test repositories""" |
20 |
20 |
21 __docformat__ = "restructuredtext en" |
21 __docformat__ = "restructuredtext en" |
22 |
22 |
|
23 import logging |
23 from random import randint, choice |
24 from random import randint, choice |
24 from copy import deepcopy |
25 from copy import deepcopy |
25 from datetime import datetime, date, time, timedelta |
26 from datetime import datetime, date, time, timedelta |
26 from decimal import Decimal |
27 from decimal import Decimal |
27 |
28 |
28 from logilab.common import attrdict |
29 from logilab.common import attrdict |
|
30 from logilab.mtconverter import xml_escape |
29 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint, |
31 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint, |
30 IntervalBoundConstraint, BoundaryConstraint, |
32 IntervalBoundConstraint, BoundaryConstraint, |
31 Attribute, actual_value) |
33 Attribute, actual_value) |
32 from rql.utils import decompose_b26 as base_decompose_b26 |
34 from rql.utils import decompose_b26 as base_decompose_b26 |
33 |
35 |
236 # content_format attribute of EmailPart has no vocabulary constraint, we |
238 # content_format attribute of EmailPart has no vocabulary constraint, we |
237 # need this method else stupid values will be set which make mtconverter |
239 # need this method else stupid values will be set which make mtconverter |
238 # raise exception |
240 # raise exception |
239 return u'text/plain' |
241 return u'text/plain' |
240 |
242 |
|
243 def generate_CWDataImport_log(self, entity, index, **kwargs): |
|
244 # content_format attribute of EmailPart has no vocabulary constraint, we |
|
245 # need this method else stupid values will be set which make mtconverter |
|
246 # raise exception |
|
247 logs = [u'%s\t%s\t%s\t%s<br/>' % (logging.ERROR, 'http://url.com?arg1=hop&arg2=hip', |
|
248 1, xml_escape('hjoio&oio"'))] |
|
249 return u'<br/>'.join(logs) |
|
250 |
241 |
251 |
242 class autoextend(type): |
252 class autoextend(type): |
243 def __new__(mcs, name, bases, classdict): |
253 def __new__(mcs, name, bases, classdict): |
244 for attrname, attrvalue in classdict.items(): |
254 for attrname, attrvalue in classdict.items(): |
245 if callable(attrvalue): |
255 if callable(attrvalue): |
294 def make_entity(etype, schema, vreg, index=0, choice_func=_default_choice_func, |
304 def make_entity(etype, schema, vreg, index=0, choice_func=_default_choice_func, |
295 form=False): |
305 form=False): |
296 """generates a random entity and returns it as a dict |
306 """generates a random entity and returns it as a dict |
297 |
307 |
298 by default, generate an entity to be inserted in the repository |
308 by default, generate an entity to be inserted in the repository |
299 elif form, generate an form dictionnary to be given to a web controller |
309 elif form, generate an form dictionary to be given to a web controller |
300 """ |
310 """ |
301 eschema = schema.eschema(etype) |
311 eschema = schema.eschema(etype) |
302 valgen = ValueGenerator(eschema, choice_func) |
312 valgen = ValueGenerator(eschema, choice_func) |
303 entity = attrdict() |
313 entity = attrdict() |
304 # preprocessing to deal with _format fields |
314 # preprocessing to deal with _format fields |