コード例 #1
0
ファイル: session.py プロジェクト: adammck/shadow-poll
 def setup_choices(self,question):
     choice1 = Choice(code= 'a',question=question, text="a")
     choice2 = Choice(code= 'b',question=question, text="a")
     choice3 = Choice(code= 'c',question=question, text="a")
     choice1.save()
     choice2.save()
     choice3.save()
コード例 #2
0
ファイル: handlers.py プロジェクト: andersoncardoso/dump
 def get(self, *args, **kwargs):
     form = FormPoll()
     xsrf = self.xsrf_form_html()
     polls = []
     for p in Poll.objects:
         polls.append((p, Choice.objects(poll=p)))
     self.render("index.html", polls=polls, xsrf=xsrf, form=form)
コード例 #3
0
ファイル: style_tests.py プロジェクト: adammck/shadow-poll
 def setUp(self):
     # clean up
     Question.objects.all().delete()
     UserResponse.objects.all().delete()
     
     # user
     self.backend = PersistantBackend(slug="MockBackend1")
     self.backend.save()
     self.pconnection = PersistantConnection(backend=self.backend, 
                                             reporter=None, 
                                             identity="user_1_identity")
     self.pconnection.save()
     self.governorate1 = Governorate.objects.get(pk=1)
     self.district1 = District.objects.get(pk=29)
     
     self.user = User(connection=self.pconnection, age=12, gender='m', 
                      governorate=self.governorate1.code, district=self.district1.code)
     self.user.save()
     
     # create categorical poll
     self.question1 = Question(text = 'question1', max_choices = 1)
     self.question1.save()
     yellow = Color(file_name="yellow.png", code="#yellow")
     yellow.save()
     fruits = Category(name="fruits", color=yellow)
     fruits.save()
     red = Color(file_name="red.png", code="#red")
     red.save()
     meat = Category(name="meat", color=red)
     meat.save()
     self.green = Color(file_name="green.png", code="#green")
     self.green.save()
     vegetables = Category(name="vegetables", color=self.green)
     vegetables.save()
     self.apple =Choice(code= 'a',question = self.question1, 
                        text="apple", category=fruits)
     self.apple.save()
     self.bear = Choice(code= 'b',question = self.question1, 
                        text="bear", category=meat)
     self.bear.save()
     self.cabbage = Choice(code= 'c',question = self.question1, 
                           text="cabbage", category=vegetables)
     self.cabbage.save()
     self.dillpickle = Choice(code= 'd',question = self.question1, 
                              text="dillpickle", category=vegetables)
     self.dillpickle.save()
コード例 #4
0
ファイル: handlers.py プロジェクト: andersoncardoso/dump
 def post(self, *args, **kwargs):
     self.check_xsrf_cookie()
     form = FormPoll(self.request.arguments)
     if form.validate():
         p = Poll()
         p.question = form.question.data
         p.save()
         for f in ['choice1', 'choice2', 'choice3']:
             if f in self.request.arguments:
                 c = Choice()
                 c.choice = getattr(form, f).data
                 c.poll = p
                 c.save()
         self.return_json({'success':True})
     else:
         d = {'success':False}
         d.update(form.errors)
         self.return_json(d)
コード例 #5
0
class ValidAnswerResponderTest(TestCase):

    def setUp(self):
        self.user = User()
        self.q = Questionnaire(trigger = "trigger", max_retries=3)
        self.q.save()
        self.session = UserSession()
        self.question =Question(text="what")
        self.question.save()
        self.choice1 = Choice(code= 'a',question=self.question, text="a")
        self.choice2 = Choice(code= 'b',question=self.question, text="a")
        self.choice3 = Choice(code= 'c',question=self.question, text="a")
        self.choice1.save()
        self.choice2.save()
        self.choice3.save()
        
        self.next_question  = Question(text="next")

        self.session.question = self.question
        self.kwargs =  {"user": self.user,
                    "next_question" :self.next_question ,
                    "session" : self.session
                        
                    }
        self.trigger_responder  = ValidAnswerResponder(self.kwargs)


    def test_criteria_for_trigger(self):
        self.assertEquals(self.trigger_responder.criteria("c"), True)
        self.assertEquals(self.trigger_responder.criteria("w"), False)
        
    def test_valid_answer_response(self):
        pass
コード例 #6
0
    def setUp(self):
        self.user = User()
        self.q = Questionnaire(trigger = "trigger", max_retries=3)
        self.q.save()
        self.session = UserSession()
        self.question =Question(text="what")
        self.question.save()
        self.choice1 = Choice(code= 'a',question=self.question, text="a")
        self.choice2 = Choice(code= 'b',question=self.question, text="a")
        self.choice3 = Choice(code= 'c',question=self.question, text="a")
        self.choice1.save()
        self.choice2.save()
        self.choice3.save()
        
        self.next_question  = Question(text="next")

        self.session.question = self.question
        self.kwargs =  {"user": self.user,
                    "next_question" :self.next_question ,
                    "session" : self.session
                        
                    }
        self.trigger_responder  = ValidAnswerResponder(self.kwargs)