Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOPE Add PDM #3751

Merged
merged 46 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9dfe6e2
init pdm
pavlo-mk Apr 2, 2024
e66e6e1
Merge branch 'develop' into 182432_add_pdm
pavlo-mk Apr 3, 2024
a54c8c1
add changes to Dockerfile
pavlo-mk Apr 3, 2024
8c2d0ab
upd PYTHONPATH
pavlo-mk Apr 4, 2024
0f918fd
Merge branch 'develop' into 182432_add_pdm
pavlo-mk Apr 5, 2024
9b6b74b
update path
pavlo-mk Apr 5, 2024
2db91c3
upd
pavlo-mk Apr 8, 2024
3c5a417
upd dockerfile
pavlo-mk Apr 9, 2024
c6830d9
linter & upd lock file
pavlo-mk Apr 9, 2024
b416ff2
Merge branch 'develop' into 182432_add_pdm
pavlo-mk Apr 9, 2024
b84aa99
Merge branch 'develop' into 182432_add_pdm
pavlo-mk Apr 9, 2024
c8ac13f
Merge branch 'develop' into 182432_add_pdm
pavlo-mk Apr 10, 2024
b68bf0d
add pytest-html
pavlo-mk Apr 10, 2024
bb42154
add test get_version
pavlo-mk Apr 11, 2024
5e44df9
upd test
pavlo-mk Apr 11, 2024
d902aae
Merge branch 'develop' into 182432_add_pdm
pavlo-mk Apr 15, 2024
1b01b72
minor fixes
pavlo-mk Apr 16, 2024
6874f90
refactoring
pavlo-mk Apr 16, 2024
8ef4f92
upd dependencies list
pavlo-mk Apr 16, 2024
f5a2118
upd bump version & docker file
pavlo-mk Apr 17, 2024
f7d1231
Merge branch 'develop' into 182432_add_pdm
pavlo-mk Apr 17, 2024
b539c8c
merge develop
pavlo-mk May 7, 2024
1f8d6af
black
pavlo-mk May 7, 2024
a49845b
upd lock file & black
pavlo-mk May 7, 2024
475a0df
mypy & add more info about pdm
pavlo-mk May 8, 2024
6f78235
Merge branch 'develop' into 182432_add_pdm
pavlo-mk May 8, 2024
d875cf6
black
pavlo-mk May 8, 2024
da66d7c
upd Dockerfile & pdm.lock
pavlo-mk May 8, 2024
9ac8bd7
test new Docker file
pavlo-mk May 8, 2024
75bbb9f
upd PATH
pavlo-mk May 9, 2024
58395d3
resolve conflicts
pavlo-mk May 9, 2024
139cfb8
clenup & add new docker env
pavlo-mk May 9, 2024
292e87d
black & more add info
pavlo-mk May 9, 2024
fd0bd9a
drf-extensions
pavlo-mk May 10, 2024
1e774fd
Merge branch 'develop' into 182432_add_pdm
pavlo-mk May 10, 2024
f3d2e72
add pytest-html-reporter
pavlo-mk May 10, 2024
4c909db
black
pavlo-mk May 10, 2024
727afa9
add test
pavlo-mk May 10, 2024
349e831
upd Docker file
pavlo-mk May 10, 2024
6508ac9
Merge branch 'develop' into 182432_add_pdm
pavlo-mk May 14, 2024
46319f6
black
pavlo-mk May 14, 2024
ecfa942
Merge remote-tracking branch 'origin/182432_add_pdm' into 182432_add_pdm
pavlo-mk May 14, 2024
401622c
black
pavlo-mk May 14, 2024
10fbd1a
isort
pavlo-mk May 14, 2024
f99726f
Merge branch 'develop' into 182432_add_pdm
pavlo-mk May 14, 2024
7d7c845
review
pavlo-mk May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ backend/test-results/
backend/lint-results/
backend/mypy-results/
backend/screenshot/
backend/__pypackages__/
cypress-results/
cypress-reports/

Expand Down
3 changes: 2 additions & 1 deletion backend/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ exclude =
# This contains builds of flake8 that we don't want to check
dist,
migrations,
snapshots
snapshots,
__pypackages__,

ignore =
# black formatting related
Expand Down
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pytest_screenshots
report
archive
output.json
pytest_html_report.html
pytest_html_report.html
.pdm-python
2 changes: 1 addition & 1 deletion backend/hct_mis_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
def get_full_version() -> str:
with open("pyproject.toml", mode="rb") as fp:
config = tomli.load(fp)
return config["tool"]["poetry"]["version"]
return config["project"]["version"]
2 changes: 1 addition & 1 deletion backend/hct_mis_api/api/endpoints/rdi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def create(self, validated_data: Dict) -> Dict:
number_of_households=info.households,
datahub_id=str(rdi_datahub.pk),
business_area=self.business_area,
program=program
program=program,
)
rdi_datahub.hct_id = rdi_mis.id
rdi_datahub.save()
Expand Down
1 change: 0 additions & 1 deletion backend/hct_mis_api/apps/account/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class Meta:


class PartnerRoleNode(DjangoObjectType):

class Meta:
model = BusinessAreaPartnerThrough
exclude = ("id",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ def test_create_accountability_communication_message_by_target_population(self,
self.user, [Permissions.ACCOUNTABILITY_COMMUNICATION_MESSAGE_VIEW_CREATE], self.business_area
)
broadcast_message_mock = MagicMock(return_value=None)
with patch(
"hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)
), patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.broadcast_message", broadcast_message_mock):
with (
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)),
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.broadcast_message", broadcast_message_mock),
):
self.snapshot_graphql_request(
request_string=self.MUTATION,
context={
Expand Down Expand Up @@ -151,9 +152,10 @@ def test_create_accountability_communication_message_by_households(self, samplin
self.user, [Permissions.ACCOUNTABILITY_COMMUNICATION_MESSAGE_VIEW_CREATE], self.business_area
)
broadcast_message_mock = MagicMock(return_value=None)
with patch(
"hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)
), patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.broadcast_message", broadcast_message_mock):
with (
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)),
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.broadcast_message", broadcast_message_mock),
):
self.snapshot_graphql_request(
request_string=self.MUTATION,
context={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ def test_create_survey_and_send_via_rapidpro(self) -> None:
households = [create_household({"size": 3})[0] for _ in range(3)]
self.tp.households.set(households)

with patch.object(django.db.transaction, "on_commit", lambda t: t()), patch(
"hct_mis_api.apps.accountability.celery_tasks.send_survey_to_users.delay"
) as task_mock:
with (
patch.object(django.db.transaction, "on_commit", lambda t: t()),
patch("hct_mis_api.apps.accountability.celery_tasks.send_survey_to_users.delay") as task_mock,
):
self.snapshot_graphql_request(
request_string=self.CREATE_SURVEY_MUTATION,
context={
Expand Down Expand Up @@ -259,11 +260,12 @@ def test_create_survey_without_recipients(self) -> None:
)

def test_getting_available_flows(self) -> None:
with patch(
"hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)
), patch(
"hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.get_flows",
MagicMock(return_value=[{"uuid": 123, "name": "flow2"}, {"uuid": 234, "name": "flow2"}]),
with (
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)),
patch(
"hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.get_flows",
MagicMock(return_value=[{"uuid": 123, "name": "flow2"}, {"uuid": 234, "name": "flow2"}]),
),
):
self.snapshot_graphql_request(
request_string=self.AVAILABLE_FLOWS,
Expand Down
1 change: 0 additions & 1 deletion backend/hct_mis_api/apps/core/tests/test_core_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class TestCoreFields(APITestCase):

def setUp(self) -> None:
self.scopes = [Scope.GLOBAL, Scope.XLSX_PEOPLE]
super().setUp()
Expand Down
2 changes: 1 addition & 1 deletion backend/hct_mis_api/apps/geo/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_choices(
include_blank: bool = True,
blank_choice: Optional[List[Union[Tuple[Any, Any], Tuple[str, Iterable[Tuple[Any, Any]]]]]] = None,
*args: Any,
**kwargs: Any
**kwargs: Any,
) -> List:
if self.choices and self.choices[0] == (None, None):
self.choices = Country.objects.all().values_list("iso_code2", "name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def save(self) -> List[GrievanceTicket]:
individual_data_with_approve_status["identities_to_remove"] = identities_to_remove_with_approve_status
individual_data_with_approve_status["identities_to_edit"] = prepare_edit_identities(identities_to_edit)
individual_data_with_approve_status["payment_channels"] = payment_channels_with_approve_status
individual_data_with_approve_status["payment_channels_to_remove"] = (
payment_channels_to_remove_with_approve_status
)
individual_data_with_approve_status[
"payment_channels_to_remove"
] = payment_channels_to_remove_with_approve_status
individual_data_with_approve_status["payment_channels_to_edit"] = prepare_edit_payment_channel(
payment_channels_to_edit
)
Expand Down Expand Up @@ -215,9 +215,9 @@ def update(self) -> GrievanceTicket:
identities_to_remove_with_approve_status
)
individual_data_with_approve_status["payment_channels"] = payment_channels_with_approve_status
individual_data_with_approve_status["payment_channels_to_remove"] = (
payment_channels_to_remove_with_approve_status
)
individual_data_with_approve_status[
"payment_channels_to_remove"
] = payment_channels_to_remove_with_approve_status
individual_data_with_approve_status["payment_channels_to_edit"] = prepare_edit_payment_channel(
payment_channels_to_edit
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def setUpTestData(cls) -> None:
IndividualFactory(
household=household_one if index % 2 else household_two,
program=household_one.program if index % 2 else household_two.program,
**individual
**individual,
)
for index, individual in enumerate(cls.individuals_to_create)
]
Expand Down
6 changes: 3 additions & 3 deletions backend/hct_mis_api/apps/grievance/tests/test_grievance_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def setUpTestData(cls) -> None:
}
)

cls.es.index(
cls.es.index( # type: ignore
index="test_es_db",
doc_type="_doc",
id=cls.grievance_ticket_1.id,
Expand Down Expand Up @@ -405,7 +405,7 @@ def setUpTestData(cls) -> None:
}
)

cls.es.index(
cls.es.index( # type: ignore
index="test_es_db",
doc_type="_doc",
id=cls.grievance_ticket_2.id,
Expand Down Expand Up @@ -447,7 +447,7 @@ def setUpTestData(cls) -> None:
}
)

cls.es.index(
cls.es.index( # type: ignore
index="test_es_db",
doc_type="_doc",
id=cls.grievance_ticket_3.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_update_referral_ticket_with_household_and_individual_extras(
) -> None:
self.create_user_role_with_permissions(self.user, permissions, self.business_area)

extras = {
extras: Dict = {
"household": self.id_to_base64(self.household.id, "HouseholdNode"),
"individual": self.id_to_base64(self.individuals[0].id, "IndividualNode"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ def test_import_valid_status_changed_received_yes_full(self) -> None:
payment_verification = PaymentVerification.objects.get(payment_object_id=payment_record_id)
self.assertEqual(payment_verification.status, PaymentVerification.STATUS_PENDING)
wb.active[f"{XlsxVerificationExportService.RECEIVED_COLUMN_LETTER}2"] = "YES"
wb.active[f"{XlsxVerificationExportService.RECEIVED_AMOUNT_COLUMN_LETTER}2"] = (
payment_verification.payment_obj.delivered_quantity
)
wb.active[
f"{XlsxVerificationExportService.RECEIVED_AMOUNT_COLUMN_LETTER}2"
] = payment_verification.payment_obj.delivered_quantity
with NamedTemporaryFile() as tmp:
wb.save(tmp.name)
file = io.BytesIO(tmp.read())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ def create_flow_response() -> Dict:
post_request_mock = MagicMock()

post_request_mock.side_effect = [first_flow, requests.exceptions.HTTPError("TEST")] # type: ignore
with patch(
"hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)
), patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI._handle_post_request", post_request_mock):
with (
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)),
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI._handle_post_request", post_request_mock),
):
try:
VerificationPlanStatusChangeServices(self.verification).activate()
except requests.exceptions.HTTPError:
Expand Down Expand Up @@ -227,9 +228,10 @@ def create_flow_response() -> Dict:

post_request_mock = MagicMock()
post_request_mock.side_effect = [first_flow, create_flow_response()]
with patch(
"hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)
), patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI._handle_post_request", post_request_mock):
with (
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI.__init__", MagicMock(return_value=None)),
patch("hct_mis_api.apps.core.services.rapid_pro.api.RapidProAPI._handle_post_request", post_request_mock),
):
VerificationPlanStatusChangeServices(self.verification).activate()

self.verification.refresh_from_db()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def _create_workbook(self) -> openpyxl.Workbook:
return wb

def _add_version(self) -> None:
self.ws_meta[XlsxVerificationExportService.VERSION_CELL_NAME_COORDINATES] = (
XlsxVerificationExportService.VERSION_CELL_NAME
)
self.ws_meta[
XlsxVerificationExportService.VERSION_CELL_NAME_COORDINATES
] = XlsxVerificationExportService.VERSION_CELL_NAME
self.ws_meta[XlsxVerificationExportService.VERSION_CELL_COORDINATES] = XlsxVerificationExportService.VERSION

def _to_received_column(self, payment_record_verification: PaymentVerification) -> Optional[str]:
Expand Down Expand Up @@ -117,7 +117,7 @@ def _add_data_validation(self) -> None:
self.dv_received = DataValidation(type="list", formula1='"YES,NO"', allow_blank=False)
self.dv_received.add(f"B2:B{len(self.ws_export_list['B'])}")
self.ws_export_list.add_data_validation(self.dv_received)
self.ws_export_list["B2" :f"B{len(self.ws_export_list['B'])}"]
self.ws_export_list["B2":f"B{len(self.ws_export_list['B'])}"]

def generate_workbook(self) -> openpyxl.Workbook:
self._create_workbook()
Expand Down
13 changes: 8 additions & 5 deletions backend/hct_mis_api/apps/reporting/tests/test_report_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,14 @@ def test_report_types(
report.save()

report_service = self.GenerateReportService(report)
with patch(
"hct_mis_api.apps.reporting.services.generate_report_service.GenerateReportService.save_wb_file_in_db"
) as mock_save_wb_file_in_db, patch(
"hct_mis_api.apps.reporting.services.generate_report_service.GenerateReportService.generate_workbook"
) as mock_generate_workbook:
with (
patch(
"hct_mis_api.apps.reporting.services.generate_report_service.GenerateReportService.save_wb_file_in_db"
) as mock_save_wb_file_in_db,
patch(
"hct_mis_api.apps.reporting.services.generate_report_service.GenerateReportService.generate_workbook"
) as mock_generate_workbook,
):
report_service.generate_report()
assert mock_generate_workbook.called
assert mock_save_wb_file_in_db.called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def generate_workbook(self) -> Workbook:
return self.workbook

def _add_version(self) -> None:
self.ws_meta[XlsxExportTargetingService.VERSION_CELL_NAME_COORDINATES] = (
XlsxExportTargetingService.VERSION_CELL_NAME
)
self.ws_meta[
XlsxExportTargetingService.VERSION_CELL_NAME_COORDINATES
] = XlsxExportTargetingService.VERSION_CELL_NAME
self.ws_meta[XlsxExportTargetingService.VERSION_CELL_COORDINATES] = XlsxExportTargetingService.VERSION

def _create_workbook(self) -> openpyxl.Workbook:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from hct_mis_api.apps.core.base_test_case import APITestCase
from hct_mis_api.apps.core.fixtures import create_afghanistan
from hct_mis_api.apps.targeting.fixtures import TargetPopulationFactory
from hct_mis_api.apps.targeting.models import TargetPopulation
from hct_mis_api.apps.targeting.services.xlsx_export_targeting_service import (
XlsxExportTargetingService,
)


class TestXlsxExportTargetingService(APITestCase):
@classmethod
def setUpTestData(cls) -> None:
cls.business_area = create_afghanistan()
cls.target_population = TargetPopulationFactory(
business_area=cls.business_area, status=TargetPopulation.STATUS_OPEN
)

def test_add_version(self) -> None:
service = XlsxExportTargetingService(self.target_population)
service._create_workbook()
service._add_version()
self.assertEqual(
service.ws_meta[XlsxExportTargetingService.VERSION_CELL_NAME_COORDINATES].value,
XlsxExportTargetingService.VERSION_CELL_NAME,
)
self.assertEqual(
service.ws_meta[XlsxExportTargetingService.VERSION_CELL_COORDINATES].value,
XlsxExportTargetingService.VERSION,
)

def test_add_standard_columns_headers(self) -> None:
service = XlsxExportTargetingService(self.target_population)
service._create_workbook()
service._add_standard_columns_headers()
headers = [cell.value for cell in service.ws_individuals[1]]
self.assertEqual(headers, ["Household unicef_id", "unicef_id", "Linked Households", "Bank account information"])
22 changes: 22 additions & 0 deletions backend/hct_mis_api/apps/utils/tests/test_get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Any
from unittest.mock import mock_open, patch

from django.test import TestCase

from hct_mis_api import get_full_version


class TestUtils(TestCase):
@patch("builtins.open", new_callable=mock_open, read_data=b'[project]\n version = "2.3.4"')
def test_get_full_version(self, mock_file_open: Any) -> None:
self.assertEqual(get_full_version(), "2.3.4")

@patch("builtins.open", side_effect=FileNotFoundError)
def test_file_not_found(self, mock_file_open: Any) -> None:
with self.assertRaises(FileNotFoundError):
get_full_version()

@patch("builtins.open", new_callable=mock_open, read_data=b'[project]\n wrong_key = "empty_version_XD"')
def test_key_not_found(self, mock_file_open: Any) -> None:
with self.assertRaises(KeyError):
get_full_version()
Loading
Loading