Beispiel #1
0
    def _do_test_read_mult(self):
        test_resource1_id,_  = self.resource_registry_service.create(Resource(name='test1'))
        test_resource2_id,_  = self.resource_registry_service.create(Resource(name='test2'))

        res_list = [test_resource1_id, test_resource2_id]

        objects = self.resource_registry_service.read_mult(res_list)

        for o in objects:
            self.assertIsInstance(o,Resource)
            self.assertTrue(o._id in res_list)
    def test_find_collection(self):
        res_id, _ = self.rr_cli.create(Resource(name='test_res'))
        collection_id = self.ims_cli.create_collection('test', [res_id])

        retval = self.ims_cli.find_collection(collection_name='test')
        self.assertTrue(retval[0] == collection_id)

        retval = self.ims_cli.find_collection(resource_ids=[res_id])
        self.assertTrue(retval[0] == collection_id)
    def test_create_collection(self):
        ims_cli = self.ims_cli
        rr_cli = self.rr_cli
        with self.assertRaises(BadRequest):
            ims_cli.create_collection('failing_collection')

        resources = [Resource(), Resource(), Resource()]
        resources = [rr_cli.create(i)[0] for i in resources]

        collection_id = ims_cli.create_collection('working_collection',
                                                  resources)

        collection = rr_cli.read(collection_id)
        collection_resources = ims_cli.list_collection_resources(collection_id,
                                                                 id_only=True)
        self.assertTrue(
            set(collection_resources) == set(resources),
            '%s != %s' % (set(collection_resources), set(resources)))
    def test_delete_collection(self):
        ims_cli = self.ims_cli
        rr_cli = self.rr_cli
        res = Resource()
        res_id, rev = rr_cli.create(res)

        collection_id = ims_cli.create_collection(name='test_collection',
                                                  resources=[res_id])

        ims_cli.delete_collection(collection_id)

        with self.assertRaises(NotFound):
            rr_cli.read(collection_id)
Beispiel #5
0
    def test_objstore_obj(self):
        # Create
        doc1 = Resource(name="String", alt_ids=["Some", "More"],
                        addl=dict(x=[1,2,3], y={}, z="Str"))
        doc2 = Resource(name=u"String\u20ac", alt_ids=[u"Some\u20ac", "More"],
                        addl=dict(x=[1,2,3], y={}, z="Str"))

        doc3_dict = doc2.__dict__.copy()
        doc3_dict.pop("type_")
        doc3 = Resource(**doc3_dict)

        doc4_dict = doc1.__dict__.copy()
        doc4_dict.pop("type_")
        doc4 = Resource(**doc4_dict)

        doc5_dict = doc2.__dict__.copy()
        doc5_dict.pop("type_")
        doc5 = Resource(**doc5_dict)

        did1, dv1 = self.os.create(doc1)
        self.assertTrue(did1)

        did2, dv2 = self.os.create(doc2)
        self.assertTrue(did2)

        did3n = create_simple_unique_id()
        did3, dv3 = self.os.create(doc3, object_id=did3n)
        self.assertEquals(did3, did3n)

        did4n, did5n = create_simple_unique_id(), create_simple_unique_id()
        res = self.os.create_mult([doc4, doc5], object_ids=[did4n, did5n])
        _, did4, dv4 = res[0]
        _, did5, dv5 = res[1]

        # Read
        all_doc_ids = [did1, did2, did3, did4, did5]
        docs = self.os.read_mult(all_doc_ids)
        self.assertEquals(len(docs), len(all_doc_ids))

        with self.assertRaises(NotFound):
            self.os.read_mult([did1, "NONEXISTING", did2])

        docs1 = self.os.read_mult([did1, "NONEXISTING", did2], strict=False)
        self.assertEquals(len(docs1), 3)
        self.assertEquals(docs1[1], None)

        docs2 = self.os.read_doc_mult([did1, "NONEXISTING", did2], strict=False)
        self.assertEquals(len(docs2), 3)
        self.assertEquals(docs2[1], None)

        doc1r = self.os.read(did1)
        self.assertIsInstance(doc1r, Resource)
        self.assertEquals(doc1r.addl["x"][1], 2)
        doc2r = self.os.read(did2)
        self.assertIsInstance(doc2r, Resource)
        self.assertEquals(type(doc2r.name), str)
        self.assertEquals(doc2r.name, u"String\u20ac".encode("utf8"))

        # Update
        doc1r.name = "BUZZ"

        doc1rc_dict = doc1r.__dict__.copy()
        doc1rc_dict.pop("type_")
        d1rv = doc1rc_dict.pop("_rev")
        d1id = doc1rc_dict.pop("_id")
        doc1rc = Resource(**doc1rc_dict)
        doc1rc["_rev"] = d1rv
        doc1rc["_id"] = d1id

        self.os.update(doc1r)
        with self.assertRaises(Conflict):
            doc1rc.name = "ZAMM"
            self.os.update(doc1rc)

        doc2r.name = u"BUZZ\u20ac"

        doc3r = self.os.read(did3)
        doc3r.name = u"BUZZ\u20ac"
        self.os.update_mult([doc2r, doc3r])

        # Delete
        self.os.delete(did1)
        self.os.delete(did2)
        self.os.delete(did3)

        self.os.delete_mult([did4, did5] )

        with self.assertRaises(NotFound):
            self.os.read(did1)
        with self.assertRaises(NotFound):
            self.os.read(did2)
        with self.assertRaises(NotFound):
            self.os.read(did3)
        with self.assertRaises(NotFound):
            self.os.read(did4)
        with self.assertRaises(NotFound):
            self.os.read(did5)
Beispiel #6
0
    def test_objstore_obj(self):
        # Create
        doc1 = Resource(name="String",
                        alt_ids=["Some", "More"],
                        addl=dict(x=[1, 2, 3], y={}, z="Str"))
        doc2 = Resource(name=u"String\u20ac",
                        alt_ids=[u"Some\u20ac", "More"],
                        addl=dict(x=[1, 2, 3], y={}, z="Str"))

        doc3_dict = doc2.__dict__.copy()
        doc3_dict.pop("type_")
        doc3 = Resource(**doc3_dict)

        doc4_dict = doc1.__dict__.copy()
        doc4_dict.pop("type_")
        doc4 = Resource(**doc4_dict)

        doc5_dict = doc2.__dict__.copy()
        doc5_dict.pop("type_")
        doc5 = Resource(**doc5_dict)

        did1, dv1 = self.os.create(doc1)
        self.assertTrue(did1)

        did2, dv2 = self.os.create(doc2)
        self.assertTrue(did2)

        did3n = create_simple_unique_id()
        did3, dv3 = self.os.create(doc3, object_id=did3n)
        self.assertEquals(did3, did3n)

        did4n, did5n = create_simple_unique_id(), create_simple_unique_id()
        res = self.os.create_mult([doc4, doc5], object_ids=[did4n, did5n])
        _, did4, dv4 = res[0]
        _, did5, dv5 = res[1]

        # Read
        all_doc_ids = [did1, did2, did3, did4, did5]
        docs = self.os.read_mult(all_doc_ids)
        self.assertEquals(len(docs), len(all_doc_ids))

        with self.assertRaises(NotFound):
            self.os.read_mult([did1, "NONEXISTING", did2])

        docs1 = self.os.read_mult([did1, "NONEXISTING", did2], strict=False)
        self.assertEquals(len(docs1), 3)
        self.assertEquals(docs1[1], None)

        docs2 = self.os.read_doc_mult([did1, "NONEXISTING", did2],
                                      strict=False)
        self.assertEquals(len(docs2), 3)
        self.assertEquals(docs2[1], None)

        doc1r = self.os.read(did1)
        self.assertIsInstance(doc1r, Resource)
        self.assertEquals(doc1r.addl["x"][1], 2)
        doc2r = self.os.read(did2)
        self.assertIsInstance(doc2r, Resource)
        self.assertEquals(type(doc2r.name), str)
        self.assertEquals(doc2r.name, u"String\u20ac".encode("utf8"))

        # Update
        doc1r.name = "BUZZ"

        doc1rc_dict = doc1r.__dict__.copy()
        doc1rc_dict.pop("type_")
        d1rv = doc1rc_dict.pop("_rev")
        d1id = doc1rc_dict.pop("_id")
        doc1rc = Resource(**doc1rc_dict)
        doc1rc["_rev"] = d1rv
        doc1rc["_id"] = d1id

        self.os.update(doc1r)
        with self.assertRaises(Conflict):
            doc1rc.name = "ZAMM"
            self.os.update(doc1rc)

        doc2r.name = u"BUZZ\u20ac"

        doc3r = self.os.read(did3)
        doc3r.name = u"BUZZ\u20ac"
        self.os.update_mult([doc2r, doc3r])

        # Delete
        self.os.delete(did1)
        self.os.delete(did2)
        self.os.delete(did3)

        self.os.delete_mult([did4, did5])

        with self.assertRaises(NotFound):
            self.os.read(did1)
        with self.assertRaises(NotFound):
            self.os.read(did2)
        with self.assertRaises(NotFound):
            self.os.read(did3)
        with self.assertRaises(NotFound):
            self.os.read(did4)
        with self.assertRaises(NotFound):
            self.os.read(did5)