Example #1
0
    def test_should_process_and_categorise_yesno_poll_responses(self):
        self.poll_attr['ptype'] = 'yesno'
        self.poll_attr['keyword']  = 'akeyword'
        poll = Poll(**self.poll_attr).save()

        self.poll_response['text'] = 'yes'
        PollResponse(**self.poll_response).save()

        poll_response = PollResponse.objects(**self.poll_response)
        self.assertEqual(1, poll_response.count())

        yes_category = ResponseCategory.objects(**dict(poll=poll, name='yes')).first()

        self.assertEqual(1, PollResponseCategory.objects.count())
        self.assertEqual(1, PollResponseCategory.objects(**dict(response_category=yes_category, poll_response=poll_response.first())).count())

        #a 'NO' Response
        self.poll_response['text'] = 'nah'
        PollResponse(**self.poll_response).save()

        poll_response = PollResponse.objects(**self.poll_response)
        self.assertEqual(1, poll_response.count())

        no_category = ResponseCategory.objects(**dict(poll=poll, name='no')).first()

        self.assertEqual(2, PollResponseCategory.objects.count())
        self.assertEqual(1, PollResponseCategory.objects(**dict(response_category=no_category, poll_response=poll_response.first())).count())

        #a 'unknown' Response
        self.poll_response['text'] = 'very wiered response'
        PollResponse(**self.poll_response).save()

        poll_response = PollResponse.objects(**self.poll_response)
        self.assertEqual(1, poll_response.count())

        unknown_category = ResponseCategory.objects(**dict(poll=poll, name='unknown')).first()

        self.assertEqual(3, PollResponseCategory.objects.count()) #bad response not associated with poll
        self.assertEqual(1, PollResponseCategory.objects(**dict(response_category=unknown_category, poll_response=poll_response.first())).count())

        #should count results
        results_count = poll.yesno_poll_stats()
        self.assertEqual(1, results_count['yes'])
        self.assertEqual(1, results_count['unknown'])
        self.assertEqual(1, results_count['no'])
Example #2
0
    def test_should_process_and_categorise_yesno_poll_responses_when_yesno_is_misplaced(self):
        self.poll_attr['ptype'] = 'yesno'
        self.poll_attr['keyword']  = 'akeyword'
        poll = Poll(**self.poll_attr).save()

        self.poll_response['text'] = 'NECOCPoll a very bad yes answer'
        PollResponse(**self.poll_response).save()

        poll_response = PollResponse.objects(**self.poll_response)
        self.assertEqual(1, poll_response.count())

        yes_category = ResponseCategory.objects(**dict(poll=poll, name='yes')).first()

        self.assertEqual(1, PollResponseCategory.objects.count())
        self.assertEqual(1, PollResponseCategory.objects(**dict(response_category=yes_category, poll_response=poll_response.first())).count())