mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 12:22:47 +00:00 
			
		
		
		
	Add testing for register
This commit is contained in:
		
							
								
								
									
										46
									
								
								tests/test_client.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								tests/test_client.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					import re
 | 
				
			||||||
 | 
					import unittest
 | 
				
			||||||
 | 
					from app import create_app, db
 | 
				
			||||||
 | 
					from app.models import User, Role
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class FlaskClientTestCase(unittest.TestCase):
 | 
				
			||||||
 | 
					    def setUp(self):
 | 
				
			||||||
 | 
					        self.app = create_app('testing')
 | 
				
			||||||
 | 
					        self.app_context = self.app.app_context()
 | 
				
			||||||
 | 
					        self.app_context.push()
 | 
				
			||||||
 | 
					        db.create_all()
 | 
				
			||||||
 | 
					        # Role.insert_roles()
 | 
				
			||||||
 | 
					        self.client = self.app.test_client(use_cookies=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def tearDown(self):
 | 
				
			||||||
 | 
					        db.session.remove()
 | 
				
			||||||
 | 
					        db.drop_all()
 | 
				
			||||||
 | 
					        self.app_context.pop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_home_page(self):
 | 
				
			||||||
 | 
					        response = self.client.get('/')
 | 
				
			||||||
 | 
					        self.assertEqual(response.status_code, 200)
 | 
				
			||||||
 | 
					        self.assertTrue('Stranger' in response.get_data(as_text=True))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_register_and_login(self):
 | 
				
			||||||
 | 
					        # register a new account
 | 
				
			||||||
 | 
					        response = self.client.post('/auth/register', data={
 | 
				
			||||||
 | 
					            'email': 'john@example.com',
 | 
				
			||||||
 | 
					            'username': 'john',
 | 
				
			||||||
 | 
					            'password': 'cat',
 | 
				
			||||||
 | 
					            'password2': 'cat'
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        self.assertEqual(response.status_code, 302)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # login with the new account
 | 
				
			||||||
 | 
					        response = self.client.post('/auth/login', data={
 | 
				
			||||||
 | 
					            'email': 'john@example.com',
 | 
				
			||||||
 | 
					            'password': 'cat'
 | 
				
			||||||
 | 
					        }, follow_redirects=True)
 | 
				
			||||||
 | 
					        self.assertEqual(response.status_code, 200)
 | 
				
			||||||
 | 
					        self.assertTrue(re.search(r'Hello,\sjohn!',
 | 
				
			||||||
 | 
					                                  response.get_data(as_text=True)))
 | 
				
			||||||
 | 
					        self.assertTrue(
 | 
				
			||||||
 | 
					            'You have not confirmed your account yet' in response.get_data(
 | 
				
			||||||
 | 
					                as_text=True))
 | 
				
			||||||
		Reference in New Issue
	
	Block a user