Best Python code snippet using pytest-django_python
tests.py
Source: tests.py
...27 Verifico che nell' inserimento di un articolo i campi obbligatori siano rispettati28 '''29 self.client.login(**self.credential)30 response = self.client.post('/inserisci_articolo/', {})31 self.assertFormError(response, 'form', 'nome', 'Questo campo è obbligatorio.')32 self.assertFormError(response, 'form', 'prezzo', 'Questo campo è obbligatorio.')33 self.assertFormError(response, 'form', 'categoria', 'Questo campo è obbligatorio.')34 self.assertFormError(response, 'form', 'descrizione', 'Questo campo è obbligatorio.')35 self.assertFormError(response, 'form', 'immagine', 'Questo campo è obbligatorio.')36 self.assertFormError(response, 'form', 'condizione', 'Questo campo è obbligatorio.')37 self.assertTemplateUsed(response, 'core/inserisci_articolo.html')38 self.assertEqual(response.status_code, 200) # verifica per capire se il template utilizzato è quello corretto39 response = self.client.post('/inserisci_articolo/',40 {'nome': 'Computer Asus', 'prezzo': '1250', 'categoria': 'I',41 'descrizione': 'funzionante',42 'immagine': 's',43 'condizione': 'U'})44 self.assertTemplateUsed(response, 'core/inserisci_articolo.html')45 self.assertEqual(response.status_code, 200)46 '''47 Test per verificare che l' eliminazione di un articolo vada a buon fine48 '''49 def test_item_delete(self):50 # con utente autenticato51 self.client.login(**self.credential)52 response = self.client.get('/item/' + str(self.item.id) + '/delete/')53 self.assertEqual(response.status_code, 200)54 response = self.client.post('/item/' + str(self.item.id) + '/delete/', {})55 self.assertRedirects(response, '/user/' + self.user.username + '/')56 self.client.logout()57 # con utente autenticato ma non creatore58 self.client.login(**self.credential2)59 response = self.client.get('/item/' + str(self.item.id) + '/delete/')60 self.assertTemplateNotUsed(response, 'core/item_delete.html')61 '''62 Test per verificare se all' inserimento di un articolo, un utente non loggato63 viene reindirizzato prima nella schermata di login.64 '''65 def test_login_required(self):66 response = self.client.get('/inserisci_articolo/')67 self.assertRedirects(response, '/accounts/login/?next=/inserisci_articolo/')68 # 302 --> FOUND: pagina esiste ma non puoi entrarci69 self.assertEqual(response.status_code, 302)70 '''71 Test della visualizzazione del profilo di un utente autenticato72 e per la visualizzazione del profilo di altri utenti.73 '''74 def test_userProfileView(self):75 # con utente autenticato76 # su il tuo profilo77 self.client.login(**self.credential)78 response = self.client.get('/user/' + self.user.username + '/')79 self.assertTemplateUsed(response, 'core/profilo.html')80 self.assertTrue(response.status_code, 200)81 # sul profilo degli altri82 response = self.client.get('/otheruser/' + self.user2.username + '/')83 self.assertTemplateNotUsed(response, 'core/profilo.html')84 self.assertTemplateUsed(response, 'core/user_profile.html')85 # con utente non autenticato86 self.client.logout()87 response = self.client.get('/otheruser/' + self.user.username + '/')88 self.assertTemplateUsed(response, 'core/user_profile.html')89 self.assertTrue(response.status_code, 200)90 '''91 Test per il cambio dell' indirizzo di un utente 92 '''93 def test_address_change(self):94 # con utente autenticato95 self.client.login(**self.credential)96 response = self.client.get('/user/address/' + str(self.address.id) + '/modify/')97 self.assertEqual(response.status_code, 200)98 response = self.client.post('/user/address/' + str(self.address.id) + '/modify/', {})99 self.assertFormError(response, 'form', 'città ', 'Questo campo è obbligatorio.')100 self.assertFormError(response, 'form', 'via', 'Questo campo è obbligatorio.')101 self.assertFormError(response, 'form', 'stato', 'Questo campo è obbligatorio.')102 self.assertFormError(response, 'form', 'cap', 'Questo campo è obbligatorio.')103 response = self.client.post('/user/address/' + str(self.address.id) + '/modify/',104 {'città ': 'chieti', 'via': 'strada', 'stato': 'it', 'cap': '85710'})105 self.assertRedirects(response, '/user/' + self.user.username + '/address_page/')106 self.client.logout()107 # con utente autenticato ma non creatore108 self.client.login(**self.credential2)109 response = self.client.get('/user/address/' + str(self.address.id) + '/modify/')110 self.assertTemplateUsed(response, 'core/homepage.html')111 self.assertTemplateNotUsed(response, 'accounts/address_change.html')112 ''' 113 Test per l' eliminazione di un indirizzo dell' utente114 '''115 def test_address_delete(self):116 # con utente autenticato...
Check out the latest blogs from LambdaTest on this topic:
Hey Folks! Welcome back to the latest edition of LambdaTest’s product updates. Since programmer’s day is just around the corner, our incredible team of developers came up with several new features and enhancements to add some zing to your workflow. We at LambdaTest are continuously upgrading the features on our platform to make lives easy for the QA community. We are releasing new functionality almost every week.
Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
If you are a web tester then somewhere down the road you will have to come across Selenium, an open-source test automation framework that has been on boom ever since its launch in 2004.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
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!!