Esempio n. 1
0
    def setUp(self):
        super(VotingTestCase, self).setUp()
        self.contest = Election(key_name=self.id(),
                                title="Yet another contest")
        self.contest.put()
        candidates = [
            "Favorite",
            "Middling",
            "Underdog",
        ]

        self.candidates = []
        for title in candidates:
            candidate = Candidate(title=title, parent=self.contest)
            candidate.put()
            self.candidates.append(str(candidate.key().id()))

        candidates = db.GqlQuery(
            "SELECT * FROM Candidate WHERE ANCESTOR IS :1", self.contest)
        self.assertEqual(set(str(c.key().id()) for c in candidates),
                         set(self.candidates))

        self.user = self.login()
        self.app = TestApp(application)
        self.page = self.app.get("/" + self.contest.key().name() + "/vote")
Esempio n. 2
0
 def post(self):
     election = self.election()
     if not election:
         return
     
     try:
         candidate = Candidate(parent=election)
         
         candidate.title = self.request.get("title").strip()
         candidate.description = self.request.get("description").strip()
         
         candidate.put()
         self.redirect("/%s/candidate" % election.key().name())
     except Exception, err:
         logging.exception("Failed to save candidate: %r", repr(locals()))
         self.render("candidate.html", election=election, candidates=[], defaults=candidate, error=err)
         raise
Esempio n. 3
0
    def setUp(self):
        super(VotingTestCase, self).setUp()
        self.contest = Election(key_name=self.id(), title="Yet another contest")
        self.contest.put()
        candidates = ["Favorite", "Middling", "Underdog"]

        self.candidates = []
        for title in candidates:
            candidate = Candidate(title=title, parent=self.contest)
            candidate.put()
            self.candidates.append(str(candidate.key().id()))

        candidates = db.GqlQuery("SELECT * FROM Candidate WHERE ANCESTOR IS :1", self.contest)
        self.assertEqual(set(str(c.key().id()) for c in candidates), set(self.candidates))

        self.user = self.login()
        self.app = TestApp(application)
        self.page = self.app.get("/" + self.contest.key().name() + "/vote")
Esempio n. 4
0
    def post(self):
        election = self.election()
        if not election:
            return

        try:
            candidate = Candidate(parent=election)

            candidate.title = self.request.get("title").strip()
            candidate.description = self.request.get("description").strip()

            candidate.put()
            self.redirect("/%s/candidate" % election.key().name())
        except Exception, err:
            logging.exception("Failed to save candidate: %r", repr(locals()))
            self.render("candidate.html",
                        election=election,
                        candidates=[],
                        defaults=candidate,
                        error=err)
            raise