def test_stealing_from_an_insured_person(self): random.seed(0) madonna = User("madonna") madonna.set_value("cool_points", 1) bowie = User("bowie") bowie.set_value("cool_points", 10) bowie.buy_insurance() assert bowie.insured() handbag = Command("handbag").save().allow_user("bowie") subject = Stealer(thief="madonna", target_sfx="handbag", victim="bowie") result = subject.steal() assert ( result.metadata["stealing_result"] == f"@madonna was blocked by @bowie's insurance! Num Attempts: 0" ) assert not bowie.insured()
def test_buying_insurance(self, irc_msg): user = User("uzi") user.update_cool_points(10) irc_response = irc_msg("uzi", "!insurance") result = CommandRouter(irc_response, logger).build_response() assert user.insured() assert result == "@uzi thank you for purchasing insurance"
def _attempt_robbery(self, thief, command): thief.update_mana(-2) steal_count = BWIA.find_thief(thief) give_count = BWIA.robinhood_score(thief) print(f"This Thief Has Stolen {steal_count} times before") was_caught_stealing, the_odds = CaughtStealing(self._thief, self._target_sfx, self._victim, steal_count, give_count).call() the_odds = f"{the_odds}%" victim = User(self._victim) if victim.insured(): victim.set_value("insured", False) self.metadata[ "stealing_result"] = f"@{self._thief} was blocked by @{self._victim}'s insurance! Num Attempts: {steal_count}" elif was_caught_stealing: thief.update_value("notoriety", 1) self.metadata[ "stealing_result"] = f"@{self._thief} WAS CAUGHT STEALING! Chance of Success: {the_odds}. Num Attempts: {steal_count}" User(self._thief).set_value("mana", 0) else: self._steal(command, thief, the_odds)