Added HostingUserLoginForm test, Added HostingUserSignupForm test, Added PasswordResetRequestForm Test, Added SetPasswordForm test, Created custom 404 page
This commit is contained in:
		
					parent
					
						
							
								e22e25cea0
							
						
					
				
			
			
				commit
				
					
						202562011e
					
				
			
		
					 9 changed files with 224 additions and 7 deletions
				
			
		
							
								
								
									
										116
									
								
								hosting/test_forms.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								hosting/test_forms.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,116 @@ | |||
| from django.test import TestCase | ||||
| 
 | ||||
| from unittest import mock | ||||
| from model_mommy import mommy | ||||
| 
 | ||||
| from .forms import HostingOrderAdminForm, HostingUserLoginForm, HostingUserSignupForm | ||||
| from .models import VirtualMachinePlan | ||||
| 
 | ||||
| 
 | ||||
| class HostingUserLoginFormTest(TestCase): | ||||
| 
 | ||||
|     def setUp(self): | ||||
|         password = 'user_password' | ||||
|         self.user = mommy.make('CustomUser') | ||||
| 
 | ||||
|         self.user.set_password(password) | ||||
|         self.user.save() | ||||
|         self.completed_data = { | ||||
|             'email': self.user.email, | ||||
|             'password': password | ||||
|         } | ||||
| 
 | ||||
|         self.incorrect_data = { | ||||
|             'email': 'test', | ||||
|         } | ||||
| 
 | ||||
|     def test_valid_form(self): | ||||
|         form = HostingUserLoginForm(data=self.completed_data) | ||||
|         self.assertTrue(form.is_valid()) | ||||
| 
 | ||||
|     def test_invalid_form(self): | ||||
|         form = HostingUserLoginForm(data=self.incorrect_data) | ||||
|         self.assertFalse(form.is_valid()) | ||||
| 
 | ||||
| 
 | ||||
| class HostingUserSignupFormTest(TestCase): | ||||
| 
 | ||||
|     def setUp(self): | ||||
| 
 | ||||
|         self.completed_data = { | ||||
|             'name': 'test name', | ||||
|             'email': 'test@ungleich.com', | ||||
|             'password': 'test_password', | ||||
|             'confirm_password': 'test_password' | ||||
|         } | ||||
| 
 | ||||
|         self.incorrect_data = { | ||||
|             'email': 'test', | ||||
|         } | ||||
| 
 | ||||
|     def test_valid_form(self): | ||||
|         form = HostingUserSignupForm(data=self.completed_data) | ||||
|         self.assertTrue(form.is_valid()) | ||||
| 
 | ||||
|     def test_invalid_form(self): | ||||
|         form = HostingUserSignupForm(data=self.incorrect_data) | ||||
|         self.assertFalse(form.is_valid()) | ||||
| 
 | ||||
| 
 | ||||
| class HostingOrderAdminFormTest(TestCase): | ||||
| 
 | ||||
|     def setUp(self): | ||||
| 
 | ||||
|         self.customer = mommy.make('StripeCustomer') | ||||
|         self.vm_plan = mommy.make('VirtualMachinePlan') | ||||
|         self.vm_canceled_plan = mommy.make('VirtualMachinePlan', | ||||
|                                            status=VirtualMachinePlan.CANCELED_STATUS) | ||||
| 
 | ||||
|         self.mocked_charge = { | ||||
|             'amount': 5100, | ||||
|             'amount_refunded': 0, | ||||
|             'balance_transaction': 'txn_18U99zGjsLAXdRPzUJKkBx3Q', | ||||
|             'captured': True, | ||||
|             'created': 1467785123, | ||||
|             'currency': 'chf', | ||||
|             'customer': 'cus_8V61MvJvMd0PhM', | ||||
|             'status': 'succeeded' | ||||
|         } | ||||
| 
 | ||||
|         self.completed_data = { | ||||
|             'customer': self.customer.id, | ||||
|             'vm_plan': self.vm_plan.id, | ||||
|         } | ||||
| 
 | ||||
|         self.incompleted_data = { | ||||
|             'vm_plan': self.vm_plan.id, | ||||
|             'customer': None | ||||
|         } | ||||
| 
 | ||||
|     @mock.patch('utils.stripe_utils.StripeUtils.make_charge') | ||||
|     def test_valid_form(self, stripe_mocked_call): | ||||
|         stripe_mocked_call.return_value = { | ||||
|             'paid': True, | ||||
|             'response_object': self.mocked_charge, | ||||
|             'error': None | ||||
|         } | ||||
|         form = HostingOrderAdminForm(data=self.completed_data) | ||||
|         self.assertTrue(form.is_valid()) | ||||
| 
 | ||||
|     @mock.patch('utils.stripe_utils.StripeUtils.make_charge') | ||||
|     def test_invalid_form_canceled_vm(self, stripe_mocked_call): | ||||
| 
 | ||||
|         self.completed_data.update({ | ||||
|             'vm_plan': self.vm_canceled_plan.id | ||||
|         }) | ||||
|         stripe_mocked_call.return_value = { | ||||
|             'paid': True, | ||||
|             'response_object': self.mocked_charge, | ||||
|             'error': None | ||||
|         } | ||||
|         form = HostingOrderAdminForm(data=self.completed_data) | ||||
|         self.assertFalse(form.is_valid()) | ||||
| 
 | ||||
|     def test_invalid_form(self): | ||||
|         form = HostingOrderAdminForm(data=self.incompleted_data) | ||||
|         self.assertFalse(form.is_valid()) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue