def test_support(test): Proposal(user="******", command="iasip", proposal="The Gang Steals Kappa").save() proposal = Proposal.last() Proposal.support("bobby", proposal.doc_id, "sumo") assert Proposal.find_by_user("bobby")["supporters"] == ["sumo"]
def _support(self): if self.args: user = self.args[0] else: user = Proposal.last()["user"] if user.startswith("@"): user = user[1:] proposal = Proposal.find_by_user(user) if Proposal(user).is_expired(): if proposal: print(f"Deleteing Expired Proposal from: {user}") Proposal.delete(proposal.doc_id) else: print(f"Did not find Proposal for {user}") total_support = len(proposal["supporters"]) + 1 support_msg = "" if proposal: support_msg = Proposal.support(user, proposal.doc_id, self.user) if total_support >= self.SUPPORT_REQUIREMENT: BreakingNews( scope=proposal["proposal"], category=proposal["command"] ).save() if proposal: print(f"Deleteing Proposal from: {user}, since it was approved!") Proposal.delete(proposal.doc_id) return support_msg + f" {total_support}/{self.SUPPORT_REQUIREMENT}"
def test_cannot_support_yourself(self): Proposal(user="******", command="iasip", proposal="The Gang Steals Kappa").save() proposal = Proposal.last() result = Proposal.support("bobby", proposal.doc_id, "bobby") assert result == "Can't support yourself @bobby" assert Proposal.find_by_user("bobby")["supporters"] == []
def test_propose(self, irc_msg): irc_response = irc_msg("beginbot", "!propose !iasip The Gang Steals Kappa") result = CommandRouter(irc_response, logger).build_response() assert "Thank you @beginbot for your proposal" in result last_proposal = Proposal.last() assert last_proposal["proposal"] == "The Gang Steals Kappa" assert last_proposal["command"] == "iasip"
def test_propose(self): assert Proposal.count() == 0 result = CommunityRouter( "beginbot", "propose", ["!iasip", "The", "Gang", "Steals", "Kappa"] ).route() assert "Thank you @beginbot for your proposal" in result last = Proposal.last() assert last["proposal"] == "The Gang Steals Kappa" assert last["command"] == "iasip"
def test_no_double_support(self): Proposal(user="******", command="iasip", proposal="The Gang Steals Kappa").save() proposal = Proposal.last() result = Proposal.support("bobby", proposal.doc_id, "sumo") assert Proposal.find_by_user("bobby")["supporters"] == ["sumo"] assert result == "@bobby Thanks You for the support @sumo" result = Proposal.support("bobby", proposal.doc_id, "sumo") assert Proposal.find_by_user("bobby")["supporters"] == ["sumo"] assert result == "You already supported! @sumo"