How to use app_route method in localstack

Best Python code snippet using localstack_python

test_views.py

Source:test_views.py Github

copy

Full Screen

1from django import forms2from django.contrib.auth import get_user_model3from django.test import Client, TestCase4from django.urls import reverse5from posts.models import Group, Post, User6User = get_user_model()7class PostsTests(TestCase):8 @classmethod9 def setUpClass(cls):10 super().setUpClass()11 cls.user = User.objects.create_user(username='LucyTestContext')12 cls.user_second = User.objects.create_user(username='MikeTestContex')13 cls.group = Group.objects.create(14 title='LucyTestGroupContext',15 slug='TestovayaGroupContext',16 description='Эта группа создана для тестирования context'17 )18 cls.group_other = Group.objects.create(19 title='MikeTestGroupContext',20 slug='MikeTestovayaGroupContext',21 description='Эта группа Mike создана для тестирования context'22 )23 cls.post = Post.objects.create(24 text='1 Тестовый текст пост',25 group=cls.group,26 author=cls.user27 )28 cls.index = (29 'posts:index',30 'posts/index.html',31 None)32 cls.group_list = (33 'posts:grouppa',34 'posts/group_list.html',35 [cls.group.slug]36 )37 cls.group_list_other = (38 'posts:grouppa',39 'posts/group_list.html',40 [cls.group_other.slug]41 )42 cls.profile = (43 'posts:profile',44 'posts/profile.html',45 [cls.user.username]46 )47 cls.detail = (48 'posts:post_detail',49 'posts/post_detail.html',50 [cls.post.id]51 )52 cls.edit = (53 'posts:post_edit',54 'posts/create_post.html',55 [cls.post.id]56 )57 cls.create = (58 'posts:post_create',59 'posts/create_post.html',60 None61 )62 cls.page_obj = Post.objects.all()63 cls.ass_urls = (64 cls.index, cls.group_list, cls.profile,65 cls.detail, cls.edit, cls.create66 )67 @classmethod68 def setUp(cls):69 cls.guest_client = Client()70 cls.authorized_client = Client()71 cls.authorized_client.force_login(cls.user)72 cls.authorized_client_second = Client()73 cls.authorized_client_second.force_login(cls.user_second)74 cls.post_author = Client()75 cls.post_author.force_login(cls.user)76 def test_pages_uses_correct_template(self):77 """URL-адрес использует соответствующий шаблон."""78 for route, template, args in self.ass_urls:79 with self.subTest(route=route):80 response = self.post_author.get(81 reverse(route, args=args)82 )83 self.assertTemplateUsed(response, template)84 def test_create_post_page_show_correct_context(self):85 """Шаблон create_post сформирован с правильными типами полей."""86 """Форма создания поста"""87 app_route, template, args_url = self.create88 response = self.authorized_client.get(89 reverse(app_route)90 )91 form_fields = {92 'text': forms.fields.CharField,93 'group': forms.fields.ChoiceField94 }95 for value, expected in form_fields.items():96 with self.subTest(value=value):97 form_field = response.context.get('form').fields.get(98 value99 )100 self.assertIsInstance(form_field, expected)101 def test_edit_post_page_show_correct_context(self):102 """Шаблон edit_post сформирован с правильными типами полей."""103 """Форма редактирования поста"""104 app_route, template, args_url = self.edit105 response = self.post_author.get(106 reverse(app_route, args=args_url)107 )108 form_fields = {109 'text': forms.fields.CharField,110 'group': forms.fields.ChoiceField111 }112 for value, expected in form_fields.items():113 with self.subTest(value=value):114 form_field = response.context.get('form').fields.get(115 value116 )117 self.assertIsInstance(form_field, expected)118 self.assertEqual(119 response.context.get('post_selected').text,120 self.post.text121 )122 self.assertEqual(123 response.context.get('post_selected').group.title,124 self.group.title125 )126 def check_context(self, check_object, proof_object):127 self.assertEqual(check_object.id, proof_object.id,)128 self.assertEqual(check_object.text, proof_object.text,)129 self.assertEqual(check_object.author, proof_object.author)130 self.assertEqual(check_object.group.id, proof_object.group.id)131 self.assertEqual(check_object.group.slug, proof_object.group.slug)132 def check_fields(self, check_object, proof_object):133 self.assertEqual(check_object.title, proof_object.title)134 self.assertEqual(check_object.slug, proof_object.slug)135 self.assertEqual(check_object.description, proof_object.description)136 def index_page_show_correct_context(self):137 """Шаблон index сформирован с правильным контекстом."""138 """Список постов с сортировкой от новых к старым"""139 app_route, template, args_url = self.index140 response = self.authorized_client.get(141 reverse(app_route)142 )143 first_post = len(self.page_obj) - 1144 first_object = response.context['page_obj'][first_post]145 base_object = self.post146 self.check_context(first_object, base_object)147 def test_group_posts_show_correct_context(self):148 """Шаблон group_posts сформирован с правильным контекстом."""149 """Список постов Группы"""150 app_route, template, args_url = self.group_list151 response = self.authorized_client.get(152 reverse(app_route, args=args_url)153 )154 group_fields = response.context.get('group')155 base_group_fields = self.group156 self.check_fields(group_fields, base_group_fields)157 def test_profile_show_correct_context(self):158 """Шаблон group_posts сформирован с правильным контекстом."""159 """Список постов пользователя"""160 app_route, template, args_url = self.profile161 response = self.authorized_client.get(162 reverse(app_route, args=args_url)163 )164 first_post = len(self.page_obj) - 1165 first_object = response.context['page_obj'][first_post]166 base_object = self.post167 self.assertEqual(168 response.context.get('author').username,169 self.post.author.username170 )171 self.assertTrue(172 response.context.get('is_profile')173 )174 self.check_context(first_object, base_object)175 def test_post_exist_index(self):176 """Проверяем что пост появился на странице постов"""177 app_route, template, args_url = self.index178 response = self.authorized_client.get(179 reverse(app_route)180 )181 all_posts = response.context['page_obj']182 first_post = len(all_posts.object_list) - 1183 first_post_post = all_posts.object_list[first_post]184 base_object = self.post185 self.check_context(first_post_post, base_object)186 def test_post_exist_group_page(self):187 """Проверяем, что пост появился на странице группы"""188 app_route, template, args_url = self.group_list189 response = self.authorized_client.get(190 reverse(app_route, args=args_url)191 )192 all_posts = response.context['posts']193 first_post = len(all_posts) - 1194 self.assertEqual(195 all_posts[first_post].text,196 self.page_obj.latest('-pub_date').text197 )198 self.assertEqual(199 all_posts[first_post].group.slug,200 self.page_obj.latest('-pub_date').group.slug201 )202 self.assertEqual(203 all_posts[first_post].author.username,204 self.page_obj.latest('-pub_date').author.username205 )206 def test_post_exist_profile_page(self):207 """Проверяем что пост появился в профайле пользователя"""208 app_route, template, args_url = self.profile209 response = self.authorized_client.get(210 reverse(app_route, args=args_url)211 )212 all_posts = response.context['page_obj']213 self.assertIn(self.post, all_posts)214 self.assertEqual(215 response.context['author'].username,216 self.post.author.username217 )218 def test_post_not_exist_in_different_group_page(self):219 """Проверяем, что пост НЕ появился на странице не своей группы"""220 app_route, template, args_url = self.group_list_other221 response = self.authorized_client.get(222 reverse(app_route, args=args_url)223 )...

Full Screen

Full Screen

tests_forms.py

Source:tests_forms.py Github

copy

Full Screen

1from django.contrib.auth import get_user_model2from django.test import Client, TestCase3from django.urls import reverse4from posts.forms import PostForm5from posts.models import Group, Post, User6User = get_user_model()7class PostCreateFormTests(TestCase):8 @classmethod9 def setUpClass(cls):10 super().setUpClass()11 cls.user = User.objects.create_user(username='LucyTesterForm')12 cls.user_author = User.objects.create_user(username='LucyTestAuthor')13 cls.group = Group.objects.create(14 title='LucyFormTesterGroup_titles',15 slug='LucyFormTesterGroup_slug',16 description='Эта группа создана для тестирования Form'17 )18 cls.post = Post.objects.create(19 text='1 Тестовый текст пост',20 group=cls.group,21 author=cls.user_author22 )23 cls.form = PostForm()24 cls.detail = (25 'posts:post_detail',26 'posts/post_detail.html',27 [cls.post.id]28 )29 cls.edit = (30 'posts:post_edit',31 'posts/create_post.html',32 [cls.post.id]33 )34 cls.create = (35 'posts:post_create',36 'posts/create_post.html',37 None38 )39 cls.ass_urls = (40 cls.detail, cls.edit41 )42 @classmethod43 def setUp(cls):44 cls.authorized_client = Client()45 cls.authorized_client.force_login(cls.user)46 cls.post_author = User.objects.get(username='LucyTestAuthor')47 cls.post_author = Client()48 cls.post_author.force_login(cls.user_author)49 def test_create_post(self):50 """Валидная форма создает запись в Post."""51 tasks_count = Post.objects.count()52 form_data = {53 'text': 'Тестовый текст от LucyTesterForm',54 'group': self.group.id55 }56 response = self.authorized_client.post(57 reverse('posts:post_create'),58 data=form_data,59 follow=True60 )61 self.assertRedirects(62 response,63 reverse(64 'posts:profile',65 kwargs={'username': f'{self.user.username}'}66 )67 )68 self.assertEqual(Post.objects.count(), tasks_count + 1)69 def test_edit_post(self):70 """Проверяем, что происходит изменение поста"""71 app_route, template, args_url = self.edit72 response = self.post_author.get(73 reverse(app_route, args=args_url)74 )75 author_post = response.context['post_selected']76 upd_form_data = {77 'text': 'UPD 1 Тестовый текст пост',78 'group': author_post.group.id,79 'post_author': self.user_author.username80 }81 response = self.post_author.post(82 reverse(app_route, args=args_url),83 data=upd_form_data,84 follow=True85 )86 self.assertRedirects(87 response,88 reverse(89 'posts:post_detail',90 kwargs={'post_id': f'{self.post.id}'}91 )92 )93 def test_fields_created_post(self):94 """Тестируем что поля нового поста сохранились"""95 app_route, template, args_url = self.create96 form_data = {97 'text': 'Самый новый тестовый текст от LucyTesterForm',98 'group': self.group.id99 }100 self.authorized_client.post(101 reverse(app_route),102 data=form_data,103 follow=True104 )105 last_object = Post.objects.first()106 fields_dict = {107 last_object.author.username: self.user.username,108 last_object.text: form_data['text'],109 last_object.group.id: self.group.id110 }111 for field, expected in fields_dict.items():112 with self.subTest(field=field):113 self.assertEqual(field, expected)114 def test_fields_updates_post(self):115 """Тестируем что поля проапдеченного поста сохранились"""116 app_route, template, args_url = self.edit117 response = self.post_author.get(118 reverse(app_route, args=args_url)119 )120 author_post = response.context['post_selected']121 upd_form_data = {122 'text': 'UPD 1 Тестовый текст пост',123 'group': author_post.group.id,124 'post_author': self.user_author.username125 }126 response = self.post_author.post(127 reverse(app_route, args=args_url),128 data=upd_form_data,129 follow=True130 )131 edited_post = Post.objects.last()132 fields_dict = {133 edited_post.author.username: self.user_author.username,134 edited_post.text: upd_form_data['text'],135 edited_post.group.id: self.group.id136 }137 for field, expected in fields_dict.items():138 with self.subTest(field=field):...

Full Screen

Full Screen

app_router.py

Source:app_router.py Github

copy

Full Screen

1from flask import Blueprint, render_template2import db.mysql3app_route = Blueprint('app_route',__name__)4@app_route.route("/")5def index():6 # Flask 렌더러7 db.mysql.Connect()8 return render_template("index.html")9@app_route.route('/healthz')10def healthEcho():11 # K8S Health check 12 return 'Hello flask, i\'m alive!'13@app_route.route('/headers')14def headers():15 # HTTP 상세히 찍어보기 (개발 테스트)...

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