How to use assertFormError method in pytest-django

Best Python code snippet using pytest-django_python

tests.py

Source:tests.py Github

copy

Full Screen

...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...

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 pytest-django 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