Example #1
0
 def test_commands(self):
     subject = User("artmattdank")
     assert subject.commands() == []
     command = Command("flacid")
     command.allow_user("artmattdank")
     assert command.users() == ["artmattdank"]
     assert subject.commands() == ["flacid"]
 def test_buy_more_than_one_random(self):
     user = User("young.thug")
     user.update_cool_points(10)
     assert user.commands() == []
     result = EconomyRouter(user.name, "buy", ["random", 3]).route()
     assert len(user.commands()) == 3
     assert user.cool_points() < 10
Example #3
0
 def test_buying_same_command(self, user_with_points,
                              mock_affordable_commands):
     user = User(user_with_points)
     assert len(user.commands()) == 0
     command = Command("mchdtmd").save()
     result = Buyer(user.name, command.name).buy()
     assert len(user.commands()) == 1
     result = Buyer(user.name, command.name).buy()
     assert len(user.commands()) == 1
Example #4
0
 def test_remove_all_commands(self):
     subject = User("artmattdank")
     assert subject.commands() == []
     command = Command("flacid")
     command.allow_user("artmattdank")
     assert command.permitted_users() == ["artmattdank"]
     assert subject.commands() == ["flacid"]
     subject.remove_all_commands()
     assert subject.commands() == []
     assert command.permitted_users() == []
 def test_trying_to_steal_sound_you_do_not_own(self):
     madonna = User("madonna")
     bowie = User("bowie")
     subject = Stealer(thief="madonna", target_sfx="handbag", victim="bowie")
     assert "handbag" not in madonna.commands()
     assert "handbag" not in bowie.commands()
     result = subject.steal()
     assert isinstance(result, Result)
     assert "handbag" not in madonna.commands()
     assert "handbag" not in bowie.commands()
     result.metadata[
         "stealing_result"
     ] == "@madonna failed to steal !handbag from @bowie"
 def test_stealing(self):
     madonna = User("madonna")
     bowie = User("bowie")
     handbag = Command("handbag").save().allow_user("bowie")
     subject = Stealer(thief="madonna", target_sfx="handbag", victim="bowie")
     assert "handbag" not in madonna.commands()
     assert "handbag" in bowie.commands()
     result = subject.steal()
     assert isinstance(result, Result)
     assert "handbag" in madonna.commands()
     assert "handbag" not in bowie.commands()
     assert madonna.mana() == 1
     result.metadata["stealing_result"] == "@madonna stole from @bowie"
    def fetch_permissions(cls, user, target_command, target_user):
        # Personal Permissions
        if not target_command and not target_user:
            user = User(user)
            stats = user.stats()
            sfx_count = len(user.commands())
            return f"{stats} | SFX Count: {sfx_count}"

        # User Permissions
        if target_user and not target_command:
            title = f"@{target_user}'s"
            sfx_count = len(User(target_user).commands())
            stats = User(target_user).stats()
            return f"{title} {stats} | SFX Count: {sfx_count}"

        # Command Permissions
        if target_command and not target_user:
            command = Command(target_command)
            user_permissions = " ".join(
                [f"@{perm}" for perm in command.users()])

            from chat_thief.models.sfx_vote import SFXVote

            link = f"{BASE_URL}/commands/{target_command}.html"
            like_ratio = SFXVote(target_command).like_to_hate_ratio()
            stats = f"!{target_command} | Cost: {command.cost()} | Health: {command.health()} | Like Ratio {round(like_ratio)}% | {link}"
            return stats
 def test_caught_stealing(self):
     random.seed(5)
     madonna = User("madonna")
     bowie = User("bowie")
     handbag = Command("handbag").save().allow_user("bowie")
     subject = Stealer(thief="madonna", target_sfx="handbag", victim="bowie")
     assert madonna.mana() == 3
     assert "handbag" not in madonna.commands()
     assert "handbag" in bowie.commands()
     result = subject.steal()
     assert "handbag" not in madonna.commands()
     assert "handbag" in bowie.commands()
     assert isinstance(result, Result)
     assert madonna.mana() == 0
     assert (
         "@madonna WAS CAUGHT STEALING! Chance of Success:"
         in result.metadata["stealing_result"]
     )
Example #9
0
 def test_purge_theme_songs(self):
     uzi = User("uzi")
     illegal_cmd = Command("beginbot")
     illegal_cmd.save()
     illegal_cmd.allow_user("uzi")
     Command("damn").save()
     assert Command.count() == 2
     DataScrubber.purge_theme_songs()
     assert Command.count() == 1
     assert uzi.commands() == []
Example #10
0
    def test_buying(self):
        subject = Buyer(user="******", target_sfx="handbag")
        user = User("madonna")
        user.set_value("cool_points", 1)
        result = subject.buy()

        assert isinstance(result, Result)
        assert result.user == "madonna"
        assert result.command == "buy"
        assert "handbag" in user.commands()
        assert result.cool_points_diff == -1
Example #11
0
def profile(username):
    user = User(username)
    commands = user.commands()
    stats = user.stats()
    print(f"{user=}")
    print(f"{commands=}")
    print(f"{stats=}")
    return render_template("user.html",
                           user=user,
                           stats=stats,
                           commands=commands)
Example #12
0
    def test_purge_duplicate_commands(self):
        uzi = User("uzi")
        illegal_cmd = Command("clap")
        illegal_cmd.permitted_users = ["uzi", "uzi"]
        illegal_cmd.save()

        illegal_cmd = Command("clap")
        illegal_cmd.permitted_users = ["uzi", "uzi"]
        illegal_cmd.save()
        assert Command.count() == 2

        DataScrubber.purge_duplicates()
        assert Command.count() == 1
        assert uzi.commands() == ["clap"]
Example #13
0
    def test_peace_keeper_losing_it_all(self):
        fence_sitter = User("CoolCat")
        fence_sitter.save()
        clap = Command("clap")
        clap.allow_user(fence_sitter.name)

        damn_command = Command("damn")
        peace_keeper = User("picakhu")
        damn_command.allow_user(peace_keeper.name)
        Vote(peace_keeper.name).vote("peace")
        assert peace_keeper.name in damn_command.users()

        revolutionary = User("beginbot")
        Vote(revolutionary.name).vote("revolution")
        revolutionary.update_cool_points(11)
        subject = Revolution(revolutionary.name)
        subject.attempt_coup("revolution")

        assert peace_keeper.name not in damn_command.users()
        assert revolutionary.name in damn_command.users()
        assert "damn" not in fence_sitter.commands()
        assert fence_sitter.name not in clap.users()