test de la route login
This commit is contained in:
parent
e3d563d58b
commit
81198bb3f8
19 changed files with 99 additions and 42 deletions
BIN
backend/__pycache__/app.cpython-310.pyc
Normal file
BIN
backend/__pycache__/app.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/__pycache__/config.cpython-310.pyc
Normal file
BIN
backend/__pycache__/config.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/__pycache__/fictive_users.cpython-38.pyc
Normal file
BIN
backend/__pycache__/fictive_users.cpython-38.pyc
Normal file
Binary file not shown.
|
|
@ -20,16 +20,16 @@ def create_app(flask_env='development'):
|
|||
if app.config['SQLALCHEMY_DATABASE_URI_1'] is None or app.config['SQLALCHEMY_DATABASE_URI_2'] is None:
|
||||
print('No ENV Variable for DATABASE_URL_USERS or DATABASE_URL_LOGS')
|
||||
sys.exit(1)
|
||||
else:
|
||||
print('ENV Variables passed : ', app.config['SQLALCHEMY_BINDS'])
|
||||
#else:
|
||||
# print('ENV Variables passed : ', app.config['SQLALCHEMY_BINDS'])
|
||||
|
||||
print('init_app')
|
||||
db.init_app(app)
|
||||
with app.app_context():
|
||||
print('import routes')
|
||||
#print('import routes')
|
||||
from . import routes
|
||||
app.register_blueprint(routes.bp)
|
||||
print('db.create_all')
|
||||
#print('db.create_all')
|
||||
db.create_all()
|
||||
print('db created')
|
||||
#print('db created')
|
||||
return app
|
||||
|
|
|
|||
BIN
backend/application/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/api_functions.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/api_functions.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/logs_model.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/logs_model.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/responses.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/responses.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/application/__pycache__/routes.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/routes.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/sessionJWT.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/sessionJWT.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/application/__pycache__/users_model.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/users_model.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -50,9 +50,3 @@ def uwp_to_user(uwp):
|
|||
salt = salt0,
|
||||
is_admin = uwp["is_admin"]
|
||||
)
|
||||
|
||||
|
||||
|
||||
TAB_USER = []
|
||||
for uwp in TAB_USER_WITH_PASSWORD:
|
||||
TAB_USER.append(uwp_to_user(uwp))
|
||||
123
backend/test.py
123
backend/test.py
|
|
@ -2,30 +2,36 @@ import unittest
|
|||
from flask_testing import TestCase
|
||||
import json
|
||||
|
||||
from fictive_users import TAB_USER
|
||||
from fictive_users import TAB_USER_WITH_PASSWORD, uwp_to_user
|
||||
|
||||
from application import db, create_app
|
||||
from application.users_model import Users
|
||||
from application.logs_model import Logs
|
||||
|
||||
|
||||
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
|
||||
def create_app(self):
|
||||
app = create_app('testing')
|
||||
return app
|
||||
|
||||
|
||||
def setUp(self):
|
||||
db.create_all()
|
||||
for user in TAB_USER:
|
||||
db.session.add(user)
|
||||
for uwp in TAB_USER_WITH_PASSWORD:
|
||||
db.session.add(uwp_to_user(uwp))
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
|
||||
|
||||
|
||||
|
||||
class FlaskTestCase(BaseTestCase):
|
||||
|
||||
# -- UTILS ---
|
||||
|
|
@ -39,21 +45,46 @@ class FlaskTestCase(BaseTestCase):
|
|||
|
||||
# --- LOGIN ---
|
||||
|
||||
# def test_login_no_fields(self):
|
||||
# data0 = {}
|
||||
# response = self.client.post('/api/login', json={})
|
||||
# print(response.json)
|
||||
# self.assertEqual(response.json['message'], 'Need email, password fields.')
|
||||
def test_login_NoFields_statusCode(self):
|
||||
data0 = {}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
# def test_login_empty_fields(self):
|
||||
# data0 = {
|
||||
# "email": "",
|
||||
# "password": "blabla"
|
||||
# }
|
||||
# response = self.client.post('/api/login', json=data0)
|
||||
# self.assertEqual(response.json['message'], 'Empty email and/or password fields.')
|
||||
|
||||
def test_login_wrong_fields(self):
|
||||
def test_login_NoFields_message(self):
|
||||
data0 = {}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Need email, password fields.')
|
||||
|
||||
|
||||
def test_login_emptyFields_statusCode(self):
|
||||
data0 = {
|
||||
"email": "",
|
||||
"password": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
|
||||
def test_login_emptyFields_message(self):
|
||||
data0 = {
|
||||
"email": "",
|
||||
"password": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Empty email and/or password fields.')
|
||||
|
||||
|
||||
def test_login_wrongFields_statusCode(self):
|
||||
data0 = {
|
||||
"email": "nimp@gmail.com",
|
||||
"password": "nimp"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
def test_login_wrongFields_message(self):
|
||||
data0 = {
|
||||
"email": "nimp@gmail.com",
|
||||
"password": "nimp"
|
||||
|
|
@ -61,7 +92,17 @@ class FlaskTestCase(BaseTestCase):
|
|||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Email or password invalid')
|
||||
|
||||
def test_login_success(self):
|
||||
|
||||
def test_login_success_statusCode(self):
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"password": "ririPass"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
def test_login_success_message(self):
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"password": "ririPass"
|
||||
|
|
@ -69,38 +110,60 @@ class FlaskTestCase(BaseTestCase):
|
|||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.json['message'], 'User authenticated.')
|
||||
|
||||
# # --- REGISTER ---
|
||||
|
||||
# def test_register_no_fields(self):
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# self.assertIn('Need', response.message)
|
||||
|
||||
# def test_register_empty_fields(self):
|
||||
# data0 = json.dumps({
|
||||
# --- REGISTER ---
|
||||
|
||||
# def test_register_noFields_statusCode(self):
|
||||
# data0 = {}
|
||||
# response = self.client.post('/api/register', json=data0)
|
||||
# self.assertEqual(response.status_code, 400)
|
||||
|
||||
|
||||
# def test_register_noFields_message(self):
|
||||
# data0 = {}
|
||||
# response = self.client.post('/api/register', json=data0)
|
||||
# self.assertIn('Need', response.json['message'])
|
||||
|
||||
|
||||
# def test_register_emptyFields_statusCode(self):
|
||||
# data0 = {
|
||||
# "email": "",
|
||||
# "password": "blabla",
|
||||
# "nickname": "blabla"
|
||||
# })
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# self.assertEqual(response.message, 'Empty email and/or password and/or nickname fields.')
|
||||
# }
|
||||
# response = self.client.post('/api/register', json=data0)
|
||||
# self.assertEqual(response.status_code, 400)
|
||||
|
||||
# def test_register_already_exist(self):
|
||||
|
||||
# def test_register_emptyFields_message(self):
|
||||
# data0 = {
|
||||
# "email": "",
|
||||
# "password": "blabla",
|
||||
# "nickname": "blabla"
|
||||
# }
|
||||
# response = self.client.post('/api/register', json=data0)
|
||||
# self.assertIn('Need', response.json['message'])
|
||||
|
||||
|
||||
# def test_register_alreadyExist_statusCode(self):
|
||||
# data0 = json.dumps({
|
||||
# "email": "riri@gmail.com",
|
||||
# "password": "blabla",
|
||||
# "nickname": "blabla"
|
||||
# })
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# response = self.client.post('/api/register', json=data0)
|
||||
# self.assertIn('already exist', response.message)
|
||||
|
||||
|
||||
|
||||
# def test_register_success(self):
|
||||
# data0 = json.dumps({
|
||||
# "email": "loulou@gmail.com",
|
||||
# "password": "loulouPass",
|
||||
# "nickname": "Loulou"
|
||||
# })
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# response = self.client.post('/api/register', json=data0)
|
||||
# self.assertEqual(response.message, 'User registered.')
|
||||
|
||||
# # --- LOGOUT ---
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue