Esempio n. 1
0
    def test_save_poll(self):
        Poll(**self.poll).save()
        polls = Poll.objects(**self.poll)
        self.assertEqual(1, polls.count())

        poll = polls.first()
        self.assertIn(self.target_locations[0], poll.target_locations)
        self.assertIn(self.target_locations[1], poll.target_locations)
Esempio n. 2
0
 def _assign_if_is_yesno(self):
     if self.text.strip() in settings.YES_WORDS or self.text.strip() in settings.NO_WORDS:
         return Poll.objects(ptype='yesno', open=True).order_by('-created_at').first()
     elif fuzzy_match_strings(self.text, settings.YES_WORDS) or fuzzy_match_strings(self.text, settings.NO_WORDS):
         return Poll.objects(ptype='yesno', open=True).order_by('-created_at').first()
     else:
         # return None
         #always asign uninteligibal responses to the last yes/no poll (possibility to distort poll results)
         return Poll.objects(ptype='yesno', open=True).order_by('-created_at').first()
Esempio n. 3
0
    def test_should_know_its_number_of_responses(self):
        poll = Poll(**self.poll).save()
        poll_response_attr = dict(phone_no='123455', text="NECOC There is a fire", relayer_id=234,
                        run_id=23243, poll=poll)

        poll_response = PollResponse(**poll_response_attr).save()

        self.assertEqual(1, poll.number_of_responses())
        self.assertIn(poll_response, poll.responses())
Esempio n. 4
0
    def test_should_save_yesno_poll_with_default_yesno_categories(self):
        self.poll['ptype'] = 'yesno'
        poll = Poll(**self.poll).save()

        self.assertEqual(1, Poll.objects.count())
        self.assertEqual(True, poll.is_yesno_poll())

        yes_category = ResponseCategory.objects(**dict(poll=poll, name='yes')).first()
        no_category = ResponseCategory.objects(**dict(poll=poll, name='no')).first()
        self.assertEqual(2, Rule.objects.count())
        self.assertEqual(u'someYES|Yeahregex', Rule.objects(**dict(response_category=yes_category)).first().regex)
        self.assertEqual(u'someNo|NAhregex', Rule.objects(**dict(response_category=no_category)).first().regex)
Esempio n. 5
0
 def _assign_if_is_yesno(self):
     if self.text.strip() in settings.YES_WORDS or self.text.strip(
     ) in settings.NO_WORDS:
         return Poll.objects(ptype='yesno',
                             open=True).order_by('-created_at').first()
     elif fuzzy_match_strings(self.text,
                              settings.YES_WORDS) or fuzzy_match_strings(
                                  self.text, settings.NO_WORDS):
         return Poll.objects(ptype='yesno',
                             open=True).order_by('-created_at').first()
     else:
         # return None
         #always asign uninteligibal responses to the last yes/no poll (possibility to distort poll results)
         return Poll.objects(ptype='yesno',
                             open=True).order_by('-created_at').first()
Esempio n. 6
0
 def _assign_poll(self):
     text = self.split_text()
     if len(text):
         active_keywords = [poll.keyword for poll in self._open()]
         if len(active_keywords):
             for kw in active_keywords:
                 if kw in text:
                     return Poll.objects(keyword=kw).order_by('-created_at').first()
                 else:
                     return self._assign_if_is_yesno()
Esempio n. 7
0
 def _assign_poll(self):
     text = self.split_text()
     if len(text):
         active_keywords = [poll.keyword for poll in self._open()]
         if len(active_keywords):
             for kw in active_keywords:
                 if kw in text:
                     return Poll.objects(
                         keyword=kw).order_by('-created_at').first()
                 else:
                     return self._assign_if_is_yesno()
Esempio n. 8
0
    def test_should_auto_close_old_polls(self):
        keywords = ['someword', 'otherkey', 'another']
        for kw in keywords:
            self.poll['keyword'] = kw
            Poll(**self.poll).save()
            time.sleep(1)

        self.assertEqual(3, Poll.objects.count())
        self.assertEqual(2, Poll.objects(open=True).count())
        self.assertEqual(1, Poll.objects(open=False).count())
        self.assertEqual(True, Poll.objects(keyword='otherkey').first().open)
        self.assertEqual(True, Poll.objects(keyword='another').first().open)
        self.assertEqual(False, Poll.objects(keyword='someword').first().open)
Esempio n. 9
0
 def _open(self):
     return Poll.objects(open=True).order_by('-created_at')
Esempio n. 10
0
    def test_should_know_its_number_of_participants(self):
        poll = Poll(**self.poll).save()

        self.assertEqual(4, poll.number_of_participants())
Esempio n. 11
0
 def test_should_not_save_a_poll_if_question_is_more_than_160_characters(self):
     self.poll['question'] = "l"*161
     self.assertRaises(ValidationError, Poll(**self.poll).save)
Esempio n. 12
0
 def test_should_not_save_a_poll_if_keyword_is_more_than_10_characters(self):
     self.poll['keyword'] = "l"*11
     self.assertRaises(ValidationError, Poll(**self.poll).save)
Esempio n. 13
0
 def test_should_not_save_a_poll_if_key_is_not_unique(self):
     Poll(**self.poll).save()
     self.assertRaises(NotUniqueError, Poll(**self.poll).save)
Esempio n. 14
0
 def _open(self):
     return Poll.objects(open=True).order_by('-created_at')