예제 #1
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])
예제 #2
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])
예제 #3
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])
예제 #4
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])
예제 #5
0
    def download_data(self, format="", previous_export=None, filter=None):
        """
        If there is data, return an HTTPResponse with the appropriate data. 
        If there is not data returns None.
        """
        from couchexport.shortcuts import export_response
        from couchexport.export import get_writer, get_schema_new, format_tables, create_intermediate_tables

        if not format:
            format = self.default_format or Format.XLS_2007

        from couchexport.export import ExportConfiguration

        database = get_db()
        config = ExportConfiguration(database, self.index, previous_export, util.intersect_filters(self.filter, filter))

        # get and checkpoint the latest schema
        updated_schema = get_schema_new(config)
        export_schema_checkpoint = ExportSchema(
            seq=config.current_seq, schema=updated_schema, index=config.schema_index
        )
        export_schema_checkpoint.save()
        # transform docs onto output and save
        writer = get_writer(format)

        # open the doc and the headers
        formatted_headers = self.get_table_headers()
        tmp = StringIO()
        writer.open(formatted_headers, tmp)

        for doc in config.get_docs():
            writer.write(self.trim(format_tables(create_intermediate_tables(doc, updated_schema), separator=".")))
        writer.close()

        return export_response(tmp, format, self.name)
예제 #6
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"])
        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])
예제 #7
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])
예제 #8
0
 def _clear_docs(self):
     config = ExportConfiguration(XFormInstance.get_db(),
                                  [DOMAIN, "http://www.commcarehq.org/export/test"])
     for form in config.get_docs():
         XFormInstance.wrap(form).delete()
예제 #9
0
 def _clear_docs(self):
     config = ExportConfiguration(
         XFormInstance.get_db(),
         [DOMAIN, "http://www.commcarehq.org/export/test"])
     for form in config.get_docs():
         XFormInstance.wrap(form).delete()