-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:dimagi/commcare-hq into em/write-…
…domain-metrics
- Loading branch information
Showing
173 changed files
with
5,862 additions
and
3,416 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.test import SimpleTestCase | ||
from corehq.apps.builds.utils import is_out_of_date | ||
|
||
|
||
class TestVersionUtils(SimpleTestCase): | ||
|
||
def test_is_out_of_date(self): | ||
test_cases = [ | ||
# (version_in_use, latest_version, expected_result) | ||
('2.53.0', '2.53.1', True), # Normal case - out of date | ||
('2.53.1', '2.53.1', False), # Same version - not out of date | ||
('2.53.2', '2.53.1', False), # Higher version - not out of date | ||
(None, '2.53.1', False), # None version_in_use | ||
('2.53.1', None, False), # None latest_version | ||
('invalid', '2.53.1', False), # Invalid version string | ||
('2.53.1', 'invalid', False), # Invalid latest version | ||
('6', '7', True), # Normal case - app version is integer | ||
(None, None, False), # None version_in_use and latest_version | ||
('2.54', '2.54.0', False), # Edge case - should not be out of date | ||
('2.54.0', '2.54', False), # Edge case - should not be out of date | ||
] | ||
|
||
for version_in_use, latest_version, expected in test_cases: | ||
with self.subTest(version_in_use=version_in_use, latest_version=latest_version): | ||
result = is_out_of_date(version_in_use, latest_version) | ||
self.assertEqual( | ||
result, | ||
expected, | ||
f"Expected is_out_of_date('{version_in_use}', '{latest_version}') to be {expected}" | ||
) |
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
56 changes: 56 additions & 0 deletions
56
corehq/apps/cleanup/management/commands/hard_delete_forms.py
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
import csv | ||
import itertools | ||
from dimagi.utils.chunked import chunked | ||
from corehq.form_processor.models import XFormInstance | ||
|
||
|
||
INDEX_FORM_ID = 0 | ||
CHUNK_SIZE = 100 | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('domain', help='Domain name that owns the forms to be deleted') | ||
parser.add_argument('filename', help='path to the CSV file') | ||
parser.add_argument('--resume_id', help='form ID to start at, within the CSV file') | ||
|
||
def handle(self, domain, filename, resume_id=None, **options): | ||
# expects the filename to have a CSV with a header containing a "Form ID" field | ||
with open(filename, mode='r', encoding='utf-8-sig') as csvfile: | ||
reader = csv.reader(csvfile, delimiter=',') | ||
self._process_rows(reader, domain, resume_id) | ||
|
||
def _process_rows(self, rows, domain, resume_id): | ||
header_row = next(rows) # skip header line | ||
if header_row[INDEX_FORM_ID] != 'Form ID': | ||
raise CommandError( | ||
f'Expected Column {INDEX_FORM_ID} to be "Form ID", found "{header_row[INDEX_FORM_ID]}". Exiting' | ||
) | ||
|
||
num_deleted = 0 | ||
|
||
if resume_id: | ||
print('resuming at: ', resume_id) | ||
rows = itertools.dropwhile(lambda row: row[INDEX_FORM_ID] != resume_id, rows) | ||
|
||
print('Starting form deletion') | ||
for chunk in chunked(rows, CHUNK_SIZE): | ||
form_ids = [row[INDEX_FORM_ID] for row in chunk] | ||
|
||
try: | ||
deleted_form_ids = set(XFormInstance.objects.hard_delete_forms( | ||
domain, form_ids, return_ids=True)) | ||
except Exception: | ||
print('failed during processing of: ', form_ids) | ||
raise | ||
|
||
for form_id in form_ids: | ||
if form_id in deleted_form_ids: | ||
print('Deleted: ', form_id) | ||
else: | ||
print('Not found:', form_id) | ||
|
||
num_deleted += len(deleted_form_ids) | ||
|
||
print(f'Complete -- removed {num_deleted} forms') |
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
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
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.