Skip to content

Commit

Permalink
Merge branch 'develop' into feature/daily-trip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayoub-Bouaziz committed Jan 15, 2024
2 parents 5785c14 + 2f1355d commit 3706237
Show file tree
Hide file tree
Showing 30 changed files with 2,150 additions and 1,798 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
python-version: ["3.10"]

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
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

Expand Down
Binary file removed documents/id_card/154.png
Binary file not shown.
Binary file removed documents/id_card/164.png
Binary file not shown.
Binary file removed documents/id_card/165.png
Binary file not shown.
Binary file removed documents/id_card/166.png
Binary file not shown.
Binary file removed documents/id_card/171.png
Binary file not shown.
Binary file removed documents/insurance/154.jpg
Binary file not shown.
Empty file added documents/license/.gitkeep
Empty file.
Binary file removed documents/pft/123.jpg
Binary file not shown.
Binary file removed documents/pft/125.jpg
Binary file not shown.
Binary file removed documents/pft/154.jpg
Binary file not shown.
Binary file removed documents/pft/171.png
Binary file not shown.
Binary file removed documents/school_certificate/154.jpg
Binary file not shown.
Binary file removed documents/school_certificate/164.jpg
Binary file not shown.
Binary file removed documents/school_certificate/165.jpg
Binary file not shown.
Binary file removed documents/school_certificate/166.jpg
Binary file not shown.
Binary file removed documents/school_certificate/171.jpg
Binary file not shown.
Binary file removed documents/school_certificate/66.png
Binary file not shown.
154 changes: 77 additions & 77 deletions pyproject.toml
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 = []
183 changes: 72 additions & 111 deletions test/unit/test_service/test_admin.py
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()
2 changes: 1 addition & 1 deletion test/unit/test_service/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def mock_verify_password(monkeypatch):
def test_authenticate_success(mock_get_user_by_login, mock_verify_password, login, password):
"""Test authenticate is working correctly"""
mock_get_user_by_login.return_value = UserBO(
1,
1,
"user1",
"u",
"s",
Expand Down
2 changes: 1 addition & 1 deletion uniride_sme/route/trip_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_trip(trip_id):
return response


@trip.route("/trip_number", methods=["GET"])
@trip.route("/trip-number", methods=["GET"])
@role_required(RoleUser.ADMINISTRATOR)
def trip_count():
"""Trip count"""
Expand Down
Loading

0 comments on commit 3706237

Please sign in to comment.