def test_for_missing_migrations(self): output = StringIO() options = { 'interactive': False, 'dry_run': True, 'stdout': output, 'check_changes': True, } if DJANGO_1_9: # this option was deprecated in Django 1.10 options['exit_code'] = True # this option was introduced in Django 1.10 del options['check_changes'] try: call_command('makemigrations', **options) except SystemExit as e: status_code = text_type(e) else: # on Django < 1.10, the "no changes" exit code is 1 # on Django > 1.10, the "no changes" exit code is 0 status_code = '1' if DJANGO_1_9 else '0' if status_code == '0' and DJANGO_1_9: self.fail('There are missing migrations:\n {}'.format( output.getvalue())) if status_code == '1' and not DJANGO_1_9: self.fail('There are missing migrations:\n {}'.format( output.getvalue()))
def test_spelling(self): status = StringIO() with TemporaryDirectory() as OUT_DIR: with tmp_list_append(sys.argv, 'spelling'): try: app = Sphinx( srcdir=DOCS_DIR, confdir=DOCS_DIR, outdir=OUT_DIR, doctreedir=OUT_DIR, buildername="spelling", warningiserror=True, status=status, confoverrides={ 'extensions': [ 'djangocms', 'sphinx.ext.intersphinx', 'sphinxcontrib.spelling' ] } ) app.build() self.assertEqual(app.statuscode, 0, status.getvalue()) except SphinxWarning: # while normally harmless, causes a test failure pass except: print(status.getvalue()) raise
def test_dsn_full(self): out = StringIO() err = StringIO() call_command("dbparams", "default", dsn=True, stdout=out, stderr=err, skip_checks=True) output = out.getvalue() assert output == "F=/tmp/defaults.cnf,u=ausername,p=apassword,h=ahost.example.com," "P=12345,D=mydatabase" errors = err.getvalue() assert "SSL params can't be" in errors
def test_dsn_socket(self): out = StringIO() err = StringIO() call_command('dbparams', dsn=True, stdout=out, stderr=err) output = out.getvalue() self.assertEqual(output, 'S=/etc/mydb.sock') errors = err.getvalue() self.assertEqual(errors, "")
def test_dsn_socket(self): out = StringIO() err = StringIO() call_command("dbparams", dsn=True, stdout=out, stderr=err, skip_checks=True) output = out.getvalue() assert output == "S=/etc/mydb.sock" errors = err.getvalue() assert errors == ""
def test_dsn_socket(self): out = StringIO() err = StringIO() call_command('dbparams', dsn=True, stdout=out, stderr=err, skip_checks=True) output = out.getvalue() assert output == 'S=/etc/mydb.sock' errors = err.getvalue() assert errors == ""
def test_dsn_full(self): out = StringIO() err = StringIO() call_command('dbparams', 'default', dsn=True, stdout=out, stderr=err) output = out.getvalue() self.assertEqual( output, "F=/tmp/defaults.cnf,u=ausername,p=apassword,h=ahost.example.com," "P=12345,D=mydatabase" ) errors = err.getvalue() self.assertIn("SSL params can't be", errors)
def test_dsn_full(self): out = StringIO() err = StringIO() call_command('dbparams', 'default', dsn=True, stdout=out, stderr=err, skip_checks=True) output = out.getvalue() assert ( output == "F=/tmp/defaults.cnf,u=ausername,p=apassword,h=ahost.example.com," "P=12345,D=mydatabase" ) errors = err.getvalue() assert "SSL params can't be" in errors
def test_mysql_cache_migration_alias(self): out = StringIO() call_command('mysql_cache_migration', 'default', stdout=out) output = out.getvalue() num_run_sqls = (len(output.split('RunSQL')) - 1) assert num_run_sqls == 1
def test_mysql_full(self): out = StringIO() call_command('dbparams', stdout=out, skip_checks=True) output = out.getvalue() assert (output == "--defaults-file=/tmp/defaults.cnf --user=ausername " "--password=apassword --host=ahost.example.com --port=12345 " "--ssl-ca=/tmp/mysql.cert mydatabase")
def test_mysql_cache_migration_alias(self): out = StringIO() call_command('mysql_cache_migration', 'default', stdout=out) output = out.getvalue() num_run_sqls = (len(output.split('RunSQL')) - 1) assert num_run_sqls == 1
def render(self, data, *args, **kwargs): charset = 'utf-8' root_node = 'xforms' xmlns = "http://openrosa.org/xforms/xformsList" if 'detail' in data.keys(): stream = StringIO() xml = SimplerXMLGenerator(stream, charset) xml.startDocument() xml.startElement(root_node, {'xmlns': xmlns}) for key, value in six.iteritems(data): xml.startElement(key, {}) xml.characters(smart_text(value)) xml.endElement(key) xml.endElement(root_node) xml.endDocument() return stream.getvalue() else: json = self.transform_to_xform_json(data) survey = create_survey_element_from_dict(json) xml = survey.xml() fix_languages(xml) xml = xml.toxml() xml = self.insert_version_attribute(xml, data.get('id_string'), data.get('version')) xml = self.insert_uuid_bind(xml, data.get('id_string')) return xml
def render(self, data, *args, **kwargs): charset = 'utf-8' root_node = 'xforms' xmlns = "http://openrosa.org/xforms/xformsList" if 'detail' in data.keys(): stream = StringIO() xml = SimplerXMLGenerator(stream, charset) xml.startDocument() xml.startElement(root_node, {'xmlns': xmlns}) for key, value in six.iteritems(data): xml.startElement(key, {}) xml.characters(smart_text(value)) xml.endElement(key) xml.endElement(root_node) xml.endDocument() return stream.getvalue() else: json = self.transform_to_xform_json(data) survey = create_survey_element_from_dict(json) xml = survey.xml() fix_languages(xml) xml = xml.toxml() xml = self.insert_version_attribute(xml, data.get('id_string'), data.get('version')) xml = self.insert_uuid_bind(xml, data.get('id_string')) return xml
def test_uninstall_plugins_with_plugin(self): out = StringIO() placeholder = Placeholder.objects.create(slot="test") add_plugin(placeholder, TextPlugin, "en", body="en body") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 1) management.call_command('cms', 'uninstall', 'plugins', PLUGIN, interactive=False, stdout=out) self.assertEqual(out.getvalue(), "1 'TextPlugin' plugins uninstalled\n") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 0)
def test_list_apphooks(self): out = StringIO() create_page('Hello Title', "nav_playground.html", "en", apphook=APPHOOK) self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 1) command = cms.Command() command.stdout = out command.handle("list", "apphooks", interactive=False) self.assertEqual(out.getvalue(), "SampleApp (draft)\n")
def test_list_apphooks(self): out = StringIO() create_page('Hello Title', "nav_playground.html", "en", apphook=APPHOOK) self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 1) command = cms.Command() command.stdout = out command.handle("list", "apphooks", interactive=False) self.assertEqual(out.getvalue(), "SampleApp\n")
def test_uninstall_plugins_without_plugin(self): out = StringIO() management.call_command('cms', 'uninstall', 'plugins', PLUGIN, interactive=False, stdout=out) self.assertEqual(out.getvalue(), "no 'TextPlugin' plugins found\n")
def test_mysql_full(self): out = StringIO() call_command("dbparams", stdout=out, skip_checks=True) output = out.getvalue() assert ( output == "--defaults-file=/tmp/defaults.cnf --user=ausername " "--password=apassword --host=ahost.example.com --port=12345 " "--ssl-ca=/tmp/mysql.cert mydatabase" )
def test_uninstall_apphooks_with_apphook(self): out = StringIO() create_page('Hello Title', "nav_playground.html", "en", apphook=APPHOOK) self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 1) command = cms.Command() command.stdout = out command.handle("uninstall", "apphooks", APPHOOK, interactive=False) self.assertEqual(out.getvalue(), "1 'SampleApp' apphooks uninstalled\n") self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 0)
def test_uninstall_apphooks_without_apphook(self): out = StringIO() management.call_command('cms', 'uninstall', 'apphooks', APPHOOK, interactive=False, stdout=out) self.assertEqual(out.getvalue(), "no 'SampleApp' apphooks found\n")
def render(self, data, prettyprint=False): """ parameters: data = dictionary of the things to be shown prettyprint = flag for pretty printing the xml output (including whitespace and linebreaks) """ stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() # add a comment xml._write(self.comment) # add namespace definitions nsattrs = {} nsattrs['version'] = self.version #nsattrs['encoding'] = charser nsattrs['xmlns:vosi'] = self.ns_vosiavail #nsattrs['xmlns:xsi'] = self.ns_xsi #nsattrs['xmlns:vs'] = self.ns_vs # add root node xml.startElement('vosi:availability', nsattrs) # add mandatory node: xml.startElement('vosi:available', {}) xml.characters(smart_unicode(data['available'])) xml.endElement('vosi:available') # remove available from data dict data.pop('available', None) # add possible optional nodes: for key in data.keys(): xml.startElement('vosi:' + key, {}) xml.characters(smart_unicode(data[key])) xml.endElement('vosi:' + key) xml.endElement('vosi:availability') xml.endDocument() xml_string = stream.getvalue() # make the xml pretty, i.e. use linebreaks and indentation # the sax XMLGenerator behind SimpleXMLGenerator does not seem to support this, # thus need a library that can do it. # TODO: since we use lxml anyway, maybe build the whole xml-tree with lxml.etree! # NOTE: This removes any possibly existing comments from the xml output! if prettyprint is True: parsed = etree.fromstring(xml_string) pretty_xml = etree.tostring(parsed, pretty_print=True) xml_string = pretty_xml return xml_string
def test_uninstall_apphooks_with_apphook(self): out = StringIO() create_page('Hello Title', "nav_playground.html", "en", apphook=APPHOOK) self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 1) command = cms.Command() command.stdout = out command.handle("uninstall", "apphooks", APPHOOK, interactive=False) self.assertEqual(out.getvalue(), "1 'SampleApp' apphooks uninstalled\n") self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 0)
def test_list_apphooks(self): out = StringIO() apps = ["cms", "menus", "sekizai", "cms.test_utils.project.sampleapp"] with SettingsOverride(INSTALLED_APPS=apps): create_page('Hello Title', "nav_playground.html", "en", apphook=APPHOOK) self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 1) command = cms.Command() command.stdout = out command.handle("list", "apphooks", interactive=False) self.assertEqual(out.getvalue(), "SampleApp\n")
def test_uninstall_plugins_with_plugin(self): out = StringIO() placeholder = Placeholder.objects.create(slot="test") add_plugin(placeholder, TextPlugin, "en", body="en body") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 1) command = cms.Command() command.stdout = out command.handle("uninstall", "plugins", PLUGIN, interactive=False) self.assertEqual(out.getvalue(), "1 'TextPlugin' plugins uninstalled\n") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 0)
def test_mysql_full(self): out = StringIO() call_command('dbparams', stdout=out) output = out.getvalue() self.assertEqual( output, "--defaults-file=/tmp/defaults.cnf --user=ausername " "--password=apassword --host=ahost.example.com --port=12345 " "--ssl-ca=/tmp/mysql.cert mydatabase" )
def _exception_traceback(exc_info): """ Return a string containing a traceback message for the given exc_info tuple (as returned by sys.exc_info()). """ # Get a traceback message. excout = StringIO() exc_type, exc_val, exc_tb = exc_info traceback.print_exception(exc_type, exc_val, exc_tb, file=excout) return excout.getvalue()
def test_uninstall_plugins_with_plugin(self): out = StringIO() placeholder = Placeholder.objects.create(slot="test") add_plugin(placeholder, TextPlugin, "en", body="en body") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 1) command = cms.Command() command.stdout = out command.handle("uninstall", "plugins", PLUGIN, interactive=False) self.assertEqual(out.getvalue(), "1 'TextPlugin' plugins uninstalled\n") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 0)
def run_it(*args, **kwargs): run_args = ['fix_datetime_columns'] run_args.extend(args) out = StringIO() run_kwargs = {'stdout': out, 'skip_checks': True} run_kwargs.update(kwargs) call_command(*run_args, **run_kwargs) return out.getvalue()
def test_cull_mysql_caches_named_cache(self): cache.set('key', 'value', 0.1) time.sleep(0.2) assert self.table_count() == 1 out = StringIO() call_command('cull_mysql_caches', 'default', verbosity=1, stdout=out) output = out.getvalue() assert (output.strip() == "Deleting from cache 'default'... 1 entries deleted.") assert self.table_count() == 0
def run_it(*args, **kwargs): run_args = ['fix_datetime_columns'] run_args.extend(args) out = StringIO() run_kwargs = {'stdout': out, 'skip_checks': True} run_kwargs.update(kwargs) call_command(*run_args, **run_kwargs) return out.getvalue()
def getvalue(self): result = StringIO.getvalue(self) # If anything at all was written, make sure there's a trailing # newline. There's no way for the expected output to indicate # that a trailing newline is missing. if result and not result.endswith("\n"): result += "\n" # Prevent softspace from screwing up the next test case, in # case they used print with a trailing comma in an example. if hasattr(self, "softspace"): del self.softspace return result
def test_uninstall_plugins_with_plugin(self): out = StringIO() apps = ["cms", "menus", "sekizai", "cms.test_utils.project.sampleapp"] with SettingsOverride(INSTALLED_APPS=apps): placeholder = Placeholder.objects.create(slot="test") add_plugin(placeholder, TextPlugin, "en", body="en body") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 1) command = cms.Command() command.stdout = out command.handle("uninstall", "plugins", PLUGIN, interactive=False) self.assertEqual(out.getvalue(), "1 'TextPlugin' plugins uninstalled\n") self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 0)
def test_uninstall_apphooks_without_apphook(self): with apphooks(): out = StringIO() management.call_command( "cms", "uninstall", "apphooks", APPHOOK, interactive=False, stdout=out, ) self.assertEqual(out.getvalue(), "no 'SampleApp' apphooks found\n")
def render(self, data): if data is None: return '' stream = StringIO() xml = SimplerXMLGenerator(stream, "utf-8") xml.startDocument() self.render_document(xml, data) xml.endDocument() return stream.getvalue()
def test_cull_mysql_caches_named_cache(self): cache.set('key', 'value', 0.1) time.sleep(0.2) assert self.table_count() == 1 out = StringIO() call_command('cull_mysql_caches', 'default', verbosity=1, stdout=out) output = out.getvalue() assert ( output.strip() == "Deleting from cache 'default'... 1 entries deleted." ) assert self.table_count() == 0
def render(self, data, accepted_media_type=None, renderer_context=None): if data is None: return '' view = (renderer_context.get("view") if renderer_context else None) self.item_tag_name = getattr(view, "item_tag_name", self.item_tag_name) self.root_tag_name = getattr(view, "root_tag_name", self.root_tag_name) stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() root_tag_name = (getattr(data, "xml_tag", None) or self.root_tag_name) self._to_xml(xml, data, root_tag_name) xml.endDocument() return stream.getvalue()
def render(self, data, accepted_media_type=None, renderer_context=None): if data is None: return '' view = (renderer_context.get("view") if renderer_context else None) self.item_tag_name = getattr(view, "item_tag_name", self.item_tag_name) self.root_tag_name = getattr(view, "root_tag_name", self.root_tag_name) stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() root_tag_name = (getattr(data, "xml_tag", None) or self.root_tag_name) self._to_xml(xml, data, root_tag_name) xml.endDocument() return stream.getvalue()
def test_list_apphooks(self): with apphooks(SampleApp): out = StringIO() create_page('Hello Title', "nav_playground.html", "en", apphook=APPHOOK) self.assertEqual(Page.objects.filter(application_urls=APPHOOK).count(), 1) management.call_command( "cms", "list", "apphooks", interactive=False, stdout=out, ) self.assertEqual(out.getvalue(), "SampleApp (draft)\n")
def html2text(html): """Use html2text but repair newlines cutting urls. Need to use this hack until https://github.com/aaronsw/html2text/issues/#issue/7 is not fixed""" txt = html2text_orig(html) links = list(LINK_RE.finditer(txt)) out = StringIO() pos = 0 for l in links: out.write(txt[pos:l.start()]) out.write(l.group().replace('\n', '')) pos = l.end() out.write(txt[pos:]) return out.getvalue()
def test_fix_tree(self): create_page("home", "nav_playground.html", "en") page1 = create_page("page", "nav_playground.html", "en") page1.depth = 3 page1.numchild = 4 page1.path = "00100010" page1.save() out = StringIO() management.call_command('cms', 'fix-tree', interactive=False, stdout=out) self.assertEqual(out.getvalue(), 'fixing page tree\nfixing plugin tree\nall done\n') page1 = page1.reload() self.assertEqual(page1.path, "0002") self.assertEqual(page1.depth, 1) self.assertEqual(page1.numchild, 0)
def test_list_apphooks(self): out = StringIO() apps = ["cms", "menus", "sekizai", "cms.test_utils.project.sampleapp"] with SettingsOverride(INSTALLED_APPS=apps): create_page('Hello Title', "nav_playground.html", "en", apphook=APPHOOK) self.assertEqual( Page.objects.filter(application_urls=APPHOOK).count(), 1) command = cms.Command() command.stdout = out command.handle("list", "apphooks", interactive=False) self.assertEqual(out.getvalue(), "SampleApp\n")
def test_copy_from_non_existing_lang(self): """ If an existing title in the target language has plugins in a placeholder and the command is called with *force-copy*, the plugins are copied on top of the existing one """ site = 1 out = StringIO() command = cms.Command() command.stdout = out command.handle("copy-lang", "de", "fr", "verbose") text = out.getvalue() page_count = Page.objects.on_site(site).drafts().count() + 1 for idx in range(1, page_count): self.assertTrue(text.find("Skipping page page%d, language de not defined" % idx) > -1)
def test_copy_from_non_existing_lang(self): """ If an existing title in the target language has plugins in a placeholder and the command is called with *force-copy*, the plugins are copied on top of the existing one """ site = 1 out = StringIO() command = cms.Command() command.stdout = out command.handle("copy-lang", "de", "fr", "verbose") text = out.getvalue() page_count = Page.objects.on_site(site).drafts().count() + 1 for idx in range(1, page_count): self.assertTrue(text.find("Skipping page page%d, language de not defined" % idx) > -1)
def test_uninstall_plugins_with_plugin(self): out = StringIO() apps = ["cms", "menus", "sekizai", "cms.test_utils.project.sampleapp"] with SettingsOverride(INSTALLED_APPS=apps): placeholder = Placeholder.objects.create(slot="test") add_plugin(placeholder, TextPlugin, "en", body="en body") self.assertEqual( CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 1) command = cms.Command() command.stdout = out command.handle("uninstall", "plugins", PLUGIN, interactive=False) self.assertEqual(out.getvalue(), "1 'TextPlugin' plugins uninstalled\n") self.assertEqual( CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 0)
def render(self, data, accepted_media_type=None, renderer_context=None): """ Renders `data` into serialized XML. """ if data is None: return '' stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() xml.startElement(self.root_tag_name, {}) self._to_xml(xml, data) xml.endElement(self.root_tag_name) xml.endDocument() #raise AssertionError(type(stream.getvalue())); generic_xml = stream.getvalue() if data.get('count') != None and data.get('list') != None: # deal with multiple tools xmlfile = 'multiple.xslt' else: # deal with a single tool xmlfile = 'framework_XML_to_biotoolsSchema_3.3.0_XML_xslt1.0.xslt' try: xslt1 = lxmletree.parse( '/elixir/application/backend/elixir/biotoolsSchema/' + xmlfile) transform1 = lxmletree.XSLT(xslt1) dom = lxmletree.fromstring(generic_xml) newdom = transform1(dom) # removing empty elements xslt2 = lxmletree.parse( "/elixir/application/backend/elixir/biotoolsSchema/removeEmptyElements.xslt" ) transform2 = lxmletree.XSLT(xslt2) newdom2 = transform2(newdom) except (lxmletree.XMLSyntaxError, Exception) as e: raise ParseError( 'XML error - %s. Please notify [email protected] if you see this error. ' % e) return lxmletree.tostring(newdom2)
def render(self, data, accepted_media_type=None, renderer_context=None): if data is None: return '' stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() if isinstance(data, (list, tuple)): self._render_list(data, xml, renderer_context) elif isinstance(data, dict): self._render_dict(data, xml, renderer_context) xml.endDocument() return stream.getvalue()
def test_fix_tree(self): create_page("home", "nav_playground.html", "en") page1 = create_page("page", "nav_playground.html", "en") page1.depth = 3 page1.numchild = 4 page1.path = "00100010" page1.save() out = StringIO() command = cms.Command() command.stdout = out command.handle("fix-tree", interactive=False) self.assertEqual(out.getvalue(), 'fixing page treefixing plugin treeall done') page1 = page1.reload() self.assertEqual(page1.path, "0002") self.assertEqual(page1.depth, 1) self.assertEqual(page1.numchild, 0)
def render(self, data, accepted_media_type=None, renderer_context=None): if data is None: return '' stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() if isinstance(data, (list, tuple)): self._render_list(data, xml, renderer_context) elif isinstance(data, dict): self._render_dict(data, xml, renderer_context) xml.endDocument() return stream.getvalue()
def test_fix_tree(self): create_page("home", "nav_playground.html", "en") page1 = create_page("page", "nav_playground.html", "en") page1.depth = 3 page1.numchild = 4 page1.path = "00100010" page1.save() out = StringIO() command = cms.Command() command.stdout = out command.handle("fix-tree", interactive=False) self.assertEqual(out.getvalue(), 'fixing page treefixing plugin treeall done') page1 = page1.reload() self.assertEqual(page1.path, "0002") self.assertEqual(page1.depth, 1) self.assertEqual(page1.numchild, 0)
def test_copy_from_non_existing_lang(self): """ If an existing title in the target language has plugins in a placeholder and the command is called with *force-copy*, the plugins are copied on top of the existing one """ site = 1 out = StringIO() management.call_command( 'cms', 'copy', 'lang', '--from-lang=de', '--to-lang=fr', verbosity=3, interactive=False, stdout=out ) text = out.getvalue() page_count = Page.objects.on_site(site).drafts().count() + 1 for idx in range(1, page_count): self.assertTrue("Skipping page page%d, language de not defined" % idx in text)
def test_mysql_cache_migration(self): out = StringIO() call_command('mysql_cache_migration', stdout=out) output = out.getvalue() # Lint it with captured_stdout() as stderr: errors = check_code(output) self.assertEqual( errors, 0, "Encountered {} errors whilst trying to lint the mysql cache " "migration.\nMigration:\n\n{}\n\nLint errors:\n\n{}" .format(errors, output, stderr.getvalue()) ) # Dynamic import and check migration_mod = imp.new_module('0001_add_cache_tables') six.exec_(output, migration_mod.__dict__) self.assertTrue(hasattr(migration_mod, 'Migration')) migration = migration_mod.Migration self.assertTrue(hasattr(migration, 'dependencies')) self.assertTrue(hasattr(migration, 'operations')) # Since they all have the same table name, there should only be one # operation self.assertEqual(len(migration.operations), 1) # Now run the migration forwards and backwards to check it works operation = migration.operations[0] self.drop_table() self.assertTableNotExists(self.table_name) state = ProjectState() new_state = state.clone() with connection.schema_editor() as editor: operation.database_forwards("django_mysql_tests", editor, state, new_state) self.assertTableExists(self.table_name) new_state = state.clone() with connection.schema_editor() as editor: operation.database_backwards("django_mysql_tests", editor, new_state, state) self.assertTableNotExists(self.table_name) self.create_table()
def test_html(self): status = StringIO() with TemporaryDirectory() as OUT_DIR: app = Sphinx( srcdir=DOCS_DIR, confdir=DOCS_DIR, outdir=OUT_DIR, doctreedir=OUT_DIR, buildername="html", warningiserror=True, status=status, ) try: app.build() except: print(status.getvalue()) raise
def test_html(self): nullout = StringIO() with TemporaryDirectory() as OUT_DIR: app = Sphinx( DOCS_DIR, DOCS_DIR, OUT_DIR, OUT_DIR, "html", warningiserror=True, status=nullout, ) try: app.build() except: print(nullout.getvalue()) raise
def render(self, data, accepted_media_type=None, renderer_context=None): """ Renders `data` into serialized XML. """ if data is None: return '' stream = StringIO() xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() xml.startElement("root", {}) self._to_xml(xml, data) xml.endElement("root") xml.endDocument() return stream.getvalue()