<commit_before>from django.test.client import Client
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User

from go.vumitools.tests.utils import VumiApiCommand
from go.apps.tests.base import DjangoGoApplicationTestCase
from go.base.utils import vumi_api_for_user


TEST_GROUP_NAME = u"Test Group"
TEST_CONTACT_NAME = u"Name"
TEST_CONTACT_SURNAME = u"Surname"
TEST_SUBJECT = u"Test Conversation"


class SurveyTestCase(DjangoGoApplicationTestCase):

    fixtures = ['test_user']

    def setUp(self):
        super(SurveyTestCase, self).setUp()
        self.client = Client()
        self.client.login(username='username', password='password')

        self.setup_riak_fixtures()

    def setup_riak_fixtures(self):
        self.user = User.objects.get(username='username')
        self.user_api = vumi_api_for_user(self.user)
        self.contact_store = self.user_api.contact_store
        self.contact_store.contacts.enable_search()
        self.conv_store = self.user_api.conversation_store

        # We need a group
        group = self.contact_store.new_group(TEST_GROUP_NAME)
        self.group_key = group.key

        # Also a contact
        contact = self.contact_store.new_contact(
            name=TEST_CONTACT_NAME, surname=TEST_CONTACT_SURNAME,
            msisdn=u"+27761234567")
        contact.add_to_group(group)
        contact.save()
        self.contact_key = contact.key

        # And a conversation
        conversation = self.conv_store.new_conversation(
            conversation_type=u'survey', subject=TEST_SUBJECT,
            message=u"Test message", delivery_class=u"sms",
            delivery_tag_pool=u"longcode", groups=[self.group_key])
        self.conv_key = conversation.key

    def get_wrapped_conv(self):
        conv = self.conv_store.get_conversation_by_key(self.conv_key)
        return self.user_api.wrap_conversation(conv)

    def run_new_conversation(self, selected_option, pool, tag):
        # render the form
        self.assertEqual(len(self.conv_store.list_conversations()), 1)
        response = self.client.get(reverse('survey:new'))
        self.assertEqual(response.status_code, 200)
        # post the form
        response = self.client.post(reverse('survey:new'), {
            'subject': 'the subject',
            'message': 'the message',
            # 'start_date': datetime.utcnow().strftime('%Y-%m-%d'),
            # 'start_time': datetime.utcnow().strftime('%H:%M'),
            'delivery_class': 'sms',
            'delivery_tag_pool': selected_option,
        })
        self.assertEqual(len(self.conv_store.list_conversations()), 2)
        conversation = max(self.conv_store.list_conversations(),
                           key=lambda c: c.created_at)
        self.assertEqual(conversation.delivery_class, 'sms')<commit_msg>removing comment code from test<commit_after>from django.test.client import Client
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User

from go.vumitools.tests.utils import VumiApiCommand
from go.apps.tests.base import DjangoGoApplicationTestCase
from go.base.utils import vumi_api_for_user


TEST_GROUP_NAME = u"Test Group"
TEST_CONTACT_NAME = u"Name"
TEST_CONTACT_SURNAME = u"Surname"
TEST_SUBJECT = u"Test Conversation"


class SurveyTestCase(DjangoGoApplicationTestCase):

    fixtures = ['test_user']

    def setUp(self):
        super(SurveyTestCase, self).setUp()
        self.client = Client()
        self.client.login(username='username', password='password')

        self.setup_riak_fixtures()

    def setup_riak_fixtures(self):
        self.user = User.objects.get(username='username')
        self.user_api = vumi_api_for_user(self.user)
        self.contact_store = self.user_api.contact_store
        self.contact_store.contacts.enable_search()
        self.conv_store = self.user_api.conversation_store

        # We need a group
        group = self.contact_store.new_group(TEST_GROUP_NAME)
        self.group_key = group.key

        # Also a contact
        contact = self.contact_store.new_contact(
            name=TEST_CONTACT_NAME, surname=TEST_CONTACT_SURNAME,
            msisdn=u"+27761234567")
        contact.add_to_group(group)
        contact.save()
        self.contact_key = contact.key

        # And a conversation
        conversation = self.conv_store.new_conversation(
            conversation_type=u'survey', subject=TEST_SUBJECT,
            message=u"Test message", delivery_class=u"sms",
            delivery_tag_pool=u"longcode", groups=[self.group_key])
        self.conv_key = conversation.key

    def get_wrapped_conv(self):
        conv = self.conv_store.get_conversation_by_key(self.conv_key)
        return self.user_api.wrap_conversation(conv)

    def run_new_conversation(self, selected_option, pool, tag):
        # render the form
        self.assertEqual(len(self.conv_store.list_conversations()), 1)
        response = self.client.get(reverse('survey:new'))
        self.assertEqual(response.status_code, 200)
        # post the form
        response = self.client.post(reverse('survey:new'), {
            'subject': 'the subject',
            'message': 'the message',
            'delivery_class': 'sms',
            'delivery_tag_pool': selected_option,
        })
        self.assertEqual(len(self.conv_store.list_conversations()), 2)
        conversation = max(self.conv_store.list_conversations(),
                           key=lambda c: c.created_at)
        self.assertEqual(conversation.delivery_class, 'sms')
{'fraction_non_alphanumeric': 0.1023976924463674, 'fraction_numerical': 0.005768884081485488, 'mean_word_length': 3.088430361090641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1193922', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1677, 'n_words': 279}