def client() -> FlaskClient: app = Flask(__name__) ctx = app.app_context() ctx.push() app.register_blueprint(bp) client = app.test_client() return client
def test_login_as_visit(self): taster = app.test_client(self) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) rv = taster.get('/login', follow_redirects=True) self.assertFalse('משתמשים'.encode() in rv.data) rv = taster.get('/logout', follow_redirects=True)
def test_login_as_admin(self): taster = app.test_client(self) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) rv = taster.get('/login', follow_redirects=True) rv = taster.get('/logout', follow_redirects=True) self.assertFalse('test'.encode() in rv.data)
def test_login_logout(self): taster = app.test_client(self) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) self.assertTrue(rv.status, '200 OK') self.assertFalse('ברוכים'.encode() in rv.data) rv = taster.get('/logout', follow_redirects=True) self.assertFalse('התנתקת בהצלחה'.encode() in rv.data)
def test_falllogin(self): taster = app.test_client(self) print("hhhhhhhhhhhhhhhhhhhh") rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) rv = taster.get('/login', follow_redirects=True) self.assertTrue('משתמשים'.encode() in rv.data) rv = taster.get('/logout', follow_redirects=False)
def client(request): app.config['TESTING'] = True client = app.test_client() def teardown(): app.config['TESTING'] = False request.addfinalizer(teardown) return client
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(app.config['BASEDIR'], TEST_DB) self.app = app.test_client() db.drop_all() db.create_all() # Disable sending emails during unit testing mail.init_app(app) self.assertEqual(app.debug, False)
def test_delete_user(self): taster = app.test_client(self) rv = taster.post('/register', data=dict(email="*****@*****.**", password="******", name="test", last="test"), follow_redirects=True) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) rv = taster.post('/unregister', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) self.assertFalse('שם משתמש או סיסמא לא נכונים'.encode() in rv.data)
def test_comment(self): taster = app.test_client(self) rv = taster.post('/register', data=dict(email="*****@*****.**", password="******", name="test", last="test"), follow_redirects=True) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) rv = taster.post('/comments/פארק%20ליכטנשטיין', data=dict(comment="test"), follow_redirects=True) rv = taster.get('/comments/פארק%20ליכטנשטיין') self.assertFalse('test'.encode() in rv.data) rv = taster.post('/unregister', data=dict(email="*****@*****.**", password="******"), follow_redirects=True)
def test_add_admin(self): taster = app.test_client(self) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) rv = taster.get('/login', follow_redirects=True) rv = taster.post('/registerByAdmin', data=dict(name="טסט", last="טסט", email="*****@*****.**", password="******", Admin="true"), follow_redirects=True) rv = taster.get('/logout', follow_redirects=True) rv = taster.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) self.assertFalse('ברוכים'.encode() in rv.data) rv = taster.post('/unregister', data=dict(email="*****@*****.**", password="******"), follow_redirects=True)
def setUp(self): app.testing = True self.app = app.test_client()
def setUpfall(self): app.testing = False self.app = app.test_client()
def test_home(self): tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200) self.assertEqual(response.data, b'Hello World!')
def test_other(self): tester = app.test_client(self) response = tester.get('a', content_type='html/text') self.assertEqual(response.status_code, 404) self.assertTrue(b'does not exist' in response.data)