diff --git a/backend/__pycache__/app.cpython-310.pyc b/backend/__pycache__/app.cpython-310.pyc new file mode 100644 index 0000000..56671cd Binary files /dev/null and b/backend/__pycache__/app.cpython-310.pyc differ diff --git a/backend/__pycache__/config.cpython-310.pyc b/backend/__pycache__/config.cpython-310.pyc new file mode 100644 index 0000000..6ca6f0b Binary files /dev/null and b/backend/__pycache__/config.cpython-310.pyc differ diff --git a/backend/__pycache__/config.cpython-38.pyc b/backend/__pycache__/config.cpython-38.pyc index ad47e0f..6e1dae2 100644 Binary files a/backend/__pycache__/config.cpython-38.pyc and b/backend/__pycache__/config.cpython-38.pyc differ diff --git a/backend/__pycache__/fictive_users.cpython-38.pyc b/backend/__pycache__/fictive_users.cpython-38.pyc new file mode 100644 index 0000000..477bdc3 Binary files /dev/null and b/backend/__pycache__/fictive_users.cpython-38.pyc differ diff --git a/backend/application/__init__.py b/backend/application/__init__.py index c726987..e26ae65 100644 --- a/backend/application/__init__.py +++ b/backend/application/__init__.py @@ -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 diff --git a/backend/application/__pycache__/__init__.cpython-310.pyc b/backend/application/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..4f97792 Binary files /dev/null and b/backend/application/__pycache__/__init__.cpython-310.pyc differ diff --git a/backend/application/__pycache__/__init__.cpython-38.pyc b/backend/application/__pycache__/__init__.cpython-38.pyc index 073b912..b057e9d 100644 Binary files a/backend/application/__pycache__/__init__.cpython-38.pyc and b/backend/application/__pycache__/__init__.cpython-38.pyc differ diff --git a/backend/application/__pycache__/api_functions.cpython-310.pyc b/backend/application/__pycache__/api_functions.cpython-310.pyc new file mode 100644 index 0000000..037557d Binary files /dev/null and b/backend/application/__pycache__/api_functions.cpython-310.pyc differ diff --git a/backend/application/__pycache__/api_functions.cpython-38.pyc b/backend/application/__pycache__/api_functions.cpython-38.pyc index adf8d1d..9f49edf 100644 Binary files a/backend/application/__pycache__/api_functions.cpython-38.pyc and b/backend/application/__pycache__/api_functions.cpython-38.pyc differ diff --git a/backend/application/__pycache__/logs_model.cpython-310.pyc b/backend/application/__pycache__/logs_model.cpython-310.pyc new file mode 100644 index 0000000..c317af2 Binary files /dev/null and b/backend/application/__pycache__/logs_model.cpython-310.pyc differ diff --git a/backend/application/__pycache__/logs_model.cpython-38.pyc b/backend/application/__pycache__/logs_model.cpython-38.pyc index 73e48a0..f7aa63a 100644 Binary files a/backend/application/__pycache__/logs_model.cpython-38.pyc and b/backend/application/__pycache__/logs_model.cpython-38.pyc differ diff --git a/backend/application/__pycache__/responses.cpython-310.pyc b/backend/application/__pycache__/responses.cpython-310.pyc new file mode 100644 index 0000000..05d2496 Binary files /dev/null and b/backend/application/__pycache__/responses.cpython-310.pyc differ diff --git a/backend/application/__pycache__/routes.cpython-310.pyc b/backend/application/__pycache__/routes.cpython-310.pyc new file mode 100644 index 0000000..d5552d7 Binary files /dev/null and b/backend/application/__pycache__/routes.cpython-310.pyc differ diff --git a/backend/application/__pycache__/routes.cpython-38.pyc b/backend/application/__pycache__/routes.cpython-38.pyc index fae7dfb..7a95df1 100644 Binary files a/backend/application/__pycache__/routes.cpython-38.pyc and b/backend/application/__pycache__/routes.cpython-38.pyc differ diff --git a/backend/application/__pycache__/sessionJWT.cpython-310.pyc b/backend/application/__pycache__/sessionJWT.cpython-310.pyc new file mode 100644 index 0000000..2b9734d Binary files /dev/null and b/backend/application/__pycache__/sessionJWT.cpython-310.pyc differ diff --git a/backend/application/__pycache__/users_model.cpython-310.pyc b/backend/application/__pycache__/users_model.cpython-310.pyc new file mode 100644 index 0000000..e386a6a Binary files /dev/null and b/backend/application/__pycache__/users_model.cpython-310.pyc differ diff --git a/backend/application/__pycache__/users_model.cpython-38.pyc b/backend/application/__pycache__/users_model.cpython-38.pyc index 989f25a..43995d7 100644 Binary files a/backend/application/__pycache__/users_model.cpython-38.pyc and b/backend/application/__pycache__/users_model.cpython-38.pyc differ diff --git a/backend/fictive_users.py b/backend/fictive_users.py index 6f6399c..6d587a7 100644 --- a/backend/fictive_users.py +++ b/backend/fictive_users.py @@ -49,10 +49,4 @@ def uwp_to_user(uwp): hash_pass = hash_pass0, salt = salt0, is_admin = uwp["is_admin"] - ) - - - -TAB_USER = [] -for uwp in TAB_USER_WITH_PASSWORD: - TAB_USER.append(uwp_to_user(uwp)) \ No newline at end of file + ) \ No newline at end of file diff --git a/backend/test.py b/backend/test.py index 604f997..b71faa3 100644 --- a/backend/test.py +++ b/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 ---