<commit_before>from hmac import new
from hashlib import sha1
from base64 import encodestring

from django.conf import settings
from django.test import Client, RequestFactory, TestCase

from django_twilio.views import conference, play, say


class ConferenceTestCase(TestCase):
    """Run tests against the ``conference`` view."""

    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()

        # Test URIs.
        self.uri = 'http://testserver/tests/views'
        self.conf_uri = '/tests/views/conference/'

        # Guarantee a value for the required configuration settings after each
        # test case.
        settings.TWILIO_ACCOUNT_SID = 'xxx'
        settings.TWILIO_AUTH_TOKEN = 'xxx'

        # Pre-calculate twilio signatures for our test views.
        self.signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
                '%s/conference/' % self.uri, sha1).digest()).strip()

    def test_conference_no_name(self):
        request = self.factory.post(self.conf_uri, HTTP_X_TWILIO_SIGNATURE=self.signature)
        self.assertRaises(TypeError, conference, request)

    def test_conference_with_name(self):
        request = self.factory.post(self.conf_uri, HTTP_X_TWILIO_SIGNATURE=self.signature)
        self.assertEquals(conference(request, name='a').status_code, 200)


class SayTestCase(TestCase):

    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()

        # Test URIs.
        self.uri = 'http://testserver/tests/views'
        self.say_uri = '/tests/views/say/'

        # Guarantee a value for the required configuration settings after each
        # test case.
        settings.TWILIO_ACCOUNT_SID = 'xxx'
        settings.TWILIO_AUTH_TOKEN = 'xxx'

        # Pre-calculate twilio signatures for our test views.
        self.signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
                '%s/say/' % self.uri, sha1).digest()).strip()<commit_msg>Adding unit tests for ``django_twilio.views.gather``.<commit_after>from hmac import new
from hashlib import sha1
from base64 import encodestring

from django.conf import settings
from django.test import Client, RequestFactory, TestCase

from django_twilio.views import conference, gather, play, say


class ConferenceTestCase(TestCase):
    """Run tests against the ``conference`` view."""

    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()

        # Test URIs.
        self.uri = 'http://testserver/tests/views'
        self.conf_uri = '/tests/views/conference/'

        # Guarantee a value for the required configuration settings after each
        # test case.
        settings.TWILIO_ACCOUNT_SID = 'xxx'
        settings.TWILIO_AUTH_TOKEN = 'xxx'

        # Pre-calculate twilio signatures for our test views.
        self.signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
                '%s/conference/' % self.uri, sha1).digest()).strip()

    def test_conference_no_name(self):
        request = self.factory.post(self.conf_uri, HTTP_X_TWILIO_SIGNATURE=self.signature)
        self.assertRaises(TypeError, conference, request)

    def test_conference_with_name(self):
        request = self.factory.post(self.conf_uri, HTTP_X_TWILIO_SIGNATURE=self.signature)
        self.assertEquals(conference(request, name='a').status_code, 200)


class GatherTestCase(TestCase):

    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()

        # Test URIs.
        self.uri = 'http://testserver/tests/views'
        self.gather_uri = '/tests/views/gather/'

        # Guarantee a value for the required configuration settings after each
        # test case.
        settings.TWILIO_ACCOUNT_SID = 'xxx'
        settings.TWILIO_AUTH_TOKEN = 'xxx'

        # Pre-calculate twilio signatures for our test views.
        self.signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
                '%s/gather/' % self.uri, sha1).digest()).strip()

    def test_gather(self):
        request = self.factory.post(self.gather_uri, HTTP_X_TWILIO_SIGNATURE=self.signature)
	self.assertEquals(gather(request).status_code, 200)


class SayTestCase(TestCase):

    def setUp(self):
        self.client = Client()
        self.factory = RequestFactory()

        # Test URIs.
        self.uri = 'http://testserver/tests/views'
        self.say_uri = '/tests/views/say/'

        # Guarantee a value for the required configuration settings after each
        # test case.
        settings.TWILIO_ACCOUNT_SID = 'xxx'
        settings.TWILIO_AUTH_TOKEN = '<PASSWORD>'

        # Pre-calculate twilio signatures for our test views.
        self.signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
                '%s/say/' % self.uri, sha1).digest()).strip()
{'fraction_non_alphanumeric': 0.10337640683618174, 'fraction_numerical': 0.004168403501458941, 'mean_word_length': 2.901626016260163, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '106119', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1407, 'n_words': 321}