def testAddColumn(self):
     column = Midgard.SqlQueryColumn(
         queryproperty=Midgard.QueryProperty(property="title"),
         name="title",
         qualifier="t1")
     # Expect exception in case of error
     self.select.add_column(column)
Ejemplo n.º 2
0
    def testCreateWorkspaceAtPath(self):
        # If element in path is missed, manager should create it
        wa = Midgard.Workspace(name="testing")
        self.assertTrue(self.manager.create_workspace(wa, "/devel"))

        wb = Midgard.Workspace(name="stable")
        self.assertTrue(self.manager.create_workspace(wb, "/devel/testing"))
Ejemplo n.º 3
0
 def createWorkspaces(self):
   ws = Midgard.Workspace()
   self.manager.get_workspace_by_path(ws, "/Foo/Bar")
   ws_bar = Midgard.Workspace(name = "FooBar")
   self.manager.create_workspace(ws_bar, "/Foo/Bar")
   ws_baz = Midgard.Workspace(name = "FooBaz")
   self.manager.create_workspace(ws_baz, "/Foo/Baz")
Ejemplo n.º 4
0
 def testSelectAllPersons(self):
   st = Midgard.QueryStorage(dbclass = "midgard_person")
   qs = Midgard.QuerySelect(connection = self.mgd, storage = st)
   qs.execute()
   objects = qs.list_objects()
   # Expect admin person and Smith family
   self.assertEqual(len(objects), 4);
 def testCreate_03_ObjectInWorkspace_FooBarFooBar(self):
     # set new workspace so we can query object from there
     workspace = Midgard.Workspace()
     self.manager.get_workspace_by_path(workspace, "/Foo/Bar/FooBar")
     self.mgd.set_workspace(workspace)
     bookstores = BookStoreQuery.findByName(self.mgd, self.bookstoreName)
     self.assertEqual(len(bookstores), 0)
     bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store",
                                        None)
     bookstore.set_property("name", self.bookstoreName)
     bookstore.set_property("extra", self.extraFooBarFooBar)
     self.assertTrue(bookstore.create())
     # test created object
     bookstores = BookStoreQuery.findByName(self.mgd, self.bookstoreName)
     self.assertEqual(len(bookstores), 1)
     bookstore = bookstores[0]
     self.assertEqual(bookstore.get_property("extra"),
                      self.extraFooBarFooBar)
     # set default workspace and get object
     workspace = Midgard.Workspace()
     self.manager.get_workspace_by_path(workspace, "/Foo")
     self.mgd.set_workspace(workspace)
     bookstores = BookStoreQuery.findByName(self.mgd, self.bookstoreName)
     self.assertEqual(len(bookstores), 1)
     bookstore = bookstores[0]
     self.assertEqual(bookstore.get_property("extra"), self.extraFoo)
 def testDelete_04_ObjectInWorkspace_FooBarFooBar(self):
     # set /Foo/Bar/FooBar workspace and get object
     workspace = Midgard.Workspace()
     self.manager.get_workspace_by_path(workspace, "/Foo/Bar/FooBar")
     self.mgd.set_workspace(workspace)
     bookstores = BookStoreQuery.findByName(self.mgd, self.bookstoreName)
     self.assertEqual(len(bookstores), 1)
     bookstore = bookstores[0]
     # purge
     self.assertTrue(bookstore.purge(False))
     # do not expect object from /Foo/Bar/FooBar
     bookstores = BookStoreQuery.findByName(self.mgd, self.bookstoreName)
     self.assertEqual(len(bookstores), 0)
     # expect object from /Foo/Bar
     workspace = Midgard.Workspace()
     self.manager.get_workspace_by_path(workspace, "/Foo/Bar")
     self.mgd.set_workspace(workspace)
     bookstores = BookStoreQuery.findByName(self.mgd, self.bookstoreName)
     self.assertEqual(len(bookstores), 1)
     # expect object from /Foo
     workspace = Midgard.Workspace()
     self.manager.get_workspace_by_path(workspace, "/Foo")
     self.mgd.set_workspace(workspace)
     bookstores = BookStoreQuery.findByName(self.mgd, self.bookstoreName)
     self.assertEqual(len(bookstores), 1)
Ejemplo n.º 7
0
 def testJoin(self):
   storage_one = Midgard.QueryStorage(dbclass = "midgard_person")
   storage_two = Midgard.QueryStorage(dbclass = "midgard_person")
   qs = Midgard.QuerySelect(connection = self.mgd, storage = storage_one)
   group = Midgard.QueryConstraintGroup(grouptype = "AND")
   constraint_one = Midgard.QueryConstraint(
     property = Midgard.QueryProperty(property = "firstname"),
     operator = "=",
     holder = Midgard.QueryValue.create_with_value("Alice")
   )
   constraint_two = Midgard.QueryConstraint(
     property = Midgard.QueryProperty(property = "firstname", storage = storage_two),
     operator = "=",
     holder = Midgard.QueryValue.create_with_value("John")
   )
   group.add_constraint(constraint_one)
   group.add_constraint(constraint_two)
   qs.set_constraint(group)
   qs.add_join(
     "LEFT",
     Midgard.QueryProperty(property = "lastname"),
     Midgard.QueryProperty(property = "lastname", storage = storage_two)
   )
   qs.execute()
   # We expect Alice person only
   self.assertEqual(qs.get_results_count(), 1)
   objects = qs.list_objects()
   self.assertEqual(objects[0].get_property("firstname"), "Alice")
 def setUp(self):
   if self.mgd == None:
     self.mgd = TestConnection.openConnection()
   self.mgd.beginTransaction()  
   if self.bookstore_one is None:
     self.bookstore_one = Midgard.Object.factory(self.mgd, "gir_test_book_store", None)
     self.bookstore_one.set_property("name", self.bookstore_one_name)
     self.bookstore_one.create()
   if self.bookstore_two is None:  
     self.bookstore_two = Midgard.Object.factory(self.mgd, "gir_test_book_store", None)
     self.bookstore_two.set_property("name", self.bookstore_two_name)
     self.bookstore_two.create()
   if self.reference_one is None:
     self.reference_one = Midgard.ObjectReference(id = Midgard.Guid.new(self.mgd), name = "TestReferenceOne")
   if self.reference_two is None:
     self.reference_two = Midgard.ObjectReference(id = Midgard.Guid.new(self.mgd), name = "TestReferenceTwo")
   if self.job_one is None:
     self.job_one = Midgard.SqlContentManagerJobDelete(
         connection = self.mgd,
         contentobject = self.bookstore_one,
         reference = self.reference_one)
   if self.job_two is None:
     self.job_two = Midgard.SqlContentManagerJobDelete(
         connection = self.mgd,
         contentobject = self.bookstore_two,
         reference = self.reference_two)
   self.callback_msg_start = "TODO START"
   self.callback_msg_end = "TODO END"
   self.async_callback_msg_end_one = "TODO ASYNC ONE END"
   self.async_callback_msg_end_two = "TODO ASYNC TWO END"
Ejemplo n.º 9
0
 def createWorkspaces(self):
     ws_foo = Midgard.Workspace(name="Foo")
     self.manager.create_workspace(ws_foo, "")
     ws_bar = Midgard.Workspace(name="Bar")
     self.manager.create_workspace(ws_bar, "/Foo")
     ws_baz = Midgard.Workspace(name="Baz")
     self.manager.create_workspace(ws_baz, "/Foo")
Ejemplo n.º 10
0
 def testGetWorkspaceByPath(self):
     wa = Midgard.Workspace()
     self.assertTrue(self.manager.get_workspace_by_path(wa, "/devel"))
     wb = Midgard.Workspace()
     self.assertTrue(
         self.manager.get_workspace_by_path(wb, "/devel/testing"))
     wc = Midgard.Workspace()
     self.assertTrue(
         self.manager.get_workspace_by_path(wc, "/devel/testing/stable"))
Ejemplo n.º 11
0
 def setUp(self):
     if self.mgd is None:
         self.mgd = TestConnection.openConnection()
     if self.column is None:
         self.queryproperty = Midgard.QueryProperty(property="title")
         self.column = Midgard.SqlQueryColumn(
             queryproperty=self.queryproperty,
             name="The title",
             qualifier="t1")
 def setUp(self):
     if self.mgd is None:
         self.mgd = TestConnection.openConnection()
         self.mgd.enable_workspace(True)
     if self.manager is None:
         self.manager = Midgard.WorkspaceManager(connection=self.mgd)
     ws = Midgard.Workspace()
     self.manager.get_workspace_by_path(ws, "/Foo")
     self.mgd.set_workspace(ws)
     self.mgd.beginTransaction()
 def addBookTitleConstraint(self):
     self.select.set_constraint(
         Midgard.SqlQueryConstraint(
             column=Midgard.SqlQueryColumn(
                 queryproperty=Midgard.QueryProperty(
                     property="title", storage=self.default_book_storage),
                 name=book_title_column,
                 qualifier=book_qualifier),
             operator="=",
             holder=Midgard.QueryValue.create_with_value(book_a_title)))
 def setUp(self):
     if self.mgd is None:
         self.mgd = TestConnection.openConnection()
     if self.select is None:
         self.select = Midgard.SqlQuerySelectData(connection=self.mgd)
     self.default_book_storage = Midgard.QueryStorage(
         dbclass="gir_test_book_crud")
     self.default_store_storage = Midgard.QueryStorage(
         dbclass="gir_test_book_store")
     self.createStore()
Ejemplo n.º 15
0
 def findByName(mgd, name):
     storage = Midgard.QueryStorage(dbclass="gir_test_book_store")
     qs = Midgard.QuerySelect(connection=mgd, storage=storage)
     qs.toggle_read_only(False)
     qs.set_constraint(
         Midgard.QueryConstraint(
             property=Midgard.QueryProperty(property="name"),
             operator="=",
             holder=Midgard.QueryValue.create_with_value(name)))
     qs.execute()
     return qs.list_objects()
Ejemplo n.º 16
0
 def testSelectInvalidType(self): 
   st = Midgard.QueryStorage(dbclass = "NotExists")
   qs = Midgard.QuerySelect(connection = self.mgd, storage = st)
   # Check if we have GError 
   self.assertRaises(GObject.GError, qs.execute)
   # Check if we have correct domain 
   try:
     qs.execute()
   except GObject.GError as e:
     self.assertEqual(e.domain, "midgard-validation-error-quark")
     self.assertEqual(e.code, Midgard.ValidationError.TYPE_INVALID)
Ejemplo n.º 17
0
 def getQSForSmiths(self):
   st = Midgard.QueryStorage(dbclass = "midgard_person")
   qs = Midgard.QuerySelect(connection = self.mgd, storage = st)
   qs.set_constraint(
     Midgard.QueryConstraint(
       property = Midgard.QueryProperty(property = "lastname"),
       operator = "=",
       holder = Midgard.QueryValue.create_with_value("Smith")
     )
   )
   return qs
Ejemplo n.º 18
0
 def purgeSnippets(self):
     st = Midgard.QueryStorage(dbclass="midgard_snippet")
     qs = Midgard.QuerySelect(connection=self.mgd, storage=st)
     qs.execute()
     for s in qs.list_objects():
         s.purge(False)
     st = Midgard.QueryStorage(dbclass="midgard_snippetdir")
     qs = Midgard.QuerySelect(connection=self.mgd, storage=st)
     qs.execute()
     for s in qs.list_objects():
         s.purge(False)
 def getBook(self):
     st = Midgard.QueryStorage(dbclass="gir_test_book_crud")
     qs = Midgard.QuerySelect(connection=self.mgd, storage=st)
     qs.set_constraint(
         Midgard.QueryConstraint(
             property=Midgard.QueryProperty(property="title"),
             operator="=",
             holder=Midgard.QueryValue.create_with_value(
                 "The Hoy Grail and Attachments")))
     qs.execute()
     res = qs.list_objects()
     return res[0]
 def addColumns(self):
     storage = Midgard.QueryStorage(dbclass="midgard_person")
     column = Midgard.SqlQueryColumn(queryproperty=Midgard.QueryProperty(
         property="firstname", storage=storage),
                                     name="name",
                                     qualifier="p")
     self.select.add_column(column)
     column = Midgard.SqlQueryColumn(queryproperty=Midgard.QueryProperty(
         property="lastname", storage=storage),
                                     name="lastname",
                                     qualifier="p")
     self.select.add_column(column)
Ejemplo n.º 21
0
    def testGetPath(self):
        ws = Midgard.Workspace()
        self.manager.get_workspace_by_path(ws, "/Foo")
        self.assertEqual(ws.get_path(), "/Foo")

        ws = Midgard.Workspace()
        self.manager.get_workspace_by_path(ws, "/Foo/Bar")
        self.assertEqual(ws.get_path(), "/Foo/Bar")

        ws = Midgard.Workspace()
        self.manager.get_workspace_by_path(ws, "/Foo/Baz")
        self.assertEqual(ws.get_path(), "/Foo/Baz")
 def addColumns(self):
     storage = self.default_book_storage
     column = Midgard.SqlQueryColumn(queryproperty=Midgard.QueryProperty(
         property="title", storage=storage),
                                     name="btitle",
                                     qualifier=book_qualifier)
     self.select.add_column(column)
     column = Midgard.SqlQueryColumn(queryproperty=Midgard.QueryProperty(
         property="id", storage=storage),
                                     name="sid",
                                     qualifier=book_qualifier)
     self.select.add_column(column)
Ejemplo n.º 23
0
 def testSelectNothing(self):
   st = Midgard.QueryStorage(dbclass = "midgard_person")
   qs = Midgard.QuerySelect(connection = self.mgd, storage = st)
   qs.set_constraint(
     Midgard.QueryConstraint(
       property = Midgard.QueryProperty(property = "firstname"),
       operator = "=",
       holder = Midgard.QueryValue.create_with_value("Sir Lancelot")
     )
   )
   qs.execute()
   # Do not expect persons
   self.assertEqual(qs.get_results_count(), 0);
Ejemplo n.º 24
0
 def testSelectAsyncAllPersons(self):
   st = Midgard.QueryStorage(dbclass = "midgard_person")
   self.pool = Midgard.ExecutionPool(max_n_threads = 10)
   l = [] # Hold all executors in array to avoid implicit objects' destruction
   for i in range(0, 30):
     qs = Midgard.QuerySelect(connection = self.mgd, storage = st)
     qs.connect("execution-end", self.ExecutionAsyncEndCallback, i)
     self.pool.push(qs)
     l.append(qs)
   # Emulate main loop - ugly   
   time.sleep(1)
   self.pool = None
   self.assertEqual(self.async_execution_callbacks_count, 30)
  def testValidateConstraintGroup(self):
    storage = Midgard.QueryStorage(dbclass = "midgard_snippet")
    columnA = Midgard.SqlQueryColumn(
      queryproperty = Midgard.QueryProperty(property = "name", storage = storage),
      name = "a",
      qualifier = "tblA"
    )
    self.select.add_column(columnA)

    columnB = Midgard.SqlQueryColumn(
      queryproperty = Midgard.QueryProperty(property = "code", storage = storage),
      name = "b",
      qualifier = "tblA"
    )
    self.select.add_column(columnB)

    cg = Midgard.QueryConstraintGroup(grouptype = "AND")
    cg.add_constraint(
      Midgard.SqlQueryConstraint(
        column = columnA,
        operator = "<>",
        holder = Midgard.QueryValue.create_with_value("")
      )
    )
    cg.add_constraint(
      Midgard.SqlQueryConstraint(
        column = columnB,
        operator = "<>",
        holder = Midgard.QueryValue.create_with_value("")
      )
    )

    self.select.set_constraint(cg)
    # Validate constraints during execution
    self.select.execute()
    def prepareJoin(self):
        self.addStoreColumns()

        # Add book and store id required for join
        store_storage = self.default_store_storage
        column = Midgard.SqlQueryColumn(queryproperty=Midgard.QueryProperty(
            property="id", storage=store_storage),
                                        name="store_id",
                                        qualifier="bookstore")
        self.select.add_column(column)

        column = Midgard.SqlQueryColumn(queryproperty=Midgard.QueryProperty(
            property="store", storage=self.default_book_storage),
                                        name=book_store_id,
                                        qualifier=book_qualifier)
        self.select.add_column(column)

        self.select.add_join(
            "INNER",
            Midgard.SqlQueryColumn(name=book_store_id,
                                   queryproperty=Midgard.QueryProperty(
                                       property="store",
                                       storage=self.default_book_storage),
                                   qualifier=book_qualifier),
            Midgard.SqlQueryColumn(name="store_id",
                                   queryproperty=Midgard.QueryProperty(
                                       property="id",
                                       storage=self.default_store_storage),
                                   qualifier=book_store_qualifier))
Ejemplo n.º 27
0
    def __init__(self):
        self._log = None
        self.config = dict(
            dbtype = "SQLite",
            database = "midgardmvc"
        )
        
        self._connected = False

        print "Call Midgard.init() in better place"
        Midgard.init()

        self._mgd_config = Midgard.Config()
        self._connection = Midgard.Connection()
 def purgeStore(self):
     tr = Midgard.Transaction(connection=self.mgd)
     tr.begin()
     st = Midgard.QueryStorage(dbclass="gir_test_book_crud")
     qs = Midgard.QuerySelect(connection=self.mgd, storage=st)
     qs.execute()
     for s in qs.list_objects():
         s.purge(False)
     st = Midgard.QueryStorage(dbclass="gir_test_book_store")
     qs = Midgard.QuerySelect(connection=self.mgd, storage=st)
     qs.execute()
     for s in qs.list_objects():
         s.purge(False)
     tr.commit()
 def testExecuteInvalidQuery(self):
     self.addColumns()
     self.select.set_constraint(
         Midgard.SqlQueryConstraint(
             column=Midgard.SqlQueryColumn(
                 queryproperty=Midgard.QueryProperty(property="title"),
                 qualifier=book_qualifier),
             operator="=",
             holder=Midgard.QueryValue.create_with_value(book_a_title)))
     try:
         self.select.execute()
     except GObject.GError as e:
         self.assertEqual(e.domain, "midgard-execution-error-quark")
         self.assertEqual(e.code, Midgard.ValidationError.TYPE_INVALID)
  def testZExecuteAsync(self):
    pool = Midgard.ExecutionPool(max_n_threads = 2)
    self.job_one.connect("execution-end", self.executionEndCallbackAsyncOne, None)
    self.job_two.connect("execution-end", self.executionEndCallbackAsyncTwo, None)
    pool.push(self.job_one)
    pool.push(self.job_two)
    time.sleep(1)
    pool = None

    self.assertEqual(self.async_callback_msg_end_one, "DONE END ASYNC ONE")
    self.assertEqual(self.async_callback_msg_end_two, "DONE END ASYNC TWO")

    deleted_one = self.bookstore_one.get_property("metadata").get_property("deleted")
    self.assertTrue(deleted_one)
    deleted_two = self.bookstore_two.get_property("metadata").get_property("deleted")
    self.assertTrue(deleted_two)
    
    bookstores = BookStoreQuery.findByName(self.mgd, self.bookstore_one_name)
    self.assertEqual(len(bookstores), 0)
    bookstores = BookStoreQuery.findByName(self.mgd, self.bookstore_two_name)
    self.assertEqual(len(bookstores), 0)

    self.assertEqual(self.job_one.is_running(), False)
    self.assertEqual(self.job_one.is_failed(), False)
    self.assertEqual(self.job_one.is_executed(), True)
    self.assertEqual(self.job_two.is_running(), False)
    self.assertEqual(self.job_two.is_failed(), False)
    self.assertEqual(self.job_two.is_executed(), True)
  def testCreate(self):
    obj = self.getNewBook()
   
    title = "The Holly Grail"
    author = "Sir Lancelot"
    price = 999.999
    serial = self.createGuid()
    edition = 1
    sold = False
    description = "The true story of white rabbit"

    obj.set_property("title", title)
    obj.set_property("author", author)
    obj.set_property("price", price)
    obj.set_property("serial", serial)
    obj.set_property("edition", edition)
    obj.set_property("sold", sold)
    obj.set_property("description", description)
 
    self.assertTrue(obj.create())
    self.assertTrue(Midgard.is_guid(obj.get_property("guid")))
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsInstance(new_obj, Midgard.Object)
    self.assertEqual(new_obj.get_property("title"), title)
    self.assertEqual(new_obj.get_property("author"), author)
    self.assertEqual(round(new_obj.get_property("price"), 3), price) # FIXME , it should be fixed in core
    self.assertEqual(new_obj.get_property("serial"), serial)
    self.assertEqual(new_obj.get_property("edition"), edition)
    self.assertEqual(new_obj.get_property("sold"), sold)
    self.assertEqual(new_obj.get_property("description"), description)

    # TODO, metadata

    # Cleanup 
    obj.purge(False)
    def createStore(self):
        tr = Midgard.Transaction(connection=self.mgd)
        tr.begin()

        sdirA = Midgard.Object.factory(self.mgd, "gir_test_book_store", None)
        sdirA.set_property("name", "Bookstore")
        self.assertTrue(sdirA.create())
        idA = sdirA.get_property("id")

        sA = Midgard.Object.factory(self.mgd, "gir_test_book_crud", None)
        sA.set_property("title", book_a_title)
        sA.set_property("edition", 1)
        sA.set_property("store", idA)
        self.assertTrue(sA.create())

        sB = Midgard.Object.factory(self.mgd, "gir_test_book_crud", None)
        sB.set_property("title", "Book B")
        sB.set_property("edition", 2)
        sB.set_property("store", idA)
        self.assertTrue(sB.create())

        sC = Midgard.Object.factory(self.mgd, "gir_test_book_crud", None)
        sC.set_property("title", "Book C")
        sC.set_property("edition", 3)
        sC.set_property("store", idA)
        self.assertTrue(sC.create())

        tr.commit()
  def testPurge(self):
    obj = self.getNewBook()    
    obj.set_property("title", "The book to delete")

    self.assertTrue(obj.create())
    self.assertTrue(Midgard.is_guid(obj.get_property("guid")))
    self.assertTrue(obj.purge(False))

    # TODO metadata
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsNone(new_obj)
Ejemplo n.º 34
0
 def init_midgard(self):
     print("Connecting to midgard")
     Midgard.init()
     self.mgd = Midgard.Connection()
     self.mgd.open_config(DaemonConfig())
     print("... DONE")
Ejemplo n.º 35
0
 def __init__(self):
     Midgard.init()
     self.mgd = Midgard.Connection()
     self.mgd.open_config(DaemonConfig())
Ejemplo n.º 36
0
from gi.repository import Midgard

# Initialize types in GType system */
Midgard.init()

# Read configuration file
config = Midgard.Config()
config.read_file_at_path("/tmp/Midgard2CR/midgard2.conf")

# Establish connection
mgd = Midgard.Connection()
mgd.open_config(config)

# Get object by specified path
nt_folder = Midgard.SchemaObjectFactory.get_object_by_path(mgd, "nt_folder", "/jackalope/tests_general_base")

# Read jcr:primaryType
type = nt_folder.get_property("jcr-primaryType")
print(type)

ref = Midgard.ReflectorProperty(dbclass="nt_folder")
print(ref.get_user_value("jcr-created", "isAutoCreated"))

Midgard.close()
Ejemplo n.º 37
0
 def __init__(self):
   Midgard.init()
   Midgard.Connection.__init__(self)
 def createGuid(self):
   try:
     guid = Midgard.Guid.new(self.mgd)
   except AttributeError:
     guid = Midgard.guid_new(self.mgd)
   return guid