Best Python code snippet using django-test-plus_python
test_views.py
Source:test_views.py
...72 setattr(request, 'session', 'session')73 messages = FallbackStorage(request)74 setattr(request, '_messages', messages)75 response = self.post(views.QuestionCreateView, request=request)76 self.assert_http_302_found(response)77 self.assertEqual(response.url, '/qa/')78class TestQuestionDetailView(BaseQATest):79 """æµè¯é®é¢è¯¦æ
"""80 def test_context_data(self):81 response = self.get(views.QuestionDetailView, request=self.request,82 pk=self.question_one.pk)83 self.assert_http_200_ok(response)84 self.assertEqual(response.context_data['question'], self.question_one)85class TestAnswerCreateView(BaseQATest):86 """æµè¯å建åç"""87 def test_get(self):88 """GET请æ±"""89 response = self.get(views.AnswerCreateView, request=self.request,90 question_id=self.question_one.pk)91 self.assert_http_200_ok(response)92 self.assertContains(response, 'ç¼è¾')93 self.assertContains(response, 'é¢è§')94 self.assertIsInstance(response.context_data['view'], views.AnswerCreateView)95 def test_post(self):96 """POST请æ±"""97 request = RequestFactory().post('/fake-url/', data={'content': 'content'})98 request.user = self.user99 setattr(request, 'session', 'session')100 messages = FallbackStorage(request)101 setattr(request, '_messages', messages)102 response = self.post(views.AnswerCreateView, request=request, question_id=self.question_one.id)103 self.assert_http_302_found(response)104 self.assertEqual(response.url, '/qa/question-detail/{}/'.format(self.question_one.id))105class TestQAVote(BaseQATest):106 """æµè¯æ票åè½ï¼é®é¢ååçï¼"""107 def setUp(self):108 super().setUp()109 self.request = RequestFactory().post('/fake-url/',110 HTTP_X_REQUESTED_WITH='XMLHttpRequest')111 self.request.POST = self.request.POST.copy()112 self.request.user = self.other_user113 def test_question_upvote(self):114 """èµåé®é¢"""115 self.request.POST['question'] = self.question_one.id116 self.request.POST['value'] = 'U'117 response = views.question_vote(self.request)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!