Esempio n. 1
0
def test_command_exit_exception():
    """Exit command raises the GamatrixExit exception."""
    exit_command = commands.get_command("exit")
    cfg = utils.Config()
    cfg.command_args_val = []
    with pytest.raises(types.GamatrixExit):
        exit_command.run(utils.Config(), utils.NoneClientProvider())
Esempio n. 2
0
 def test_games_command_fails_with_incorrect_parameters(self):
     """Games command elegantly handles incorrect parameters."""
     games_cmd = spcmd.get_command("games")
     assert games_cmd
     cli = utils.NoneClientProvider()
     self.cfg.command_args_val = ["--something-not-there"]
     try:
         games_cmd.run(self.cfg, cli)
         assert "Games command did not recognize bad input." == ""
     except docopt.DocoptExit as e:
         assert "games" in e.usage.lower()
         assert "--force" in e.usage.lower()
Esempio n. 3
0
 def test_friend_force(self):
     """Friend command issues the '-f' flag correctly and runs when it is issued."""
     friendcmd = spcmd.get_command("friends")
     cli = utils.SettableClientProvider()
     cli.set_friends = [
         sptype.FriendInformation(name="d3r3kk", user_id="12345"),
         sptype.FriendInformation(name="other", user_id="67890"),
     ]
     self.cfg.force_flag = True
     out = friendcmd.run(self.cfg, cli)
     assert cli.get_friends_forced is True
     for row in out:
         assert "d3r3kk" in row or "other" in row
Esempio n. 4
0
    def test_get_games_for_friend_is_forced(self):
        """Ensure we can get a game for a friend."""
        friends_list = utils.get_friends(count=1)
        games_cmd = spcmd.get_command("games")
        self.cfg.command_args_val = [f"--friend={friends_list[0].name}", "--force"]
        cli_provider = utils.SettableClientProvider()
        cli_provider.set_friends = friends_list
        friends_games = utils.get_games(1)
        cli_provider.set_games = friends_games
        output = games_cmd.run(self.cfg, cli_provider)

        assert cli_provider.get_games_forced is True
        assert any(friends_games[0].name in s for s in output)
Esempio n. 5
0
 def test_friend_command_runs(self):
     """Friend command runs when given appropriate cmdline options."""
     friendcmd = spcmd.get_command("friends")
     cli = utils.SettableClientProvider()
     cli.set_friends = [
         sptype.FriendInformation(name="d3r3kk", user_id="12345"),
         sptype.FriendInformation(name="other", user_id="67890"),
     ]
     self.cfg.command_args_val = []
     out = friendcmd.run(self.cfg, cli)
     assert out
     assert len(out) == 2
     for row in out:
         assert "d3r3kk" in row or "other" in row
Esempio n. 6
0
    def test_get_games_for_friend_with_space_in_name(self):
        """Ensure we can get a game for a friend."""
        friends_list = utils.get_friends(count=1, name_prefix="Space in name ")
        games_cmd = spcmd.get_command("games")
        assert games_cmd
        self.cfg.command_args_val = [f"--friend='{friends_list[0].name}'"]
        cli_provider = utils.SettableClientProvider()
        cli_provider.set_friends = friends_list
        friends_games = utils.get_games(1)
        cli_provider.set_games = friends_games
        output = games_cmd.run(self.cfg, cli_provider)

        assert cli_provider.get_games_forced is False
        assert any(friends_games[0].name in s for s in output)
Esempio n. 7
0
 def test_friend_fails_bad_cmdline(self):
     """Friend command fails when given unknown commandline argument."""
     friendcmd = spcmd.get_command("friends")
     cli = utils.SettableClientProvider()
     cli.set_friends = [
         sptype.FriendInformation(name="d3r3kk", user_id="12345"),
         sptype.FriendInformation(name="other", user_id="67890"),
     ]
     self.cfg.command_args_val = ["--jibbity-flibbit"]
     try:
         friendcmd.run(self.cfg, cli)
         assert (
             "Argument parsing for friends command did not recognize bad input."
             == ""
         )
     except docopt.DocoptExit as e:
         assert "friends" in e.usage.lower()
         assert "usage" in e.usage.lower()
Esempio n. 8
0
 def test_friend_command_exists(self):
     """Friend command exists and is the right type."""
     friendcmd = spcmd.get_command("friends")
     assert friendcmd
     assert isinstance(friendcmd, spcmd.Friends)
Esempio n. 9
0
def test_get_command_with_args():
    """Get a legit command back."""
    cmd = commands.get_command("exit")
    assert cmd
    assert isinstance(cmd, commands.Exit)
Esempio n. 10
0
def test_command_unknown():
    """Ensure unknown commands are handled without exceptions."""
    unkown_command = commands.get_command("no_command_here")
    assert unkown_command is None
Esempio n. 11
0
 def test_get_games_command(self):
     """Ensure get_command returns a proper games command instance."""
     games_cmd = spcmd.get_command("games")
     assert games_cmd
     assert isinstance(games_cmd, spcmd.Games)