How to use test_invalid_form method in Kiwi

Best Python code snippet using Kiwi_python

test_forms.py

Source:test_forms.py Github

copy

Full Screen

...10class TestLoginForm(TestCase):11 def test_valid_form(self):12 form = LoginForm(data={'username':'Test','password':'secretpassword'})13 self.assertTrue(form.is_valid())14 def test_invalid_form(self):15 form = LoginForm(data={})16 self.assertFalse(form.is_valid())17 self.assertEquals(len(form.errors),2)18class TestRegisterForm(TestCase):19 def test_valid_form(self):20 form = RegisterForm(data={'username':'Test','password1':'secretpassword','password1':'secretpassword','password2':'secretpassword'})21 self.assertTrue(form.is_valid())22 def test_invalid_form(self):23 form = RegisterForm(data={'username':'Test','password1':'secretpassword'})24 self.assertFalse(form.is_valid())25 self.assertEquals(len(form.errors),1)26class TestCategoryForm(TestCase):27 def setUp(self):28 self.user = User.objects.create_user(username='PanTest',password='hasło')29 def test_valid_form(self):30 form = CategoryForm(data={'name':'TestCategory'},User=self.user)31 self.assertTrue(form.is_valid())32 def test_invalid_form(self):33 form = CategoryForm(data={},User=self.user)34 self.assertFalse(form.is_valid())35 self.assertEquals(len(form.errors),1)36class TestAccountForm(TestCase):37 def test_valid_form(self):38 form = AccountForm(data={'name':'cash','is_cash':True})39 self.assertTrue(form.is_valid())40 def test_invalid_form(self):41 form = AccountForm(data={})42 self.assertFalse(form.is_valid())43 self.assertEquals(len(form.errors),1)44class TestSavingGoalForm(TestCase):45 def test_valid_form(self):46 form = SavingGoalForm(data={'name':'cash','due_date':datetime.now(),'goal_value':1000,'is_active_saving_goal':True})47 self.assertTrue(form.is_valid())48 def test_invalid_form(self):49 form = SavingGoalForm(data={})50 self.assertFalse(form.is_valid())51 self.assertEquals(len(form.errors),3)52class TestTagForm(TestCase):53 def test_valid_form(self):54 form = TagForm(data={'name':'Tag'})55 self.assertTrue(form.is_valid())56 def test_invalid_form(self):57 form = TagForm(data={})58 self.assertFalse(form.is_valid())59 self.assertEquals(len(form.errors),1)60class TestTransactionForm(TestCase):61 def setUp(self):62 self.user = User.objects.create_user(username='PanTest',password='hasło')63 self.account = Account.objects.create(user=self.user,name='Test',is_cash=True)64 def test_valid_form(self):65 form = TransactionForm(data={'name':'Test','account':self.account,'value':10.24,'date':'2022-02-02'},User=self.user)66 self.assertTrue(form.is_valid())67 def test_invalid_form(self):68 form = TransactionForm(data={},User=self.user)69 self.assertFalse(form.is_valid())70 self.assertEquals(len(form.errors),4)71class TestRecurringForm(TestCase):72 def setUp(self):73 self.user = User.objects.create_user(username='PanTest',password='hasło')74 self.account = Account.objects.create(user=self.user,name='Test',is_cash=True)75 def test_valid_form(self):76 form = RecurringForm(data={'name':'Test','account':self.account,'value':10.24,'date':'2022-02-02','recurring_type':'month'},User=self.user)77 self.assertTrue(form.is_valid())78 def test_invalid_form(self):79 form = RecurringForm(data={},User=self.user)80 self.assertFalse(form.is_valid())81 self.assertEquals(len(form.errors),5)82class TestTransferForm(TestCase):83 def setUp(self):84 self.user = User.objects.create_user(username='PanTest',password='hasło')85 self.account = Account.objects.create(user=self.user,name='Test',is_cash=True)86 self.account_to = Account.objects.create(user=self.user,name='Test2',is_cash=True)87 def test_valid_form(self):88 form = TransferForm(data={'account':self.account,'transfer_account':self.account_to,'value':10.24,'date':'2022-02-02'},User=self.user)89 self.assertTrue(form.is_valid())90 def test_invalid_form(self):91 form = TransferForm(data={},User=self.user)92 self.assertFalse(form.is_valid())93 self.assertEquals(len(form.errors),4)94class TestTransactionItemForm(TestCase):95 def setUp(self):96 self.user = User.objects.create_user(username='PanTest',password='hasło')97 self.account = Account.objects.create(user=self.user,name='Test',is_cash=True)98 self.category = Category.objects.create(user=self.user,name='Test',is_income=True)99 self.transaction = Transaction.objects.create(user=self.user,name='Test',account=self.account,value=10,date='2022-02-01')100 def test_valid_form(self):101 form = TransactionItemForm(data={'item_name':'test','category':self.category,'item_value':10.24,'is_planned':True},User=self.user,type='income')102 self.assertTrue(form.is_valid())103 def test_invalid_form(self):104 form = TransactionItemForm(data={},User=self.user,type='income')105 self.assertFalse(form.is_valid())106 self.assertEquals(len(form.errors),4)107class TestSearchForm(TestCase):108 def setUp(self):109 self.user = User.objects.create_user(username='PanTest',password='hasło')110 def test_valid_form(self):111 form = SearchForm(data={},user=self.user)112 self.assertTrue(form.is_valid())113class TestDateForm(TestCase):114 def setUp(self):115 self.user = User.objects.create_user(username='PanTest',password='hasło')116 def test_valid_form(self):117 form = DateForm(data={'date_from':'2022-02-01','date_to':'2022-02-02'},user=self.user)118 self.assertTrue(form.is_valid())119 def test_invalid_form(self):120 form = DateForm(data={},user=self.user)121 self.assertFalse(form.is_valid())122 self.assertEquals(len(form.errors),2)...

Full Screen

Full Screen

test_contactus.py

Source:test_contactus.py Github

copy

Full Screen

...12 'subject': ['This field is required.'],13 'body': ['This field is required.'],14 }15 assert ContactUs.objects.count() == contactus_initial_count16def test_invalid_form(client):17 contactus_initial_count = ContactUs.objects.count()18 form_data = {19 'email_to': 'test_invalid_form',20 'subject': 'test_subject'*100,21 'body': 'test_invalid_form',22 }23 response = client.post(URL, data=form_data)24 assert response.status_code == 20025 assert response.context_data['form'].errors == {26 'email_to': ['Enter a valid email address.'],27 'subject': ['Ensure this value has at most 255 characters (it has 1200).'], }28 assert ContactUs.objects.count() == contactus_initial_count29def test_valid_form(client):30 contactus_initial_count = ContactUs.objects.count()...

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