def action_status(args, cfg): if not cfg: cfg = config.UAConfig() status = cfg.status() active_value = ua_status.UserFacingConfigStatus.ACTIVE.value config_active = bool(status["configStatus"] == active_value) if args and args.wait and config_active: while status["configStatus"] == active_value: print(".", end="") time.sleep(1) status = cfg.status() print("") if args and args.format == "json": if status["expires"] != ua_status.UserFacingStatus.INAPPLICABLE.value: status["expires"] = str(status["expires"]) print(json.dumps(status)) else: show_beta = args.all if args else False output = ua_status.format_tabular(cfg.status(show_beta)) # Replace our Unicode dash with an ASCII dash if we aren't going to be # writing to a utf-8 output; see # https://github.com/CanonicalLtd/ubuntu-advantage-client/issues/859 if ( sys.stdout.encoding is None or "UTF-8" not in sys.stdout.encoding.upper() ): output = output.replace("\u2014", "-") print(output) return 0
def test_no_leading_newline(self, attached, status_dict_attached, status_dict_unattached): if attached: status_dict = status_dict_attached else: status_dict = status_dict_unattached assert not format_tabular(status_dict).startswith("\n")
def action_status(args, cfg): if not cfg: cfg = config.UAConfig() if args and args.format == 'json': status = cfg.status() if status['expires'] != ua_status.INAPPLICABLE: status['expires'] = str(status['expires']) print(json.dumps(status)) else: print(ua_status.format_tabular(cfg.status()))
def test_correct_unattached_column_alignment(self, status_dict_unattached): tabular_output = format_tabular(status_dict_unattached) [header, eal_service_line] = [ line for line in tabular_output.splitlines() if "eal" in line or "AVAILABLE" in line ] printable_eal_line = "".join( filter(lambda x: x in string.printable, eal_service_line)) assert header.find("AVAILABLE") == printable_eal_line.find("no") assert header.find("DESCRIPTION") == printable_eal_line.find("Common")
def action_status(args, cfg): if not cfg: cfg = config.UAConfig() if args and args.format == "json": status = cfg.status() if status["expires"] != ua_status.UserFacingStatus.INAPPLICABLE.value: status["expires"] = str(status["expires"]) print(json.dumps(status)) else: print(ua_status.format_tabular(cfg.status())) return 0
def test_correct_header_keys_included(self, origin, expected_headers, status_dict_attached): status_dict_attached["origin"] = origin tabular_output = format_tabular(status_dict_attached) headers = [ line.split(":")[0].strip() for line in tabular_output.splitlines() if ":" in line and "Enable services" not in line ] assert list(expected_headers) == headers
def test_header_alignment(self, origin, status_dict_attached): status_dict_attached["origin"] = origin tabular_output = format_tabular(status_dict_attached) colon_idx = None for line in tabular_output.splitlines(): if ":" not in line or "Enable services" in line: # This isn't a header line continue if colon_idx is None: # This is the first header line, record where the colon is colon_idx = line.index(":") continue # Ensure that the colon in this line is aligned with previous ones assert line.index(":") == colon_idx
def test_custom_descr( self, description_override, uf_status, uf_descr, status_dict_attached ): """Services can provide a custom call to action if present.""" default_descr = "Common Criteria EAL2 default descr" status_dict_attached["services"] = [ { "name": "cc-eal", "description": default_descr, "available": "no", "status": uf_status, "entitled": True, "description_override": description_override, } ] assert uf_descr in format_tabular(status_dict_attached)
def test_correct_header_keys_included(self, origin, expected_headers, status_dict_attached): status_dict_attached["origin"] = origin if status_dict_attached["contract"].get("name"): expected_headers = ("Subscription", ) + expected_headers if status_dict_attached["account"].get("name"): expected_headers = ("Account", ) + expected_headers tabular_output = format_tabular(status_dict_attached) headers = [ line.split(":")[0].strip() for line in tabular_output.splitlines() if ":" in line and "Enable services" not in line ] assert list(expected_headers) == headers
def test_support_colouring( self, m_isatty, support_level, expected_colour, istty, status_dict_attached, ): status_dict_attached["contract"]["tech_support_level"] = support_level m_isatty.return_value = istty tabular_output = format_tabular(status_dict_attached) expected_string = "Technical support level: {}".format( support_level if not expected_colour else expected_colour + support_level + TxtColor.ENDC) assert expected_string in tabular_output
def action_status(args, cfg): if not cfg: cfg = config.UAConfig() if args and args.format == "json": status = cfg.status() if status["expires"] != ua_status.UserFacingStatus.INAPPLICABLE.value: status["expires"] = str(status["expires"]) print(json.dumps(status)) else: output = ua_status.format_tabular(cfg.status()) # Replace our Unicode dash with an ASCII dash if we aren't going to be # writing to a utf-8 output; see # https://github.com/CanonicalLtd/ubuntu-advantage-client/issues/859 if (sys.stdout.encoding is None or "UTF-8" not in sys.stdout.encoding.upper()): output = output.replace("\u2014", "-") print(output) return 0
def test_custom_descr(self, description_override, uf_status, uf_descr, status_dict_attached): """Services can provide a custom call to action if present.""" default_descr = "Common Criteria EAL2 default descr" status_dict_attached["services"] = [{ "name": "cc-eal", "description": default_descr, "available": "no", "status": uf_status, "entitled": True, "description_override": description_override, }] if not description_override: # Remove key to test upgrade path from older ua-tools status_dict_attached["services"][0].pop("description_override") assert uf_descr in format_tabular(status_dict_attached)