コード例 #1
0
 def test_make_and_type_object(self):
     a = create_object(s, "A", path=domain_id + "/a")
     self.assertEqual(a.create, "created")
     
     b = create_object(s, "B", path=domain_id + "/b", included_types=["/people/person"])
     
     q = { "id" : b.id, "type" : [{"id" : None}] }
     types = [x["id"] for x in s.mqlread(q)["type"]]
     self.assertEqual("/common/topic" in types, True)
     self.assertEqual("/people/person" in types, True)
     self.assertEqual("/film/actor" in types, False)
     
     add_type_to_object(s, b.id, "/film/film_genre")
     
     types = [x["id"] for x in s.mqlread(q)["type"]]
     
     self.assertEqual("/film/film_genre" in types, True)
     self.assertEqual("/media_common/media_genre" in types, True)
コード例 #2
0
 def test_move_object(self):
     old = create_object(s, "old", domain_id + "/old")
     move_object(s, domain_id + "/old", domain_id + "/new")
     is_old = { "id" : domain_id + "/old", "key" : [{"value" : None}]}
     is_new = { "id" : domain_id + "/new", "key" : [{"value" : None}]}
     s.touch()
     o = s.mqlread(is_old)
     n = s.mqlread(is_new)
     # we don't just check to see if the id exists, as freebase caches id -> guid lookups
     if o:
         self.assertEqual(len([b for b in o["key"] if b["value"] == "old"]), 0)
     self.assertEqual(len([b for b in n["key"]]), 1)
コード例 #3
0
    def test_make_and_type_object(self):
        a = create_object(s, "A", path=domain_id + "/a")
        self.assertEqual(a.create, "created")

        b = create_object(s,
                          "B",
                          path=domain_id + "/b",
                          included_types=["/people/person"])

        q = {"id": b.id, "type": [{"id": None}]}
        types = [x["id"] for x in s.mqlread(q)["type"]]
        self.assertEqual("/common/topic" in types, True)
        self.assertEqual("/people/person" in types, True)
        self.assertEqual("/film/actor" in types, False)

        add_type_to_object(s, b.id, "/film/film_genre")

        types = [x["id"] for x in s.mqlread(q)["type"]]

        self.assertEqual("/film/film_genre" in types, True)
        self.assertEqual("/media_common/media_genre" in types, True)
コード例 #4
0
 def test_move_object(self):
     old = create_object(s, "old", domain_id + "/old")
     move_object(s, domain_id + "/old", domain_id + "/new")
     is_old = {"id": domain_id + "/old", "key": [{"value": None}]}
     is_new = {"id": domain_id + "/new", "key": [{"value": None}]}
     s.touch()
     o = s.mqlread(is_old)
     n = s.mqlread(is_new)
     # we don't just check to see if the id exists, as freebase caches id -> guid lookups
     if o:
         self.assertEqual(len([b for b in o["key"] if b["value"] == "old"]),
                          0)
     self.assertEqual(len([b for b in n["key"]]), 1)
コード例 #5
0
ファイル: mktype.py プロジェクト: XiliangSong/freebase-python
def cmd_mkobj(fb, id, typeid="/common/topic", name=""):
    """create a new object with a given type  -- EXPERIMENTAL
    %prog mkobj new_id typeid name

    create a new object with type typeid at the given
    namespace location.

    if present, name gives the display name of the new object.
    
    """
    id = fb.absid(id)

    return create_object(fb.mss, name=name, path=id, included_types=typeid, create="unless_exists")
コード例 #6
0
def cmd_mkobj(fb, id, typeid='/common/topic', name=''):
    """create a new object with a given type  -- EXPERIMENTAL
    %prog mkobj new_id typeid name

    create a new object with type typeid at the given
    namespace location.

    if present, name gives the display name of the new object.
    
    """
    id = fb.absid(id)

    return create_object(fb.mss,
                         name=name,
                         path=id,
                         included_types=typeid,
                         create="unless_exists")