SEBA-405 Cleanup synchronizer imports of model_accessor to globals;
Move mock modelaccessor to /tmp;
Easier mock modelaccessor configuration
Change-Id: I67a17b9a72ea69f61d92206f1b520a11c2f18d80
diff --git a/lib/xos-genx/xosgenx/targets/mock_classes.xtarget b/lib/xos-genx/xosgenx/targets/mock_classes.xtarget
index 69efe92..61c2f1f 100644
--- a/lib/xos-genx/xosgenx/targets/mock_classes.xtarget
+++ b/lib/xos-genx/xosgenx/targets/mock_classes.xtarget
@@ -170,10 +170,20 @@
AllMockObjectStores.append(store)
return store
-class ModelAccessor:
- def check_db_connection_ok(self):
+class ModelAccessor(object):
+ def check_db_connection_okay(self):
return True
+ def connection_close(self):
+ pass
+
+ def journal_object(self, *args, **kwargs):
+ pass
+
+ def obj_exists(self, o):
+ # gRPC will default id to '0' for uninitialized objects
+ return (o.id is not None) and (o.id != 0)
+
def fetch_pending(self, model, deleted = False):
num = random.randint(1, 5)
object_list = []
@@ -200,6 +210,19 @@
def get_model_class(self, classname):
return globals()[classname]
+ def has_model_class(self, classname):
+ return classname in globals()
+
+ def __getattr__(self, name):
+ """ Wrapper for getattr to facilitate retrieval of classes """
+ has_model_class = self.__getattribute__("has_model_class")
+ get_model_class = self.__getattribute__("get_model_class")
+ if has_model_class(name):
+ return get_model_class(name)
+
+ # Default behaviour
+ return self.__getattribute__(name)
+
model_accessor = ModelAccessor()
class ObjectSet(object):