def test_get_all_checkpoints(self): index = ["mydomain", "myxmlns"] self.addCleanup(lambda: [cp.delete() for cp in ExportSchema.get_all_checkpoints(index)]) schema1 = ExportSchema(index=index, timestamp=datetime.utcnow()) schema1.save() schema1_prime, = list(ExportSchema.get_all_checkpoints(index)) self.assert_docs_equal(schema1_prime, schema1) schema2 = ExportSchema(index=index, timestamp=datetime.utcnow()) schema2.save() schema1_prime, schema2_prime = list(ExportSchema.get_all_checkpoints(index)) self.assert_docs_equal(schema1_prime, schema1) self.assert_docs_equal(schema2_prime, schema2)
def test_get_last(self): indices = ["a string", ["a", "list"]] save_args = get_safe_write_kwargs() for index in indices: self.addCleanup( lambda idx: [cp.delete() for cp in ExportSchema.get_all_checkpoints(idx)], index) for index in indices: self.assertEqual(None, ExportSchema.last(index)) dt = datetime.utcnow() schema1 = ExportSchema(index=index, timestamp=dt) schema1.save(**save_args) self.assert_docs_equal(schema1, ExportSchema.last(index)) schema2 = ExportSchema(index=index, timestamp=dt + timedelta(seconds=1)) schema2.save(**save_args) self.assert_docs_equal(schema2, ExportSchema.last(index)) schema3 = ExportSchema(index=index, timestamp=dt - timedelta(seconds=1)) schema3.save(**save_args) # still schema2 (which has a later date than schema3) self.assert_docs_equal(schema2, ExportSchema.last(index))
def rebuild_schemas(index): """ Resets the schema for all checkpoints to the latest version based off the current document structure. Returns the number of checkpoints updated. """ db = ExportSchema.get_db() all_checkpoints = ExportSchema.get_all_checkpoints(index) config = ExportConfiguration(db, index, disable_checkpoints=True) latest = config.create_new_checkpoint() for cp in all_checkpoints: cp.schema = latest.schema cp.save() return len(all_checkpoints)
def test_get_last(self): indices = ["a string", ["a", "list"]] save_args = get_safe_write_kwargs() for index in indices: self.addCleanup( lambda idx: [cp.delete() for cp in ExportSchema.get_all_checkpoints(idx)], index ) for index in indices: self.assertEqual(None, ExportSchema.last(index)) dt = datetime.utcnow() schema1 = ExportSchema(index=index, timestamp=dt) schema1.save(**save_args) self.assert_docs_equal(schema1, ExportSchema.last(index)) schema2 = ExportSchema(index=index, timestamp=dt + timedelta(seconds=1)) schema2.save(**save_args) self.assert_docs_equal(schema2, ExportSchema.last(index)) schema3 = ExportSchema(index=index, timestamp=dt - timedelta(seconds=1)) schema3.save(**save_args) # still schema2 (which has a later date than schema3) self.assert_docs_equal(schema2, ExportSchema.last(index))