Merge lp:~camptocamp/oerpscenario/trunk-set-context-lep into lp:oerpscenario

Proposed by Leonardo Pistone
Status: Merged
Merged at revision: 334
Proposed branch: lp:~camptocamp/oerpscenario/trunk-set-context-lep
Merge into: lp:oerpscenario
Diff against target: 73 lines (+18/-9)
2 files modified
features/environment.py (+1/-0)
features/steps/dsl.py (+17/-9)
To merge this branch: bzr merge lp:~camptocamp/oerpscenario/trunk-set-context-lep
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) Approve
Alexandre Fayolle - camptocamp code reiview, test Approve
Review via email: mp+223207@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

little fix in inline comments.

The only point that tickle me is that I'm not sure of the lifespan of ctx.
It may be dangerous if we do not reset it.

I would add a hook at Scenario initialization to reset it to {}.

review: Needs Fixing
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Good start, but there are other places where you want to add the context:

* all calls to browse / search / create / write / read in dsl.py

* all the same calls in the other python files of oerpscenario

review: Needs Fixing (code review, no test)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

maybe we want a helper function too:

    def get_oe_context(ctx):
        return getattr(ctx, 'oe_context', None)

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

For the browse / search / create / write / read in dsl.py I agreed.
Then for the rest we can agree on a convention and update the doc.

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Maybe a better approach would be to dynamically alter ctx.client._context
And reset it at the end of scenario.

My two cents.

Nicolas

Revision history for this message
Leonardo Pistone (lepistone) wrote :

I addressed Nicolas' remarks.

As for the Alexandre's comments, they are not done yet, because a cleaner solution could be to do that in erppeek and not in oerpscenario. See

https://github.com/tinyerp/erppeek/issues/40

So for now I could leave this MP as is, since it does what I need now (pass a context to create()) and then maybe adapt it when the new erppeek feature lands.

Thanks!

332. By Alexandre Fayolle - camptocamp

[MRG] new step to count number of results

334. By Leonardo Pistone

[imp] reset oe_context at scenario init

335. By Leonardo Pistone

[imp] use ast.literal_eval

Revision history for this message
Leonardo Pistone (lepistone) wrote :

rebased upstream

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

@lpisone : ok point taken.

review: Approve (code reiview, test)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

LGTM can be improved with released 1.6 of erppeek

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'features/environment.py'
2--- features/environment.py 2013-09-03 10:44:42 +0000
3+++ features/environment.py 2014-06-17 08:46:43 +0000
4@@ -39,6 +39,7 @@
5
6 # Work around https://github.com/behave/behave/issues/145
7 def before_scenario(ctx, scenario):
8+ ctx.oe_context = {}
9 if not hasattr(ctx, 'data'):
10 ctx.data = {}
11
12
13=== modified file 'features/steps/dsl.py'
14--- features/steps/dsl.py 2014-06-17 08:14:33 +0000
15+++ features/steps/dsl.py 2014-06-17 08:46:43 +0000
16@@ -180,18 +180,25 @@
17 ctx.found_item.write(table_values)
18
19
20+@step(u'I set the context to "{oe_context_string}"')
21+def impl(ctx, oe_context_string):
22+ ctx.oe_context = literal_eval(oe_context_string)
23+
24+
25 def create_new_obj(ctx, model_name, values):
26 values = values.copy()
27 xmlid = values.pop('xmlid', None)
28- record = model(model_name).create(values)
29+ oe_context = getattr(ctx, 'oe_context', None)
30+ record = model(model_name).create(values, context=oe_context)
31 if xmlid is not None:
32 ModelData = model('ir.model.data')
33 module, xmlid = xmlid.split('.', 1)
34- _model_data = ModelData.create({'name': xmlid,
35- 'model': model_name,
36- 'res_id': record.id,
37- 'module': module,
38- })
39+ _model_data = ModelData.create({
40+ 'name': xmlid,
41+ 'model': model_name,
42+ 'res_id': record.id,
43+ 'module': module,
44+ }, context=oe_context)
45 return record
46
47
48@@ -201,6 +208,7 @@
49 assert active_text in ('', 'inactive', 'active', 'possibly inactive')
50 Model = model(model_name)
51 ctx.search_model_name = model_name
52+ oe_context = getattr(ctx, 'oe_context', None)
53 values = parse_domain(domain)
54 active = True
55 if active_text == 'inactive':
56@@ -209,14 +217,14 @@
57 active = None
58 domain = build_search_domain(ctx, model_name, values, active=active)
59 if domain is not None:
60- ids = Model.search(domain)
61+ ids = Model.search(domain, context=oe_context)
62 else:
63 ids = []
64 if len(ids) == 1:
65- ctx.found_item = Model.browse(ids[0])
66+ ctx.found_item = Model.browse(ids[0], context=oe_context)
67 else:
68 ctx.found_item = None
69- ctx.found_items = Model.browse(ids)
70+ ctx.found_items = Model.browse(ids, context=oe_context)
71
72
73 @step(u'I need a{n:optional}{active_text:optional} "{model_name}" with {domain}')

Subscribers

People subscribed via source and target branches

to all changes: