How to use test_CSRF method in localstack

Best Python code snippet using localstack_python

test_form.py

Source:test_form.py Github

copy

Full Screen

1from django.test import TestCase, Client2from django.urls import reverse, resolve3from post.forms import CommentForm, ContactForm, ShareForm4from model_mommy import mommy5from post import views6class TestCommentForm(TestCase):7 def setUp(self):8 self.client = Client()9 self.model = mommy.make("Post")10 self.url = reverse("post:detail", kwargs={"slug": self.model.slug})11 self.response = self.client.get(self.url)12 def test_signup_page_status_code(self):13 self.assertEqual(self.response.status_code, 200)14 def test_csrf(self):15 self.assertContains(self.response, 'csrfmiddlewaretoken')16 def test_post_detail_template_use(self):17 self.assertTemplateUsed(self.response, 'post/post_detail.html')18 def test_comment_post_view(self):19 view = resolve(self.url)20 self.assertEqual(view.func.view_class, views.PostDetailView)21 def test_form_inputs_count(self):22 self.assertContains(self.response, '<input', 4)23 def test_name_input(self):24 self.assertContains(self.response, 'type="text"', 1)25 def test_form_csrf(self):26 self.assertContains(self.response, 'type="hidden"', 1)27 def test_email_input(self):28 self.assertContains(self.response, 'type="email"', 1)29 def test_submit_button(self):30 self.assertContains(self.response, 'type="submit"', 2)31class TestContactForm(TestCase):32 def setUp(self):33 self.client = Client()34 self.model = mommy.make("Post")35 self.url = reverse("post:contact")36 self.response = self.client.get(self.url)37 def test_contact_page_status_code(self):38 self.assertEqual(self.response.status_code, 200)39 def test_csrf(self):40 self.assertContains(self.response, 'csrfmiddlewaretoken')41 def test_template_use(self):42 self.assertTemplateUsed(self.response, 'post/contact.html')43 def test_form_inputs_count(self):44 self.assertContains(self.response, '<input', 4)45 def test_name_input(self):46 self.assertContains(self.response, 'type="text"', 1)47 def test_form_csrf(self):48 self.assertContains(self.response, 'type="hidden"', 1)49 def test_email_input(self):50 self.assertContains(self.response, 'type="email"', 1)51 def test_submit_button(self):52 self.assertContains(self.response, 'type="submit"', 1)53class TestShareForm(TestCase):54 55 def setUp(self):56 self.client = Client()57 self.model = mommy.make("Post")58 self.url = reverse("post:share",kwargs={"pk":self.model.pk})59 self.response = self.client.get(self.url)60 def test_csrf(self):61 self.assertContains(self.response, 'csrfmiddlewaretoken')62 def test_form_inputs_count(self):63 self.assertContains(self.response, '<input', 6)64 def test_name_input(self):65 self.assertContains(self.response, 'type="text"', 2)66 def test_form_csrf(self):67 self.assertContains(self.response, 'type="hidden"', 1)68 def test_email_input(self):69 self.assertContains(self.response, 'type="email"', 2)70 def test_submit_button(self):...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1"""mysite7 URL Configuration2The `urlpatterns` list routes URLs to views. For more information please see:3 https://docs.djangoproject.com/en/2.2/topics/http/urls/4Examples:5Function views6 1. Add an import: from my_app import views7 2. Add a URL to urlpatterns: path('', views.home, name='home')8Class-based views9 1. Add an import: from other_app.views import Home10 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')11Including another URLconf12 1. Import the include() function: from django.urls import include, path13 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))14"""15from django.contrib import admin16from django.urls import path17from mysite7 import views18urlpatterns = [19 path('admin/', admin.site.urls),20 path('test_cache', views.test_cache),21 path('test_mw', views.test_mw),22 path('test_csrf', views.test_csrf),23 path('test_page', views.test_page, name='book'),...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1import time2from django.core.paginator import Paginator3from django.http import HttpResponse4from django.shortcuts import render5from django.views.decorators.cache import cache_page6@cache_page(15)7def test_cache(request):8 t1 = time.time()9 # time.sleep(3)10 print('--test_cache view--')11 return HttpResponse('t1 is %s' % t1)12def test_mw(request):13 print('--mw view in--')14 return HttpResponse('my mw view')15def test_csrf(request):16 if request.method == 'GET':17 return render(request, 'test_csrf.html')18 elif request.method == 'POST':19 return HttpResponse('post is success!')20def test_page(request):21 list01 = ['a', 'b', 'c', 'd', 'e']22 # 创建分页器23 paginator = Paginator(list01, 2)24 cur_page = request.GET.get('page', 1) # 得到默认的当前页25 page = paginator.page(cur_page)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful