def test_get_external_ip(self): # Test success with requests_mock.mock() as m: m.get(util._AWS_CHECK_IP, text="1.2.3.4") self.assertEqual("1.2.3.4", util.get_external_ip()) util._external_ip = None # Test failure with requests_mock.mock() as m: m.get(util._AWS_CHECK_IP, exc=requests.exceptions.ConnectTimeout) self.assertEqual(None, util.get_external_ip())
def _print_url(): title_message = "You can now view your Streamlit app in your browser." named_urls = [] if config.is_manually_set("browser.serverAddress"): named_urls = [ ("URL", Report.get_url(config.get_option("browser.serverAddress"))) ] elif config.get_option("server.headless"): named_urls = [ ("Network URL", Report.get_url(util.get_internal_ip())), ("External URL", Report.get_url(util.get_external_ip())), ] else: named_urls = [ ("Local URL", Report.get_url("localhost")), ("Network URL", Report.get_url(util.get_internal_ip())), ] click.secho("") click.secho(" %s" % title_message, fg="blue", bold=True) click.secho("") for url_name, url in named_urls: util.print_url(url_name, url) click.secho("")
def _print_url(): title_message = 'You can now view your Streamlit report in your browser.' named_urls = [] if config.is_manually_set('browser.serverAddress'): named_urls = [ ('URL', Report.get_url(config.get_option('browser.serverAddress'))), ] elif config.get_option('server.headless'): named_urls = [ ('Network URL', Report.get_url(util.get_internal_ip())), ('External URL', Report.get_url(util.get_external_ip())), ] else: named_urls = [ ('Local URL', Report.get_url('localhost')), ('Network URL', Report.get_url(util.get_internal_ip())), ] click.secho('') click.secho(' %s' % title_message, fg='green') click.secho('') for url_name, url in named_urls: util.print_url(url_name, url) click.secho('')
def serialize_running_report_to_files(self): """Return a running report as an easily-serializable list of tuples. Returns ------- list of tuples See `CloudStorage.save_report_files()` for schema. But as to the output of this method, it's just a manifest pointing to the Server so browsers who go to the shareable report URL can connect to it live. """ LOGGER.debug("Serializing running report") manifest = self._build_manifest( status=StaticManifest.RUNNING, external_server_ip=util.get_external_ip(), internal_server_ip=util.get_internal_ip(), ) return [("reports/%s/manifest.pb" % self.report_id, manifest.SerializeToString())]
def serialize_running_report_to_files(self): """Return a running report as an easily-serializable list of tuples. Returns ------- list of tuples See `CloudStorage.save_report_files()` for schema. But as to the output of this method, it's just a manifest pointing to the Server so browsers who go to the shareable report URL can connect to it live. """ LOGGER.debug('Serializing running report') manifest = self._build_manifest( status='running', external_server_ip=util.get_external_ip(), internal_server_ip=util.get_internal_ip(), ) manifest_json = json.dumps(manifest).encode('utf-8') return [('reports/%s/manifest.json' % self.report_id, manifest_json)]