def testBatchCRUD(self): dogs = [] for i in range(0, 3): s = ParaObject() s.type = self.dogsType s["foo"] = "bark!" dogs.append(s) self.assertIs(len(self.pc.createAll(None)), 0) l1 = self.pc.createAll(dogs) self.assertEqual(3, len(l1)) self.assertIsNotNone(l1[0].id) self.assertIs(len(self.pc.readAll(None)), 0) nl = [] self.assertIs(len(self.pc.readAll(nl)), 0) nl.append(l1[0].id) nl.append(l1[1].id) nl.append(l1[2].id) l2 = self.pc.readAll(nl) self.assertEqual(3, len(l2)) self.assertEqual(l1[0].id, l2[0].id) self.assertEqual(l1[1].id, l2[1].id) self.assertIsNotNone(l2[0]["foo"]) self.assertEqual("bark!", l2[0]["foo"]) self.assertIs(len(self.pc.updateAll(None)), 0) part1 = ParaObject(l1[0].id) part2 = ParaObject(l1[1].id) part3 = ParaObject(l1[2].id) part1.type = self.dogsType part2.type = self.dogsType part3.type = self.dogsType part1["custom"] = "prop" part1.name = "NewName1" part2.name = "NewName2" part3.name = "NewName3" l3 = self.pc.updateAll([part1, part2, part3]) self.assertIsNotNone(l3[0]["custom"]) self.assertEqual(self.dogsType, l3[0].type) self.assertEqual(self.dogsType, l3[1].type) self.assertEqual(self.dogsType, l3[2].type) self.assertEqual(part1.name, l3[0].name) self.assertEqual(part2.name, l3[1].name) self.assertEqual(part3.name, l3[2].name) self.pc.deleteAll(nl) sleep(1) l4 = self.pc.list(self.dogsType) self.assertIs(len(l4), 0) self.assertIs(self.dogsType in self.pc.getApp()["datatypes"].values(), True)
def testList(self): cats = [] for i in range(0, 3): s = ParaObject(self.catsType + str(i)) s.type = self.catsType cats.append(s) self.pc.createAll(cats) sleep(1) self.assertIs(len(self.pc.list(None)), 0) self.assertIs(len(self.pc.list("")), 0) list1 = self.pc.list(self.catsType) self.assertIsNot(len(list1), 0) self.assertEqual(3, len(list1)) self.assertEqual(isinstance(list1[0], ParaObject), True) list2 = self.pc.list(self.catsType, Pager(limit=2)) self.assertIsNot(len(list2), 0) self.assertEqual(2, len(list2)) nl = [cats[0].id, cats[1].id, cats[2].id] self.pc.deleteAll(nl) self.assertIs(self.catsType in self.pc.getApp()["datatypes"].values(), True)
def testGetObjectURI(self): o1 = ParaObject() self.assertEqual(o1.getObjectURI(), "/sysprop") o1.type = "dog" self.assertEqual(o1.getObjectURI(), "/dog") o1.id = "123" self.assertEqual(o1.getObjectURI(), "/dog/123") o2 = ParaObject(id_="123 56", type_="dog 2") self.assertEqual(o2.getObjectURI(), "/dog%202/123%2056")
def testValidationConstraints(self): # Validations string kittenType = "kitten" constraints = self.pc.validationConstraints() self.assertIsNot(len(constraints), 0) self.assertIs("app" in constraints.keys(), True) self.assertIs("user" in constraints.keys(), True) constraint = self.pc.validationConstraints("app") self.assertIsNot(len(constraint), 0) self.assertIs("app" in constraint.keys(), True) self.assertEqual(1, len(constraint)) self.pc.addValidationConstraint(kittenType, "paws", Constraint.required()) constraint = self.pc.validationConstraints(kittenType) self.assertIs("paws" in constraint[kittenType].keys(), True) ct = ParaObject("felix") ct.type = kittenType # validation fails ct2 = self.pc.create(ct) self.assertIsNone(ct2) ct["paws"] = "4" self.assertIsNotNone(self.pc.create(ct)) self.pc.removeValidationConstraint(kittenType, "paws", "required") constraint = self.pc.validationConstraints(kittenType) self.assertIs(kittenType in constraint.keys(), False) # votes self.assertIs(self.pc.voteUp(ct, self.u.id), True) self.assertIsNot(self.pc.voteUp(ct, self.u.id), True) self.assertIs(self.pc.voteDown(ct, self.u.id), True) self.assertIs(self.pc.voteDown(ct, self.u.id), True) self.assertIsNot(self.pc.voteDown(ct, self.u.id), True) self.pc.delete(ct) self.pc.delete(ParaObject("vote:" + self.u.id + ":" + ct.id, "vote")) self.assertIs(self.pc.getServerVersion().startswith("1"), True) self.assertNotEqual("unknown", self.pc.getServerVersion())
def testCRUD(self): self.assertIsNotNone(self.pc.create(ParaObject())) t1 = self.pc.create(ParaObject("test1", "tag")) t1["tag"] = "test1" self.assertIsNotNone(t1) self.assertIsNone(self.pc.read(None, None)) self.assertIsNone(self.pc.read("", "")) tr_id = self.pc.read(id_=t1.id) self.assertIsNotNone(tr_id) self.assertIsNotNone(tr_id.timestamp) self.assertEqual(t1.tag, tr_id.tag) tr = self.pc.read(t1.type, t1.id) self.assertIsNotNone(tr) self.assertIsNotNone(tr.timestamp) self.assertEqual(t1["tag"], tr["tag"]) tr["count"] = 15 tu = self.pc.update(tr) self.assertIsNone(self.pc.update(ParaObject("None"))) self.assertIsNotNone(tu) self.assertEqual(tu["count"], tr["count"]) self.assertIsNotNone(tu.updated) s = ParaObject() s.type = self.dogsType s["foo"] = "bark!" s = self.pc.create(s) dog = self.pc.read(self.dogsType, s.id) self.assertIsNotNone(dog["foo"]) self.assertEqual("bark!", dog["foo"]) self.pc.delete(t1) self.pc.delete(dog) self.assertIsNone(self.pc.read(tr.type, tr.id))