[18.0][IMP] product_cost_security: Make tests more resilient#2254
[18.0][IMP] product_cost_security: Make tests more resilient#2254sergio-teruel wants to merge 1 commit into
Conversation
| if ( | ||
| config["test_enable"] | ||
| and not self.env.context.get("testing_product_cost_security") | ||
| and "standard_price" in fields | ||
| ): | ||
| # By default in other tests users have not this security group, so do this | ||
| # only when we are testing this module. | ||
| return fields |
There was a problem hiding this comment.
The logic of this module is not exclusive to the standard_price field; it applies to every field that has the group product_cost_security.group_product_cost defined in its field definition. So, I think it is better to use the function _product_cost_security_fields to check this.
Additionally, I returned the super() call.
What do you think about this approach?
| if ( | |
| config["test_enable"] | |
| and not self.env.context.get("testing_product_cost_security") | |
| and "standard_price" in fields | |
| ): | |
| # By default in other tests users have not this security group, so do this | |
| # only when we are testing this module. | |
| return fields | |
| product_cost_fields = self._product_cost_security_fields().intersection( | |
| valid_fields | |
| ) | |
| if ( | |
| config["test_enable"] | |
| and not self.env.context.get("testing_product_cost_security") | |
| and product_cost_fields | |
| ): | |
| # By default in other tests users have not this security group, so do this | |
| # only when we are testing this module. | |
| return valid_fields |
There was a problem hiding this comment.
suggestion: alter context in test only once, here:
| cls.env = cls.env(context=dict(cls.env.context, disable_auto_svl=True, testing_product_cost_security=True)) |
34936be to
f118288
Compare
|
@yajo @carlos-lopez-tecnativa Changes done! |
f118288 to
c3db4b2
Compare
| except AccessError as e: | ||
| if ( | ||
| "You do not have enough rights to access the " | ||
| 'fields "standard_price" on' in str(e) |
There was a problem hiding this comment.
The string comparison for this is very fragile and difficult to debug if upstream the message is changed (or maybe translated). Isn't there other way to get this? Or only look for "standard_price" term?
@Tecnativa
ping @carlosdauden @CarlosRoca13