def test_all_props(self):
     young_thug = User("young.thug")
     young_thug.update_street_cred(10)
     uzi = User("uzi")
     result = EconomyRouter(young_thug.name, "props",
                            [uzi.name, "all"]).route()
     assert young_thug.cool_points() == 0
     assert young_thug.street_cred() == 0
     assert uzi.cool_points() == 10
Example #2
0
 def test_bankrupt(self):
     subject = User("artmattdank")
     subject.update_street_cred(10)
     subject.update_cool_points(10)
     assert subject.cool_points() == 10
     assert subject.street_cred() == 10
     subject.bankrupt()
     assert subject.cool_points() == 0
     assert subject.street_cred() == 0
    def test_props(self):
        young_thug = User("young.thug")
        uzi = User("uzi")

        uzi.update_street_cred(10)

        assert young_thug.cool_points() == 0
        assert young_thug.street_cred() == 0
        assert uzi.street_cred() == 10

        result = EconomyRouter(uzi.name, "props", [young_thug.name]).route()
        assert young_thug.cool_points() == 1
        assert young_thug.street_cred() == 0
        assert uzi.street_cred() == 9
 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 #5
0
 def test_attempt_coup_without_enough_cool_points(self):
     revolutionary = "beginbot"
     user = User(revolutionary)
     assert user.street_cred() == 0
     assert user.cool_points() == 0
     user.update_street_cred(1)
     user.update_cool_points(1)
     subject = Revolution(revolutionary)
     tide = Vote.have_tables_turned(1)
     result = subject.attempt_coup(tide)
     assert user.street_cred() == 0
     assert user.cool_points() == 0
     assert (
         result ==
         "@beginbot is now Bankrupt, that will teach you a lesson. Coups require 11 Cool Points"
     )
Example #6
0
    def test_peace_scenario(self):
        fence_sitter = User("CoolCat")
        fence_sitter.save()
        clap_command = Command("clap")
        clap_command.allow_user(fence_sitter.name)
        fence_sitter.update_street_cred(10)
        fence_sitter.update_cool_points(10)

        peace_keeper = User("picakhu")
        damn_command = Command("damn")
        damn_command.allow_user(peace_keeper.name)
        Vote(peace_keeper.name).vote("peace")
        peace_keeper.update_cool_points(11)
        peace_keeper.update_street_cred(10)
        peace_keeper.update_cool_points(10)

        peace_keeper2 = User("beginbotsmonster")
        wassup_command = Command("wassup_command")
        wassup_command.allow_user(peace_keeper2.name)
        Vote(peace_keeper2.name).vote("peace")

        revolutionary = User("beginbot")
        listen_command = Command("listen")
        listen_command.allow_user(revolutionary.name)
        Vote(revolutionary.name).vote("revolution")

        subject = Revolution(peace_keeper.name)
        subject.attempt_coup("peace")

        assert peace_keeper.name in listen_command.users()
        assert peace_keeper2.name not in listen_command.users()
        assert revolutionary.name not in listen_command.users()
        assert fence_sitter.name not in clap_command.users()
        assert fence_sitter.street_cred() == 10
        assert fence_sitter.cool_points() == 10
 def test_try_steal_unowned_sound(self, mock_present_users, mock_find_random_user):
     User("uzi").update_cool_points(10)
     user = User("young.thug")
     user.update_cool_points(10)
     result = EconomyRouter(user.name, "steal", ["clap", "uzi"]).route()
     assert result == "!clap is not owned by @uzi"
     assert user.cool_points() == 10
Example #8
0
 def test_do_over(self):
     command = Command("damn")
     command.save()
     command.increase_cost(9)
     user = User("future", 100)
     user.save()
     assert user.cool_points() == 100
     result = ModeratorRouter("beginbotbot", "do_over", ["@future"]).route()
     assert command.cost() == 5
     assert result == "Society now must rebuild"
Example #9
0
 def test_attempt_coup_with_enough_cool_points(self):
     revolutionary = "beginbot"
     user = User(revolutionary)
     user.update_street_cred(1)
     user.update_cool_points(11)
     subject = Revolution(revolutionary)
     tide = Vote.have_tables_turned(1)
     subject.attempt_coup(tide)
     assert user.street_cred() == 1
     assert user.cool_points() == 0
     assert self.coup.cost() == 33
 def test_try_steal_fake_sound(self, mock_present_users, mock_find_random_user):
     User("uzi").update_cool_points(10)
     Command("clap").allow_user("uzi")
     user = User("young.thug")
     user.update_cool_points(10)
     result = EconomyRouter(user.name, "steal", ["fakesound"]).route()
     assert (
         result
         == "@young.thug you must specify who and what you want to steal. Invalid Args: fakesound"
     )
     assert user.cool_points() == 10
Example #11
0
    def test_paperup(self, monkeypatch):
        user = User("coltrane")

        def _fake_parse(self):
            return FakeParser()

        monkeypatch.setattr(CommandParser, "parse", _fake_parse)

        result = BasicInfoRouter("beginbotbot", "paperup",
                                 ["coltrane"]).route()
        assert user.cool_points() == 100
        assert user.street_cred() == 100
        assert result == "@coltrane has been Papered Up"
Example #12
0
    def test_bankrupt(self, monkeypatch):
        user = User("coltrane")
        user.update_cool_points(10)
        user.update_street_cred(10)

        def _fake_parse(self):
            return FakeParser()

        monkeypatch.setattr(CommandParser, "parse", _fake_parse)

        result = BasicInfoRouter("beginbotbot", "bankrupt",
                                 ["coltrane"]).route()
        assert user.cool_points() == 0
        assert user.street_cred() == 0
        assert result == "@coltrane is now Bankrupt"
Example #13
0
    def _buy_sfx(self, user: User, effect: str) -> PurchaseReceipt:
        current_cool_points = user.cool_points()

        if effect not in SoundeffectsLibrary.fetch_soundeffect_names():
            return PurchaseReceipt(
                user=user.name,
                sfx=effect,
                result=PurchaseResult.InvalidSFX,
                cool_points=current_cool_points,
            )

        command = Command(effect)
        command_cost = command.cost()

        if Command(effect).allowed_to_play(user.name):
            return PurchaseReceipt(
                user=user.name,
                sfx=effect,
                cost=command_cost,
                result=PurchaseResult.AlreadyOwn,
                cool_points=current_cool_points,
            )

        if current_cool_points >= command_cost:
            user.update_cool_points(-command_cost)
            command.allow_user(user.name)
            command.increase_cost()

            return PurchaseReceipt(
                user=user.name,
                sfx=effect,
                cool_points=current_cool_points,
                result=PurchaseResult.SuccessfulPurchase,
                cost=command_cost,
            )
        else:
            return PurchaseReceipt(
                user=user.name,
                sfx=effect,
                cool_points=current_cool_points,
                result=PurchaseResult.TooPoor,
                cost=command_cost,
            )
Example #14
0
    def attempt_coup(self, tide: str) -> str:
        user = User(self.revolutionary)
        coup_cost = self.coup.cost()

        print(f"Cool Points: {user.cool_points()} | Coup Cost: {coup_cost}")

        if user.cool_points() >= coup_cost or self.revolutionary == "beginbotbot":
            print("WE HAVE ENOUGH FOR A REVOLUTION")
            user.update_cool_points(-coup_cost)
            self.coup.increase_cost(coup_cost * 2)

            if "TEST_MODE" not in os.environ:
                os.system(f"so {tide}")

            return self._turn_the_tides(tide)
        else:
            print(f"YOU CAN'T TRIGGER A REVOLUTION: {coup_cost}")
            self._punish_revolutionary()
            return f"@{self.revolutionary} is now Bankrupt, that will teach you a lesson. Coups require {coup_cost} Cool Points"
    def test_share(self):
        user = User("fake_user")
        user.update_cool_points(1)
        command = Command("damn")
        friend = User("bizmarkie")

        command.allow_user(user.name)
        assert user.name in command.users()
        assert friend.name not in command.users()

        subject = CommandSharer(
            user=user.name, command=command.name, friend=friend.name,
        )

        subject.share()

        assert user.name in command.users()
        assert friend.name in command.users()
        assert user.cool_points() == 0
        assert command.cost() == 3