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

Back merge STG into DEV #4437

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export function RequestedIndividualDataChangeTable({
payment_channels_to_edit: paymentChannelsToEdit,
previous_payment_channels: previousPaymentChannels,
flex_fields: flexFields,
// eslint-disable-next-line
delivery_mechanism_data: _deliveryMechanismData,
delivery_mechanism_data_to_edit: deliveryMechanismDataToEdit,
// eslint-disable-next-line
delivery_mechanism_data_to_remove: _deliveryMechanismDataToRemove,
...restIndividualData
} = individualData;
const entries = restIndividualData && Object.entries(restIndividualData);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import logging
from typing import Any

from django.core.management import BaseCommand
from django.utils import timezone

from hct_mis_api.one_time_scripts.remove_migrated_data_is_original import (
get_statistic_is_original,
remove_migrated_data_is_original,
)

logger = logging.getLogger(__name__)


class Command(BaseCommand):
help = "Remove pre-GPF data, with is_original=True"

def handle(self, *args: Any, **options: Any) -> None:
start_time = timezone.now()
self.stdout.write("Starting to remove pre-GPF data.")

# get statistics
get_statistic_is_original()
# run script
remove_migrated_data_is_original()
# get statistics after
get_statistic_is_original()

self.stdout.write(self.style.SUCCESS(f"Done in {timezone.now() - start_time}"))
9 changes: 6 additions & 3 deletions src/hct_mis_api/apps/payment/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ def destroy(self, request: Request, *args: Any, **kwargs: Any) -> Response:
@action(detail=True, methods=["get"])
def download(self, request: Request, *args: Any, **kwargs: Any) -> FileResponse:
document = self.get_object()
file_mimetype, _ = mimetypes.guess_type(document.file.path)
response = FileResponse(document.file.open(), content_type=file_mimetype or "application/octet-stream")
response["Content-Disposition"] = f"attachment; filename={document.file.name.split('/')[-1]}"
file = document.file
file_mimetype, _ = mimetypes.guess_type(file.url)
response = FileResponse(
file.open(), as_attachment=True, content_type=file_mimetype or "application/octet-stream"
)
response["Content-Disposition"] = f"attachment; filename={file.name.split('/')[-1]}"
return response
2 changes: 1 addition & 1 deletion src/hct_mis_api/config/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"MAILJET_API_KEY": (str, ""),
"MAILJET_SECRET_KEY": (str, ""),
"CATCH_ALL_EMAIL": (list, []),
"DEFAULT_EMAIL_DISPLAY": (list, []),
"DEFAULT_EMAIL_DISPLAY": (str, ""),
"KOBO_KF_URL": (str, "https://kf-hope.unitst.org"),
"KOBO_KC_URL": (str, "https://kc-hope.unitst.org"),
"KOBO_MASTER_API_TOKEN": (str, "KOBO_TOKEN"),
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/apps/core/test_remove_pre_gpf_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from io import StringIO
from unittest import mock

from django.core.management import call_command
from django.test import TestCase

from hct_mis_api.apps.account.fixtures import BusinessAreaFactory
from hct_mis_api.apps.household.fixtures import (
HouseholdFactory,
IndividualFactory,
PendingHouseholdFactory,
PendingIndividualFactory,
)
from hct_mis_api.apps.household.models import (
Household,
Individual,
PendingHousehold,
PendingIndividual,
)


class TestRemovePreGpfDataCommands(TestCase):
def setUp(self) -> None:
BusinessAreaFactory(name="Afghanistan")
IndividualFactory(household=None)
IndividualFactory(is_original=True, household=None)
PendingIndividualFactory(household=None)
PendingIndividualFactory(is_original=True, household=None)
HouseholdFactory()
HouseholdFactory(is_original=True)
PendingHouseholdFactory()
PendingHouseholdFactory(is_original=True)

def test_remove_pre_gpf_data(self) -> None:
# check count before
self.assertEqual(Individual.all_objects.count(), 4)
self.assertEqual(PendingIndividual.all_objects.count(), 4)
self.assertEqual(Household.all_objects.count(), 4)
self.assertEqual(PendingHousehold.all_objects.count(), 4)

with mock.patch("sys.stdout", new=StringIO()):
call_command("remove-pre-gpf-data")

# check count after
self.assertEqual(Individual.all_objects.count(), 2)
self.assertEqual(PendingIndividual.all_objects.count(), 2)
self.assertEqual(Household.all_objects.count(), 2)
self.assertEqual(PendingHousehold.all_objects.count(), 2)
Loading