-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/daily-trip
- Loading branch information
Showing
30 changed files
with
2,150 additions
and
1,798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3.9 | ||
FROM python:3.10 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,78 @@ | ||
[project] | ||
name = "uniride-sme" | ||
version = "2.0.1" | ||
description = "Backend of UniRide" | ||
authors = [ | ||
{name = "Gregoire FAURE"}, | ||
{name = "Yassine HAMIDI"}, | ||
{name = "Steven YANG"}, | ||
{name = "Rayan CHOUCHANE"}, | ||
{name = "Ayoub BOUAZIZ"}] | ||
|
||
readme = "README.md" | ||
|
||
requires-python = ">3.7" | ||
|
||
dependencies = [ | ||
"flask", | ||
"flask_restful", | ||
"flask_cors", | ||
"flask_mail", | ||
"flask_jwt_extended", | ||
"flask_rq2", | ||
"flask_caching", | ||
"python-dotenv", | ||
"psycopg2", | ||
"bcrypt", | ||
"googlemaps", | ||
"requests", | ||
"setuptools",] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"pytest==7.4.3", | ||
"bandit[toml]==1.7.4", | ||
"black==22.10.0", | ||
"coverage[toml]==7.2.6", | ||
"pycodestyle==2.10.0", | ||
"pylint>=2.15.16",] | ||
|
||
[tool.black] | ||
line-length = 120 | ||
target-version = ['py37'] | ||
include = '\.pyi?$' | ||
exclude = '' | ||
|
||
[build-system] | ||
requires = ["setuptools", "setuptools-scm"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools] | ||
packages = ["uniride_sme"] | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = "test/" | ||
addopts = "-vv" | ||
|
||
[pycodestyle] | ||
count = true | ||
max-line-length = 120 | ||
statistics = true | ||
|
||
[tool.pylint.format] | ||
max-line-length=120 | ||
|
||
[tool.pylint.main] | ||
ignore-paths = [] | ||
|
||
[tool.pylint.reports] | ||
msg-template="{path}:{line}: [{msg_id}, {obj}] {msg} ({symbol})" | ||
output-format="parseable" | ||
|
||
[tool.pylint.'messages control'] | ||
max-line-length = 120 | ||
disable=[] | ||
|
||
[tool.bandit] | ||
targets = ["app"] | ||
[project] | ||
name = "uniride-sme" | ||
version = "2.0.1" | ||
description = "Backend of UniRide" | ||
authors = [ | ||
{name = "Gregoire FAURE"}, | ||
{name = "Yassine HAMIDI"}, | ||
{name = "Steven YANG"}, | ||
{name = "Rayan CHOUCHANE"}, | ||
{name = "Ayoub BOUAZIZ"}] | ||
|
||
readme = "README.md" | ||
|
||
requires-python = ">3.10" | ||
|
||
dependencies = [ | ||
"flask", | ||
"flask_restful", | ||
"flask_cors", | ||
"flask_mail", | ||
"flask_jwt_extended", | ||
"flask_rq2", | ||
"flask_caching", | ||
"python-dotenv", | ||
"psycopg2", | ||
"bcrypt", | ||
"googlemaps", | ||
"requests", | ||
"setuptools",] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"pytest==7.4.3", | ||
"bandit[toml]==1.7.4", | ||
"black==22.10.0", | ||
"coverage[toml]==7.2.6", | ||
"pycodestyle==2.10.0", | ||
"pylint>=2.15.16",] | ||
|
||
[tool.black] | ||
line-length = 120 | ||
target-version = ['py37'] | ||
include = '\.pyi?$' | ||
exclude = '' | ||
|
||
[build-system] | ||
requires = ["setuptools", "setuptools-scm"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools] | ||
packages = ["uniride_sme"] | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = "test/" | ||
addopts = "-vv" | ||
|
||
[pycodestyle] | ||
count = true | ||
max-line-length = 120 | ||
statistics = true | ||
|
||
[tool.pylint.format] | ||
max-line-length=120 | ||
|
||
[tool.pylint.main] | ||
ignore-paths = [] | ||
|
||
[tool.pylint.reports] | ||
msg-template="{path}:{line}: [{msg_id}, {obj}] {msg} ({symbol})" | ||
output-format="parseable" | ||
|
||
[tool.pylint.'messages control'] | ||
max-line-length = 120 | ||
disable=[] | ||
|
||
[tool.bandit] | ||
targets = ["app"] | ||
exclude_dirs = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,72 @@ | ||
# import pytest | ||
# from unittest.mock import MagicMock, patch, ANY, Mock | ||
# from uniride_sme.service.documents_service import document_user, document_to_verify, document_check | ||
# from uniride_sme.connect_pg import connect | ||
# from uniride_sme.utils.exception.documents_exceptions import DocumentsTypeException | ||
# from datetime import datetime | ||
|
||
|
||
# @pytest.fixture | ||
# def mock_connect(): | ||
# with patch("uniride_sme.connect_pg.connect") as mock: | ||
# yield mock | ||
|
||
|
||
# @pytest.fixture | ||
# def mock_get_query(): | ||
# with patch("uniride_sme.connect_pg.get_query") as mock: | ||
# yield mock | ||
|
||
|
||
# @pytest.fixture | ||
# def mock_disconnect(): | ||
# with patch("uniride_sme.connect_pg.disconnect") as mock: | ||
# yield mock | ||
|
||
|
||
# @pytest.fixture | ||
# def mock_execute_command(): | ||
# with patch("uniride_sme.connect_pg.execute_command") as mock: | ||
# yield mock | ||
|
||
|
||
# def test_document_user_valid(mock_connect, mock_get_query, mock_disconnect): | ||
# user_id = 123 | ||
# mock_document_data = [ | ||
# {"u_id": user_id, "d_license": "license_url", "v_license_verified": True}, | ||
# {"u_id": user_id, "d_id_card": "id_card_url", "v_id_card_verified": False}, | ||
# {"u_id": user_id, "d_school_certificate": "school_certificate_url", "v_school_certificate_verified": True}, | ||
# ] | ||
|
||
# mock_connect.return_value = MagicMock() | ||
# mock_get_query.return_value = mock_document_data | ||
# result = document_user(user_id) | ||
# assert result["user_id"] == user_id | ||
# assert len(result["documents"]) == len(mock_document_data) | ||
|
||
# mock_disconnect.assert_called_once() | ||
|
||
|
||
# def test_document_user_no_data(mock_get_query, mock_disconnect): | ||
# user_id = 456 | ||
# mock_get_query.return_value = [] | ||
|
||
# with pytest.raises(DocumentsTypeException): | ||
# document_user(user_id) | ||
|
||
# mock_disconnect.assert_called_once() | ||
|
||
|
||
# def test_document_check(mock_connect, mock_disconnect, mock_execute_command): | ||
# data = { | ||
# "user_id": 123, | ||
# "document": { | ||
# "type": "license", | ||
# "status": "verified", | ||
# }, | ||
# } | ||
|
||
# with patch("uniride_sme.connect_pg.connect", return_value=mock_connect): | ||
# result = document_check(data) | ||
|
||
# mock_connect.return_value = MagicMock() | ||
|
||
# expected_query = """ | ||
# UPDATE uniride.ur_document_verification | ||
# SET v_license_verified = %s | ||
# WHERE u_id = %s | ||
# """ | ||
# mock_execute_command.assert_called_once_with(mock_connect, expected_query, ("verified", 123)) | ||
|
||
# assert result == {"message": "DOCUMENT_STATUS_UPDATED"} | ||
|
||
|
||
# def test_document_check_invalid_document_type(mock_connect): | ||
# data = { | ||
# "user_id": 123, | ||
# "document": { | ||
# "type": "invalid_type", | ||
# "status": "verified", | ||
# }, | ||
# } | ||
# with pytest.raises(DocumentsTypeException): | ||
# document_check(data) | ||
|
||
|
||
# def test_document_to_verify(mock_connect, mock_get_query, mock_disconnect, mock_get_encoded_file): | ||
# user_id = 123 | ||
# mock_document_data = [ | ||
# (user_id, 456, "Doe", "John", "profile.jpg", datetime(2023, 1, 1), 1, 0, 1), | ||
# ] | ||
|
||
# mock_connect.return_value = MagicMock() | ||
# mock_get_query.return_value = mock_document_data | ||
|
||
# mock_get_encoded_file.return_value = "mocked_profile_picture_url" | ||
|
||
# result = document_to_verify() | ||
|
||
# assert len(result) == len(mock_document_data) | ||
# mock_disconnect.assert_called_once() | ||
# mock_get_encoded_file.assert_called_with("profile.jpg") | ||
import datetime | ||
from unittest.mock import MagicMock, patch | ||
import pytest | ||
from uniride_sme.service.user_service import ( | ||
users_information, | ||
verify_user, | ||
delete_user, | ||
user_information_id, | ||
user_stat_passenger, | ||
user_stat_driver, | ||
) | ||
from uniride_sme.utils.exception.user_exceptions import UserNotFoundException | ||
|
||
# Mocking the database connection and query functions | ||
@pytest.fixture | ||
def mock_connect_pg(monkeypatch): | ||
mock_conn = MagicMock() | ||
mock_get_query = MagicMock() | ||
mock_execute_command = MagicMock() | ||
monkeypatch.setattr("uniride_sme.service.user_service.connect_pg.connect", mock_conn) | ||
monkeypatch.setattr("uniride_sme.service.user_service.connect_pg.get_query", mock_get_query) | ||
monkeypatch.setattr("uniride_sme.service.user_service.connect_pg.execute_command", mock_execute_command) | ||
return mock_conn, mock_get_query, mock_execute_command | ||
|
||
|
||
def test_users_information(mock_connect_pg): | ||
"""Test users_information function""" | ||
mock_conn, mock_get_query, _ = mock_connect_pg | ||
mock_get_query.return_value = [ | ||
(1, 2, "Last", "First", "profile.jpg", datetime.datetime(2022, 1, 1), datetime.datetime(2022, 1, 2)), | ||
] | ||
result = users_information() | ||
assert len(result) == 1 | ||
assert result[0]["id_user"] == 1 | ||
assert result[0]["lastname"] == "Last" | ||
assert result[0]["firstname"] == "First" | ||
|
||
|
||
def test_verify_user_existing(mock_connect_pg): | ||
"""Test verify_user function for an existing user""" | ||
mock_conn, mock_get_query, _ = mock_connect_pg | ||
mock_get_query.return_value = [(1,)] | ||
verify_user(1) | ||
mock_conn.assert_called_once() | ||
mock_conn.return_value.close.assert_called_once() | ||
|
||
|
||
def test_verify_user_non_existing(mock_connect_pg): | ||
"""Test verify_user function for a non-existing user""" | ||
mock_conn, mock_get_query, _ = mock_connect_pg | ||
mock_get_query.return_value = [] | ||
with pytest.raises(UserNotFoundException): | ||
verify_user(1) | ||
mock_conn.assert_called_once() | ||
mock_conn.return_value.close.assert_called_once() | ||
|
||
def test_delete_user_existing(mock_connect_pg): | ||
"""Test delete_user function for an existing user""" | ||
mock_conn, _, mock_execute_command = mock_connect_pg | ||
# Mocking the result of the verify_user function | ||
with patch("uniride_sme.service.user_service.verify_user") as verify_user_mock: | ||
verify_user_mock.return_value = None | ||
delete_user(1) | ||
|
||
# Verify that the connection was opened and closed | ||
mock_conn.assert_called_once() | ||
# Verify that verify_user was called with the correct parameter | ||
verify_user_mock.assert_called_once_with(1) | ||
# Verify that execute_command was called with the correct query and values | ||
mock_execute_command.assert_called_once_with(mock_conn.return_value, "DELETE FROM uniride.ur_user WHERE u_id = %s", (1,)) | ||
# Verify that the connection was closed | ||
mock_conn.return_value.close.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.