Beispiel #1
0
 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"]
Beispiel #2
0
 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"] == []
Beispiel #3
0
 def test_deleting_proposal_after_report(self):
     CommunityRouter.SUPPORT_REQUIREMENT = 1
     result = CommunityRouter(
         "beginbot", "propose", ["!iasip", "The", "Gang", "Steals", "Kappa"]
     ).route()
     Proposal.count() == 1
     result = CommunityRouter("uzi", "support", ["@beginbot"]).route()
     assert BreakingNews.count() == 1
     assert Proposal.count() == 0
Beispiel #4
0
 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"
Beispiel #5
0
 def test_proposals_expire(self):
     proposal = Proposal(user="******",
                         command="iasip",
                         proposal="The Gang Steals Kappa").save()
     OG_PROPOSAL_TIME = Proposal.EXPIRE_TIME_IN_SECS
     assert not proposal.is_expired()
     Proposal.EXPIRE_TIME_IN_SECS = 0
     assert proposal.is_expired()
     Proposal.EXPIRE_TIME_IN_SECS = OG_PROPOSAL_TIME
    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_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"
Beispiel #8
0
 def test_support(self):
     CommunityRouter.SUPPORT_REQUIREMENT = 1
     BreakingNews.count() == 0
     assert Proposal.count() == 0
     result = CommunityRouter(
         "beginbot", "propose", ["!iasip", "The", "Gang", "Steals", "Kappa"]
     ).route()
     result = CommunityRouter("uzi", "support", ["@beginbot"]).route()
     assert result == "@beginbot Thanks You for the support @uzi 1/1"
     assert BreakingNews.count() == 1
    def _propose(self, proposed_command=None):
        if proposed_command:
            args = self.args
        else:
            proposed_command, *args = self.args

        if proposed_command.startswith("!"):
            proposed_command = proposed_command[1:]

        proposal = Proposal(
            user=self.user, command=proposed_command, proposal=" ".join(args),
        )
        proposal.save()

        if "TEST_MODE" not in os.environ:
            # Maybe I should be able to say no notification

            PlaySoundeffectRequest(
                user="******", command="5minutes", notification=False
            ).save()

            Notification("Type !support", duration=300).save()
        return f"Thank you @{self.user} for your proposal. You have 5 minutes to get {self.SUPPORT_REQUIREMENT} supporters"
Beispiel #10
0
 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"
Beispiel #11
0
 def test_it_is_real(self):
     assert Proposal.count() == 0
     Proposal(user="******",
              command="iasip",
              proposal="The Gang Steals Kappa").save()
     assert Proposal.count() == 1
Beispiel #12
0
 def test_find_by_user(self):
     Proposal(user="******",
              command="iasip",
              proposal="The Gang Steals Kappa").save()
     proposal = Proposal.find_by_user("bobby")
     assert proposal["proposal"] == "The Gang Steals Kappa"