Пример #1
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"
Пример #2
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"]
Пример #3
0
    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}"
Пример #4
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"] == []
Пример #5
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"