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:
|
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')
|
print('No ENV Variable for DATABASE_URL_USERS or DATABASE_URL_LOGS')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
#else:
|
||||||
print('ENV Variables passed : ', app.config['SQLALCHEMY_BINDS'])
|
# print('ENV Variables passed : ', app.config['SQLALCHEMY_BINDS'])
|
||||||
|
|
||||||
print('init_app')
|
print('init_app')
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
print('import routes')
|
#print('import routes')
|
||||||
from . import routes
|
from . import routes
|
||||||
app.register_blueprint(routes.bp)
|
app.register_blueprint(routes.bp)
|
||||||
print('db.create_all')
|
#print('db.create_all')
|
||||||
db.create_all()
|
db.create_all()
|
||||||
print('db created')
|
#print('db created')
|
||||||
return app
|
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.
|
|
@ -49,10 +49,4 @@ def uwp_to_user(uwp):
|
||||||
hash_pass = hash_pass0,
|
hash_pass = hash_pass0,
|
||||||
salt = salt0,
|
salt = salt0,
|
||||||
is_admin = uwp["is_admin"]
|
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
|
from flask_testing import TestCase
|
||||||
import json
|
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 import db, create_app
|
||||||
from application.users_model import Users
|
from application.users_model import Users
|
||||||
from application.logs_model import Logs
|
from application.logs_model import Logs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(TestCase):
|
class BaseTestCase(TestCase):
|
||||||
|
|
||||||
def create_app(self):
|
def create_app(self):
|
||||||
app = create_app('testing')
|
app = create_app('testing')
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
db.create_all()
|
db.create_all()
|
||||||
for user in TAB_USER:
|
for uwp in TAB_USER_WITH_PASSWORD:
|
||||||
db.session.add(user)
|
db.session.add(uwp_to_user(uwp))
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
db.session.remove()
|
db.session.remove()
|
||||||
db.drop_all()
|
db.drop_all()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FlaskTestCase(BaseTestCase):
|
class FlaskTestCase(BaseTestCase):
|
||||||
|
|
||||||
# -- UTILS ---
|
# -- UTILS ---
|
||||||
|
|
@ -39,21 +45,46 @@ class FlaskTestCase(BaseTestCase):
|
||||||
|
|
||||||
# --- LOGIN ---
|
# --- LOGIN ---
|
||||||
|
|
||||||
# def test_login_no_fields(self):
|
def test_login_NoFields_statusCode(self):
|
||||||
# data0 = {}
|
data0 = {}
|
||||||
# response = self.client.post('/api/login', json={})
|
response = self.client.post('/api/login', json=data0)
|
||||||
# print(response.json)
|
self.assertEqual(response.status_code, 400)
|
||||||
# self.assertEqual(response.json['message'], 'Need email, password fields.')
|
|
||||||
|
|
||||||
# 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 = {
|
data0 = {
|
||||||
"email": "nimp@gmail.com",
|
"email": "nimp@gmail.com",
|
||||||
"password": "nimp"
|
"password": "nimp"
|
||||||
|
|
@ -61,7 +92,17 @@ class FlaskTestCase(BaseTestCase):
|
||||||
response = self.client.post('/api/login', json=data0)
|
response = self.client.post('/api/login', json=data0)
|
||||||
self.assertEqual(response.json['message'], 'Email or password invalid')
|
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 = {
|
data0 = {
|
||||||
"email": "riri@gmail.com",
|
"email": "riri@gmail.com",
|
||||||
"password": "ririPass"
|
"password": "ririPass"
|
||||||
|
|
@ -69,38 +110,60 @@ class FlaskTestCase(BaseTestCase):
|
||||||
response = self.client.post('/api/login', json=data0)
|
response = self.client.post('/api/login', json=data0)
|
||||||
self.assertEqual(response.json['message'], 'User authenticated.')
|
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):
|
# --- REGISTER ---
|
||||||
# data0 = json.dumps({
|
|
||||||
|
# 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": "",
|
# "email": "",
|
||||||
# "password": "blabla",
|
# "password": "blabla",
|
||||||
# "nickname": "blabla"
|
# "nickname": "blabla"
|
||||||
# })
|
# }
|
||||||
# response = self.client.post('/api/register', data=data0)
|
# response = self.client.post('/api/register', json=data0)
|
||||||
# self.assertEqual(response.message, 'Empty email and/or password and/or nickname fields.')
|
# 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({
|
# data0 = json.dumps({
|
||||||
# "email": "riri@gmail.com",
|
# "email": "riri@gmail.com",
|
||||||
# "password": "blabla",
|
# "password": "blabla",
|
||||||
# "nickname": "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)
|
# self.assertIn('already exist', response.message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def test_register_success(self):
|
# def test_register_success(self):
|
||||||
# data0 = json.dumps({
|
# data0 = json.dumps({
|
||||||
# "email": "loulou@gmail.com",
|
# "email": "loulou@gmail.com",
|
||||||
# "password": "loulouPass",
|
# "password": "loulouPass",
|
||||||
# "nickname": "Loulou"
|
# "nickname": "Loulou"
|
||||||
# })
|
# })
|
||||||
# response = self.client.post('/api/register', data=data0)
|
# response = self.client.post('/api/register', json=data0)
|
||||||
# self.assertEqual(response.message, 'User registered.')
|
# self.assertEqual(response.message, 'User registered.')
|
||||||
|
|
||||||
# # --- LOGOUT ---
|
# # --- LOGOUT ---
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue