def testComputedRemoved(self): db = get_db() db.save_doc({ '#export_tag': 'tag', 'tag': 'computed-test', 'p1': 'v1', 'computed_': { 'ignore': 'this stuff' } }, **get_safe_write_kwargs() ) config = ExportConfiguration(db, ['computed-test'], cleanup_fn=None) schema = config.get_latest_schema() self.assertTrue('computed_' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertTrue('computed_' in docs[0]) # check that it works both explicitly and by default explicit_config = ExportConfiguration(db, ['computed-test'], cleanup_fn=clear_computed) default_config = ExportConfiguration(db, ['computed-test']) for config in (explicit_config, default_config): schema = config.get_latest_schema() self.assertFalse('computed_' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertFalse('computed_' in docs[0])
def testAttachmentsRemoved(self): db = get_db() res = db.save_doc( { '#export_tag': 'tag', 'tag': 'attachments-test', 'p1': 'v1', }, **get_safe_write_kwargs()) doc = db.get(res['id']) doc['_attachments'] = { "attach.txt": { "content_type": "text/plain", "data": "some content", }, } db.save_doc(doc) config = ExportConfiguration(db, ['attachments-test'], cleanup_fn=None) schema = config.get_latest_schema() self.assertTrue('_attachments' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertTrue('_attachments' in docs[0]) # check that it works both explicitly and by default explicit_config = ExportConfiguration(db, ['attachments-test'], cleanup_fn=clear_attachments) default_config = ExportConfiguration(db, ['attachments-test']) for config in (explicit_config, default_config): schema = config.get_latest_schema() self.assertFalse('_attachments' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertFalse('_attachments' in docs[0])
def testAttachmentsRemoved(self): db = get_db() res = db.save_doc({ '#export_tag': 'tag', 'tag': 'attachments-test', 'p1': 'v1', }, **get_safe_write_kwargs() ) doc = db.get(res['id']) doc['_attachments'] = { "attach.txt": { "content_type": "text/plain", "data": "some content", }, } db.save_doc(doc) config = ExportConfiguration(db, ['attachments-test'], cleanup_fn=None) schema = config.get_latest_schema() self.assertTrue('_attachments' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertTrue('_attachments' in docs[0]) # check that it works both explicitly and by default explicit_config = ExportConfiguration(db, ['attachments-test'], cleanup_fn=clear_attachments) default_config = ExportConfiguration(db, ['attachments-test']) for config in (explicit_config, default_config): schema = config.get_latest_schema() self.assertFalse('_attachments' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertFalse('_attachments' in docs[0])
def testComputedRemoved(self): db = get_db() db.save_doc( { '#export_tag': 'tag', 'tag': 'computed-test', 'p1': 'v1', 'computed_': { 'ignore': 'this stuff' } }, **get_safe_write_kwargs()) config = ExportConfiguration(db, ['computed-test'], cleanup_fn=None) schema = config.get_latest_schema() self.assertTrue('computed_' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertTrue('computed_' in docs[0]) # check that it works both explicitly and by default explicit_config = ExportConfiguration(db, ['computed-test'], cleanup_fn=clear_computed) default_config = ExportConfiguration(db, ['computed-test']) for config in (explicit_config, default_config): schema = config.get_latest_schema() self.assertFalse('computed_' in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertFalse('computed_' in docs[0])
def build_latest_schema(schema_index): """ Build a schema, directly from the index. Also creates a saved checkpoint. """ from couchexport.export import ExportConfiguration db = Database(settings.COUCH_DATABASE) previous_export = ExportSchema.last(schema_index) try: current_seq = int(db.info()["update_seq"]) except ValueError: pass # we must be on bigcouch, so comparing seqs is useless else: if previous_export and not previous_export.is_bigcouch \ and int(previous_export.seq) > current_seq: # something weird happened (like the couch database changing) # better rebuild from scratch previous_export = None config = ExportConfiguration(db, schema_index, previous_export=previous_export) schema = config.get_latest_schema() if not schema: return None updated_checkpoint = config.create_new_checkpoint() return updated_checkpoint
def get_export_components(self, previous_export_id=None, filter=None): from couchexport.export import ExportConfiguration database = get_db() config = ExportConfiguration(database, self.index, previous_export_id, self.filter & filter) # get and checkpoint the latest schema updated_schema = config.get_latest_schema() export_schema_checkpoint = config.create_new_checkpoint() return config, updated_schema, export_schema_checkpoint
def testAttachmentsRemoved(self): db = get_db() res = db.save_doc({"#export_tag": "tag", "tag": "attachments-test", "p1": "v1"}, **get_safe_write_kwargs()) doc = db.get(res["id"]) db.put_attachment(doc, "some content", "attach.txt") config = ExportConfiguration(db, ["attachments-test"], cleanup_fn=None) schema = config.get_latest_schema() self.assertTrue("_attachments" in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertTrue("_attachments" in docs[0]) # check that it works both explicitly and by default explicit_config = ExportConfiguration(db, ["attachments-test"], cleanup_fn=clear_attachments) default_config = ExportConfiguration(db, ["attachments-test"]) for config in (explicit_config, default_config): schema = config.get_latest_schema() self.assertFalse("_attachments" in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertFalse("_attachments" in docs[0])
def testComputedRemoved(self): db = get_db() db.save_doc( {"#export_tag": "tag", "tag": "computed-test", "p1": "v1", "computed_": {"ignore": "this stuff"}}, **get_safe_write_kwargs() ) config = ExportConfiguration(db, ["computed-test"], cleanup_fn=None) schema = config.get_latest_schema() self.assertTrue("computed_" in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertTrue("computed_" in docs[0]) # check that it works both explicitly and by default explicit_config = ExportConfiguration(db, ["computed-test"], cleanup_fn=clear_computed) default_config = ExportConfiguration(db, ["computed-test"]) for config in (explicit_config, default_config): schema = config.get_latest_schema() self.assertFalse("computed_" in schema) docs = list(config.get_docs()) self.assertEqual(1, len(docs)) self.assertFalse("computed_" in docs[0])
def build_latest_schema(schema_index): """ Build a schema, directly from the index. Also creates a saved checkpoint. """ from couchexport.export import ExportConfiguration db = Database(settings.COUCH_DATABASE) previous_export = ExportSchema.last(schema_index) config = ExportConfiguration(db, schema_index, previous_export=previous_export) schema = config.get_latest_schema() if not schema: return None updated_checkpoint = config.create_new_checkpoint() return updated_checkpoint