def test_bad(self): c = Connector() stores = [self.store1, self.store2] w = self.create("public.data", "test.ignore", stores) w.commit() doc = w.getDoc() rev = w.getRev() with c.update(doc, rev, stores=[self.store1]) as w: w.write('FILE', 'first') w.commit() rev1 = w.getRev() with c.update(doc, rev, stores=[self.store2]) as w: w.write('FILE', 'second') w.commit() rev2 = w.getRev() self.failIfEqual(rev, rev1) self.failIfEqual(rev, rev2) self.failIfEqual(rev1, rev2) self.assertRaises(IOError, c.sync, doc) l = c.lookup_doc(doc) self.assertEqual(len(l.revs()), 2) self.assertEqual(l.rev(self.store1), rev1) self.assertEqual(l.rev(self.store2), rev2)
def test_suspend_multi(self): c = Connector() (doc, rev1, rev_s1) = self.createSuspendDoc() with c.update(doc, rev1) as w: w.writeAll('FILE', 'forward') w.commit() rev2 = w.getRev() with c.update(doc, rev2) as w: w.writeAll('FILE', 'Hail to the king, baby!') w.suspend() rev_s2 = w.getRev() l = c.lookup_doc(doc) self.assertEqual(l.revs(), [rev2]) self.assertEqual(len(l.preRevs()), 2) self.assertTrue(rev_s1 in l.preRevs()) self.assertTrue(rev_s2 in l.preRevs()) s = c.stat(rev_s1) self.assertEqual(s.parents(), [rev1]) s = c.stat(rev_s2) self.assertEqual(s.parents(), [rev2]) self.assertRevContent(rev1, {'FILE' : 'ok'}) self.assertRevContent(rev_s1, {'FILE' : 'update'}) self.assertRevContent(rev2, {'FILE' : 'forward'}) self.assertRevContent(rev_s2, {'FILE' : 'Hail to the king, baby!'})
def test_merge(self): c = Connector() stores = [self.store1, self.store2] w = self.create("public.data", "test.ignore", stores) w.commit() doc = w.getDoc() rev = w.getRev() with c.update(doc, rev, stores=[self.store1]) as w: w.write('FILE', 'first') w.commit() rev1 = w.getRev() with c.update(doc, rev, stores=[self.store2]) as w: w.write('FILE', 'second') w.commit() rev2 = w.getRev() with c.update(doc, rev1, stores=stores) as w: w.setParents([rev1, rev2]) w.commit() rev3 = w.getRev() self.assertTrue(c.sync(doc) == rev3) l = c.lookup_doc(doc) self.assertEqual(l.revs(), [rev3]) self.assertEqual(set(c.lookup_rev(rev)), set(stores)) self.assertEqual(set(c.lookup_rev(rev1)), set(stores)) self.assertEqual(set(c.lookup_rev(rev2)), set(stores)) self.assertEqual(set(c.lookup_rev(rev3)), set(stores))
def test_suspend_multi(self): c = Connector() (doc, rev1, rev_s1) = self.createSuspendDoc() with c.update(doc, rev1) as w: w.writeAll('FILE', 'forward') w.commit() rev2 = w.getRev() with c.update(doc, rev2) as w: w.writeAll('FILE', 'Hail to the king, baby!') w.suspend() rev_s2 = w.getRev() l = c.lookup_doc(doc) self.assertEqual(l.revs(), [rev2]) self.assertEqual(len(l.preRevs()), 2) self.assertTrue(rev_s1 in l.preRevs()) self.assertTrue(rev_s2 in l.preRevs()) s = c.stat(rev_s1) self.assertEqual(s.parents(), [rev1]) s = c.stat(rev_s2) self.assertEqual(s.parents(), [rev2]) self.assertRevContent(rev1, {'FILE': 'ok'}) self.assertRevContent(rev_s1, {'FILE': 'update'}) self.assertRevContent(rev2, {'FILE': 'forward'}) self.assertRevContent(rev_s2, {'FILE': 'Hail to the king, baby!'})
def test_forget(self): c = Connector() (doc, rev1, rev_s1) = self.createSuspendDoc() with c.update(doc, rev1) as w: w.writeAll('FILE', 'forward') w.commit() rev2 = w.getRev() with c.update(doc, rev2) as w: w.writeAll('FILE', 'Hail to the king, baby!') w.suspend() rev_s2 = w.getRev() self.assertRaises(IOError, c.forget, doc, rev1) c.forget(doc, rev_s1) l = c.lookup_doc(doc) self.assertEqual(l.revs(), [rev2]) self.assertEqual(l.preRevs(), [rev_s2])
def createSuspendDoc(self): c = Connector() w = self.create("test.format", "test.ignore", [self.store1]) w.writeAll('FILE', 'ok') w.commit() doc = w.getDoc() rev1 = w.getRev() with c.update(doc, rev1) as w: w.writeAll('FILE', 'update') w.suspend() rev2 = w.getRev() return (doc, rev1, rev2)
def test_update_change(self): c = Connector() w = self.create("public.data", "test.foo", [self.store1]) w.commit() doc = w.getDoc() rev1 = w.getRev() with c.update(doc, rev1, "test.baz") as w: w.commit() rev2 = w.getRev() s = c.stat(rev1) self.assertEqual(s.creator(), "test.foo") s = c.stat(rev2) self.assertEqual(s.creator(), "test.baz")
def test_update_keep(self): c = Connector() w = self.create("test.format.foo", "test.ignore", [self.store1]) self.assertEqual(w.getType(), "test.format.foo") w.commit() doc = w.getDoc() rev1 = w.getRev() with c.update(doc, rev1, "test.ignore") as w: self.assertEqual(w.getType(), "test.format.foo") w.write('FILE', 'update') w.commit() rev2 = w.getRev() s = c.stat(rev1) self.assertEqual(s.type(), "test.format.foo") s = c.stat(rev2) self.assertEqual(s.type(), "test.format.foo")
def test_good(self): c = Connector() stores = [self.store1, self.store2] w = self.create("public.data", "test.ignore", stores) w.commit() doc = w.getDoc() rev = w.getRev() with c.update(doc, rev, stores=[self.store1]) as w: w.write('FILE', 'update') w.commit() rev = w.getRev() self.assertTrue(c.sync(doc) == rev) l = c.lookup_doc(doc) self.assertEqual(len(l.revs()), 1) self.assertEqual(l.rev(self.store1), rev) self.assertEqual(l.rev(self.store2), rev)