예제 #1
0
 def test_attach_parser_accepts_and_stores_no_auto_enable(self):
     full_parser = get_parser()
     with mock.patch(
         "sys.argv", ["ua", "attach", "--no-auto-enable", "token"]
     ):
         args = full_parser.parse_args()
     assert not args.auto_enable
    def test_detach_parser_defaults_to_not_assume_yes(self, _m_resources,
                                                      FakeConfig):
        full_parser = get_parser(FakeConfig())
        with mock.patch("sys.argv", ["ua", "detach"]):
            args = full_parser.parse_args()

        assert not args.assume_yes
예제 #3
0
 def test_attach_parser_default_to_cli_format(
     self, _m_resources, FakeConfig
 ):
     full_parser = get_parser(FakeConfig())
     with mock.patch("sys.argv", ["ua", "attach", "token"]):
         args = full_parser.parse_args()
     assert "cli" == args.format
예제 #4
0
    def test_status_parser_updates_parser_config(self, _m_resources,
                                                 FakeConfig):
        """Update the parser configuration for 'status'."""
        m_parser = status_parser(mock.Mock())
        assert "status" == m_parser.prog

        full_parser = get_parser(FakeConfig())
        with mock.patch(
                "sys.argv",
            [
                "ua",
                "status",
                "--format",
                "json",
                "--simulate-with-token",
                "some_token",
                "--all",
            ],
        ):
            args = full_parser.parse_args()
        assert "status" == args.command
        assert True is args.all
        assert "json" == args.format
        assert "some_token" == args.simulate_with_token
        assert "action_status" == args.action.__name__
예제 #5
0
 def test_attach_parser_accepts_format_flag(self, _m_resources, FakeConfig):
     full_parser = get_parser(FakeConfig())
     with mock.patch(
         "sys.argv", ["ua", "attach", "token", "--format", "json"]
     ):
         args = full_parser.parse_args()
     assert "json" == args.format
예제 #6
0
 def test_attach_parser_defaults_to_auto_enable(
     self, _m_resources, FakeConfig
 ):
     full_parser = get_parser(FakeConfig())
     with mock.patch("sys.argv", ["ua", "attach", "token"]):
         args = full_parser.parse_args()
     assert args.auto_enable
 def _get_help_output():
     parser = get_parser()
     with mock.patch("sys.argv", ["ua", "--help"]):
         with pytest.raises(SystemExit):
             parser.parse_args()
     out, _err = capsys.readouterr()
     return out
    def test_detach_parser_accepts_and_stores_assume_yes(
            self, _m_resources, FakeConfig):
        full_parser = get_parser(FakeConfig())
        with mock.patch("sys.argv", ["ua", "detach", "--assume-yes"]):
            args = full_parser.parse_args()

        assert args.assume_yes
예제 #9
0
 def test_attach_parser_help_points_to_ua_contract_dashboard_url(
         self, capsys):
     """Contracts' dashboard URL is referenced by ua attach --help."""
     full_parser = get_parser()
     with mock.patch("sys.argv", ["ua", "attach", "--help"]):
         with pytest.raises(SystemExit):
             full_parser.parse_args()
     assert UA_AUTH_TOKEN_URL in capsys.readouterr()[0]
예제 #10
0
 def test_attach_parser_allows_empty_required_token(
     self, _m_resources, FakeConfig
 ):
     """Token required but parse_args allows none due to action_attach"""
     full_parser = get_parser(FakeConfig())
     with mock.patch("sys.argv", ["ua", "attach"]):
         args = full_parser.parse_args()
     assert None is args.token
예제 #11
0
 def test_argparse_errors_well_formatted(self, capsys):
     parser = get_parser()
     with mock.patch("sys.argv", ["ua", "enable"]):
         with pytest.raises(SystemExit) as excinfo:
             parser.parse_args()
     assert 2 == excinfo.value.code
     _, err = capsys.readouterr()
     assert (textwrap.dedent("""\
         usage: ua enable <service> [<service>] [flags]
         the following arguments are required: service
     """) == str(err))
예제 #12
0
    def test_attach_parser_creates_a_parser_when_not_provided(self):
        """Create a named parser configured for 'attach'."""
        m_parser = attach_parser(mock.Mock())
        assert "ua attach <token> [flags]" == m_parser.usage
        assert "attach" == m_parser.prog
        assert "Flags" == m_parser._optionals.title

        full_parser = get_parser()
        with mock.patch("sys.argv", ["ua", "attach", "token"]):
            args = full_parser.parse_args()
        assert "token" == args.token
    def test_auto_attach_parser_updates_parser_config(self):
        """Update the parser configuration for 'auto-attach'."""
        m_parser = auto_attach_parser(mock.Mock())
        assert "ua auto-attach [flags]" == m_parser.usage
        assert "auto-attach" == m_parser.prog
        assert "Flags" == m_parser._optionals.title

        full_parser = get_parser()
        with mock.patch("sys.argv", ["ua", "auto-attach"]):
            args = full_parser.parse_args()
        assert "auto-attach" == args.command
        assert "action_auto_attach" == args.action.__name__
    def test_security_status_parser_updates_parser_config(
            self, _m_resources, FakeConfig):
        """Update the parser configuration for 'security-status'."""
        m_parser = security_status_parser(mock.Mock())
        assert "security-status" == m_parser.prog

        full_parser = get_parser(FakeConfig())
        with mock.patch("sys.argv",
                        ["ua", "security-status", "--format", "json"]):
            args = full_parser.parse_args()
        assert "security-status" == args.command
        assert "action_security_status" == args.action.__name__
예제 #15
0
    def test_collect_logs_parser_updates_parser_config(
        self, _m_resources, FakeConfig
    ):
        """Update the parser configuration for 'collect-logs'."""
        m_parser = collect_logs_parser(mock.Mock())
        assert "ua collect-logs [flags]" == m_parser.usage
        assert "collect-logs" == m_parser.prog

        full_parser = get_parser(FakeConfig())
        with mock.patch("sys.argv", ["ua", "collect-logs"]):
            args = full_parser.parse_args()
        assert "collect-logs" == args.command
        assert "action_collect_logs" == args.action.__name__
예제 #16
0
 def test_attach_parser_defaults_to_auto_enable(self):
     full_parser = get_parser()
     with mock.patch("sys.argv", ["ua", "attach", "token"]):
         args = full_parser.parse_args()
     assert args.auto_enable
예제 #17
0
 def test_attach_parser_stores_token(self, _m_resources, FakeConfig):
     full_parser = get_parser(FakeConfig())
     with mock.patch("sys.argv", ["ua", "attach", "token"]):
         args = full_parser.parse_args()
     assert "token" == args.token
예제 #18
0
 def _get_help_output():
     parser = get_parser()
     help_file = io.StringIO()
     parser.print_help(file=help_file)
     return help_file.getvalue()
예제 #19
0
    def test_detach_parser_defaults_to_not_assume_yes(self):
        full_parser = get_parser()
        with mock.patch("sys.argv", ["ua", "detach"]):
            args = full_parser.parse_args()

        assert not args.assume_yes
예제 #20
0
    def test_detach_parser_accepts_and_stores_assume_yes(self):
        full_parser = get_parser()
        with mock.patch("sys.argv", ["ua", "detach", "--assume-yes"]):
            args = full_parser.parse_args()

        assert args.assume_yes
    def test_detach_parser_with_json_format(self, _m_resources, FakeConfig):
        full_parser = get_parser(FakeConfig())
        with mock.patch("sys.argv", ["ua", "detach", "--format", "json"]):
            args = full_parser.parse_args()

        assert "json" == args.format
예제 #22
0
 def test_attach_parser_stores_token(self):
     full_parser = get_parser()
     with mock.patch("sys.argv", ["ua", "attach", "token"]):
         args = full_parser.parse_args()
     assert "token" == args.token