[TEST] add new tests and refactor
authorAlexandre Fayolle <alexandre.fayolle@camptocamp.com>
Wed, 22 May 2013 15:32:03 +0000 (17:32 +0200)
committerAlexandre Fayolle <alexandre.fayolle@camptocamp.com>
Wed, 22 May 2013 15:32:03 +0000 (17:32 +0200)
bzr revid: alexandre.fayolle@camptocamp.com-20130522153203-wp45pyicciktg8m8

addons/stock/test/multicompany.yml

index 962bb82..8c5df8f 100644 (file)
@@ -4,20 +4,49 @@
 -
   !context
     uid: 'stock.multicompany_user'
+
+-
+  check no error on getting default stock.move values in multicompany setting
+-
+  !python {model: stock.move}: |
+    location_obj = self.pool.get('stock.location')
+    fields = ['location_id', 'location_dest_id']
+    for type in ('in', 'internal', 'out'):
+        context['picking_type'] = type
+        defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context)
+        for field in fields:
+            if defaults[field] != False:
+                assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable location %s" % field
+        assert defaults['type'] == type}, "wrong move type"
+
 -
-  check no error on getting default stock.move values for internal move
+  check onchange_move_type does not return unreadable in multicompany setting
 -
   !python {model: stock.move}: |
-    multicomp_user = ref('stock.multicompany_user')
-    context['picking_type'] = 'internal'
-    log('multicompany user: %s, uid: %s', multicomp_user, uid)
-    log('current context: %s', context)
-    defaults = self.default_get(cr, multicomp_user, ['location_id', 'location_dest_id', 'type'], context)
-    assertion_msg = "did not get the correct default (got: %s)" % defaults
-    log('got defaults: %s', defaults)
-    assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, assertion_msg
-    defaults = self.default_get(cr, uid, ['location_id', 'location_dest_id', 'type'], context)
-    assertion_msg = "did not get the correct default with uid %s (got: %s)" % (uid, defaults)
-    log('got defaults: %s', defaults)
-    assert defaults == {'location_id': False, 'location_dest_id': False, 'type': 'internal'}, assertion_msg
+    location_obj = self.pool.get('stock.location')
+    fields = ['location_id', 'location_dest_id']
+    for type in ('in', 'internal', 'out'):
+        result = self.onchange_move_type(cr, uid, [], type, context)['value']
+        for field in fields:
+            if defaults[field] != False:
+                assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable default %s" % field
 
+-
+  check default location readability for stock_fill_inventory in multicompany setting
+-
+  !python {model: stock.fill.inventory}: |
+    location_obj = self.pool.get('stock.location')
+    defaults = self.default_get(cr, uid, ['location_id'], context)
+    if defaults['location_id'] != False:
+        assert location_obj.check_access_rule(cr, uid, defaults['location_id'], 'read', context), "unreadable default source location"
+
+-
+  check default locations for warehouse in multicompany setting
+-
+  !python {model: stock.warehouse}: |
+    fields = ['lot_input_id', 'lot_stock_id', 'lot_output_id']
+    defaults = self.default_get(cr, uid, fields, context)
+    for field in fields:
+        for field in fields:
+            if defaults[field] != False:
+                assert location_obj.check_access_rule(cr, uid, defaults[field], 'read', context), "unreadable default %s" % field