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

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

from django_twilio.tests.views import response_view, str_view, verb_view


class TwilioViewTestCase(TestCase):
	"""Run tests against the ``twilio_view`` decorator."""
	fixtures = ['django_twilio.json']
	urls = 'django_twilio.tests.urls'

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

		# 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 two test views.
		self.response_signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/response_view/', sha1).digest()).strip()
		self.str_signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/str_view/', sha1).digest()).strip()
		self.str_signature_with_from_field_normal_caller = encodestring(new(
				settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/str_view/From+12222222222',
				sha1).digest()).strip()
		self.str_signature_with_from_field_blacklisted_caller = encodestring(
				new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/str_view/From+13333333333',
				sha1).digest()).strip()
		self.verb_signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/verb_view/', sha1).digest()).strip()

	def test_is_csrf_exempt(self):
		self.assertTrue(self.client.post('/test/str_view/').csrf_exempt)<commit_msg>Adding a test URI variable for simplifying logic.<commit_after>from hmac import new
from hashlib import sha1
from base64 import encodestring

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

from django_twilio.tests.views import response_view, str_view, verb_view


class TwilioViewTestCase(TestCase):
	"""Run tests against the ``twilio_view`` decorator."""
	fixtures = ['django_twilio.json']
	urls = 'django_twilio.tests.urls'

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

		# Test URI.
		self.uri = 'http://testserver'

		# 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 two test views.
		self.response_signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/response_view/', sha1).digest()).strip()
		self.str_signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/str_view/', sha1).digest()).strip()
		self.str_signature_with_from_field_normal_caller = encodestring(new(
				settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/str_view/From+12222222222',
				sha1).digest()).strip()
		self.str_signature_with_from_field_blacklisted_caller = encodestring(
				new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/str_view/From+13333333333',
				sha1).digest()).strip()
		self.verb_signature = encodestring(new(settings.TWILIO_AUTH_TOKEN,
				'http://testserver/test/verb_view/', sha1).digest()).strip()

	def test_is_csrf_exempt(self):
		self.assertTrue(self.client.post('/test/str_view/').csrf_exempt)
{'fraction_non_alphanumeric': 0.11542857142857142, 'fraction_numerical': 0.017142857142857144, 'mean_word_length': 5.556179775280899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '656900', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1171, 'n_words': 208}