Skip to content

Commit

Permalink
Merge branch 'master' into jls/b5-web-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
orangejenny committed Jun 10, 2024
2 parents 882870d + 9b23e3c commit 1c635c8
Show file tree
Hide file tree
Showing 56 changed files with 272 additions and 1,939 deletions.
11 changes: 3 additions & 8 deletions corehq/apps/app_manager/tests/test_repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from corehq.apps.app_manager.models import Application
from corehq.apps.domain.models import Domain
from corehq.motech.models import ConnectionSettings
from corehq.motech.repeaters.dbaccessors import delete_all_repeat_records
from corehq.motech.repeaters.models import AppStructureRepeater, SQLRepeatRecord
from corehq.motech.repeaters.models import AppStructureRepeater, RepeatRecord


class TestAppStructureRepeater(TestCase, DomainSubscriptionMixin):
Expand All @@ -37,10 +36,6 @@ def tearDownClass(cls):
clear_plan_version_cache()
super().tearDownClass()

def tearDown(self):
delete_all_repeat_records()
super().tearDown()

def test_repeat_record_not_created(self):
"""
When an application without a repeater is saved, then a repeat record should not be created
Expand All @@ -51,7 +46,7 @@ def test_repeat_record_not_created(self):

# Enqueued repeat records have next_check set 48 hours in the future.
later = datetime.utcnow() + timedelta(hours=48 + 1)
repeat_records = SQLRepeatRecord.objects.filter(domain=self.domain, next_check__lt=later)
repeat_records = RepeatRecord.objects.filter(domain=self.domain, next_check__lt=later)
self.assertEqual(len(repeat_records), 0)

def test_repeat_record_created(self):
Expand All @@ -67,7 +62,7 @@ def test_repeat_record_created(self):
self.addCleanup(self.application.delete)

later = datetime.utcnow() + timedelta(hours=48 + 1)
repeat_records = SQLRepeatRecord.objects.filter(domain=self.domain, next_check__lt=later)
repeat_records = RepeatRecord.objects.filter(domain=self.domain, next_check__lt=later)
self.assertEqual(len(repeat_records), 1)

def test_repeat_record_forwarded(self):
Expand Down
3 changes: 3 additions & 0 deletions corehq/apps/cleanup/deletable_doc_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

MAIN_DB = None
FIXTURES_DB = 'fixtures'
REPEATERS_DB = 'receiverwrapper'

# Doc types for classes we've removed from our code
# but may still have docs lying around from
Expand Down Expand Up @@ -43,6 +44,8 @@
'FixtureDataType': (FIXTURES_DB,),
'FixtureDataItem': (FIXTURES_DB,),
'FixtureOwnership': (FIXTURES_DB,),
'RepeatRecord': (REPEATERS_DB,),
'RepeatRecordAttempt': (REPEATERS_DB,),

# form and case types
'XFormInstance': (MAIN_DB,),
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/cleanup/management/commands/fire_repeaters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand

from corehq.motech.repeaters.models import SQLRepeatRecord, State
from corehq.motech.repeaters.models import RepeatRecord, State


class Command(BaseCommand):
Expand All @@ -10,7 +10,7 @@ def add_arguments(self, parser):
parser.add_argument('domain')

def handle(self, domain, **options):
records = SQLRepeatRecord.objects.filter(
records = RepeatRecord.objects.filter(
domain=domain,
next_check__isnull=False,
state__in=[State.Pending, State.Fail],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,3 @@ class Command(PopulateSQLCommand):
helpers.
"""
return None

def update_or_create_sql_object(self, doc):
model, created = self.sql_class().objects.update_or_create(
couch_id=doc['_id'],
defaults={
{%- for update in suggested_updates %}
{{ update }}
{%- endfor %}
})
{%- if submodels %}
{%- for model in submodels %}
# add code to migrate {{ class_name }}.{{ model }}
{%- endfor %}
{%- endif %}
return model, created
8 changes: 3 additions & 5 deletions corehq/apps/data_interfaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from corehq.apps.users.models import CouchUser
from corehq.form_processor.models import XFormInstance
from corehq.apps.case_importer.do_import import SubmitCaseBlockHandler, RowAndCase
from corehq.motech.repeaters.models import SQLRepeatRecord
from corehq.motech.repeaters.models import RepeatRecord
from corehq.sql_db.util import get_db_aliases_for_partitioned_query
from corehq.toggles import DISABLE_CASE_UPDATE_RULE_SCHEDULED_TASK
from corehq.util.celery_utils import no_result_task
Expand Down Expand Up @@ -203,7 +203,6 @@ def task_operate_on_payloads(
record_ids: List[str],
domain: str,
action, # type: Literal['resend', 'cancel', 'requeue'] # 3.8+
use_sql: bool = True,
):
return operate_on_payloads(record_ids, domain, action, task=task_operate_on_payloads)

Expand All @@ -214,7 +213,6 @@ def task_generate_ids_and_operate_on_payloads(
repeater_id: Optional[str],
domain: str,
action, # type: Literal['resend', 'cancel', 'requeue'] # 3.8+
use_sql: bool = True,
) -> dict:
repeat_record_ids = _get_repeat_record_ids(payload_id, repeater_id, domain)
return operate_on_payloads(repeat_record_ids, domain, action,
Expand All @@ -223,12 +221,12 @@ def task_generate_ids_and_operate_on_payloads(

def _get_repeat_record_ids(payload_id, repeater_id, domain):
if payload_id:
queryset = SQLRepeatRecord.objects.filter(
queryset = RepeatRecord.objects.filter(
domain=domain,
payload_id=payload_id,
)
elif repeater_id:
queryset = SQLRepeatRecord.objects.filter(
queryset = RepeatRecord.objects.filter(
domain=domain,
repeater__id=repeater_id,
)
Expand Down
34 changes: 10 additions & 24 deletions corehq/apps/data_interfaces/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
operate_on_payloads,
)
from corehq.motech.models import ConnectionSettings
from corehq.motech.repeaters.models import FormRepeater, SQLRepeatRecord
from dimagi.utils.couch.migration import SyncSQLToCouchMixin
from corehq.motech.repeaters.models import FormRepeater, RepeatRecord

DOMAIN = 'test-domain'

Expand All @@ -25,39 +24,39 @@ def test__get_ids_no_data(self):
response = _get_repeat_record_ids(None, None, 'test_domain')
self.assertEqual(response, [])

@patch('corehq.apps.data_interfaces.tasks.SQLRepeatRecord.objects.filter')
@patch('corehq.apps.data_interfaces.tasks.RepeatRecord.objects.filter')
def test__get_ids_payload_id_in_data(self, get_by_payload_id):
payload_id = Mock()
_get_repeat_record_ids(payload_id, None, 'test_domain')

self.assertEqual(get_by_payload_id.call_count, 1)
get_by_payload_id.assert_called_with(domain='test_domain', payload_id=payload_id)

@patch('corehq.apps.data_interfaces.tasks.SQLRepeatRecord.objects.filter')
@patch('corehq.apps.data_interfaces.tasks.RepeatRecord.objects.filter')
def test__get_ids_payload_id_not_in_data(self, iter_by_repeater):
REPEATER_ID = 'c0ffee'
_get_repeat_record_ids(None, REPEATER_ID, 'test_domain')

iter_by_repeater.assert_called_with(domain='test_domain', repeater__id=REPEATER_ID)
self.assertEqual(iter_by_repeater.call_count, 1)

@patch('corehq.motech.repeaters.models.SQLRepeatRecord.objects')
@patch('corehq.motech.repeaters.models.RepeatRecord.objects')
def test__validate_record_record_does_not_exist(self, mock_objects):
mock_objects.get.side_effect = [SQLRepeatRecord.DoesNotExist]
mock_objects.get.side_effect = [RepeatRecord.DoesNotExist]
response = _get_sql_repeat_record('test_domain', '1234')

mock_objects.get.assert_called_once_with(domain='test_domain', id='1234')
self.assertIsNone(response)

@patch('corehq.motech.repeaters.models.SQLRepeatRecord.objects')
@patch('corehq.motech.repeaters.models.RepeatRecord.objects')
def test__validate_record_invalid_domain(self, mock_objects):
mock_objects.get.side_effect = SQLRepeatRecord.DoesNotExist
mock_objects.get.side_effect = RepeatRecord.DoesNotExist
response = _get_sql_repeat_record('test_domain', '1234')

mock_objects.get.assert_called_once_with(domain='test_domain', id='1234')
self.assertIsNone(response)

@patch('corehq.motech.repeaters.models.SQLRepeatRecord.objects')
@patch('corehq.motech.repeaters.models.RepeatRecord.objects')
def test__validate_record_success(self, mock_objects):
mock_record = Mock()
mock_record.domain = 'test_domain'
Expand All @@ -67,19 +66,6 @@ def test__validate_record_success(self, mock_objects):
mock_objects.get.assert_called_once_with(domain='test_domain', id='1234')
self.assertEqual(response, mock_record)

@patch('corehq.motech.repeaters.models.SQLRepeatRecord.objects')
def test__validate_record_success_with_couch_id(self, mock_objects):
couch_id = 'b6859ae05fd94dccbc3dfd25cdc6cb2c'
mock_record = Mock()
mock_record.domain = 'test_domain'
mock_objects.get.return_value = mock_record
response = _get_sql_repeat_record('test_domain', couch_id)

mock_objects.get.assert_called_once_with(domain='test_domain', couch_id=couch_id)
self.assertEqual(response, mock_record)
assert issubclass(SQLRepeatRecord, SyncSQLToCouchMixin), \
"couch_id not supported? Should this test be removed?"


class TestTasks(TestCase):

Expand Down Expand Up @@ -504,13 +490,13 @@ def setUpClass(cls):
@classmethod
def create_repeat_records(cls):
now = datetime.now()
cls.sql_records = [SQLRepeatRecord(
cls.sql_records = [RepeatRecord(
domain=DOMAIN,
repeater_id=cls.repeater.id,
payload_id=cls.instance_id,
registered_at=now,
) for __ in range(3)]
SQLRepeatRecord.objects.bulk_create(cls.sql_records)
RepeatRecord.objects.bulk_create(cls.sql_records)

def test_no_payload_id_no_repeater_id_sql(self):
result = _get_repeat_record_ids(payload_id=None, repeater_id=None, domain=DOMAIN)
Expand Down
8 changes: 3 additions & 5 deletions corehq/apps/data_interfaces/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,10 @@ def operate_on_payloads(


def _get_sql_repeat_record(domain, record_id):
from corehq.motech.repeaters.models import SQLRepeatRecord, is_sql_id

where = {"id": record_id} if is_sql_id(record_id) else {"couch_id": record_id}
from corehq.motech.repeaters.models import RepeatRecord
try:
return SQLRepeatRecord.objects.get(domain=domain, **where)
except SQLRepeatRecord.DoesNotExist:
return RepeatRecord.objects.get(domain=domain, id=record_id)
except RepeatRecord.DoesNotExist:
return None


Expand Down
8 changes: 4 additions & 4 deletions corehq/apps/domain/tests/test_delete_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
from corehq.motech.repeaters.models import (
CaseRepeater,
Repeater,
SQLRepeatRecord,
SQLRepeatRecordAttempt,
RepeatRecord,
RepeatRecordAttempt,
)
from settings import HQ_ACCOUNT_ROOT

Expand Down Expand Up @@ -973,8 +973,8 @@ def test_motech_delete(self):
def _assert_repeaters_count(self, domain_name, count):
self._assert_queryset_count([
Repeater.objects.filter(domain=domain_name),
SQLRepeatRecord.objects.filter(domain=domain_name),
SQLRepeatRecordAttempt.objects.filter(repeat_record__domain=domain_name),
RepeatRecord.objects.filter(domain=domain_name),
RepeatRecordAttempt.objects.filter(repeat_record__domain=domain_name),
], count)

def test_repeaters_delete(self):
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/domain/tests/test_deletion_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
'fixtures.UserLookupTableStatus',
'fixtures.LookupTableRow', # handled by cascading delete
'fixtures.LookupTableRowOwner', # handled by cascading delete
'repeaters.SQLRepeatRecord', # handled by cascading delete
'repeaters.SQLRepeatRecordAttempt', # handled by cascading delete
'repeaters.RepeatRecord', # handled by cascading delete
'repeaters.RepeatRecordAttempt', # handled by cascading delete
'sms.MigrationStatus',
'util.BouncedEmail',
'util.ComplaintBounceMeta',
Expand Down
2 changes: 0 additions & 2 deletions corehq/apps/dump_reload/couch/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from corehq.apps.dump_reload.couch.id_providers import (
DocTypeIDProvider,
DomainInListKeyGenerator,
DomainKeyGenerator,
WebUserIDProvider,
ViewIDProvider,
Expand Down Expand Up @@ -36,7 +35,6 @@
DocTypeIDProvider('ExportDataSchema'),
DocTypeIDProvider('CaseExportInstance'),
DocTypeIDProvider('CaseExportDataSchema'),
ViewIDProvider('RepeatRecord', 'repeaters/repeat_records', DomainInListKeyGenerator([None])),
}

DOC_PROVIDERS_BY_DOC_TYPE = {
Expand Down
12 changes: 0 additions & 12 deletions corehq/apps/dump_reload/couch/id_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ def get_key_args(self, doc_type, domain):
}


class DomainInListKeyGenerator(ViewKeyGenerator):
def __init__(self, static_key_items=None):
self.static_key_items = static_key_items or []

def get_key_args(self, doc_type, domain):
startkey = [domain] + self.static_key_items
return {
'startkey': startkey,
'endkey': startkey + [{}],
}


class ViewIDProvider(BaseIDProvider):
"""ID provider that gets ID's from view rows
:param doc_type: Doc Type of returned docs
Expand Down
6 changes: 3 additions & 3 deletions corehq/apps/dump_reload/sql/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@
FilteredModelIteratorBuilder('repeaters.Repeater', SimpleFilter('domain')),
FilteredModelIteratorBuilder('motech.ConnectionSettings', SimpleFilter('domain')),
FilteredModelIteratorBuilder('motech.RequestLog', SimpleFilter('domain')),
# NH (2021-01-08): Including SQLRepeatRecord because we dump (Couch)
# NH (2021-01-08): Including RepeatRecord because we dump (Couch)
# RepeatRecord, but this does not seem like a good idea.
FilteredModelIteratorBuilder('repeaters.SQLRepeatRecord', SimpleFilter('domain')),
FilteredModelIteratorBuilder('repeaters.SQLRepeatRecordAttempt', SimpleFilter('repeat_record__domain')),
FilteredModelIteratorBuilder('repeaters.RepeatRecord', SimpleFilter('domain')),
FilteredModelIteratorBuilder('repeaters.RepeatRecordAttempt', SimpleFilter('repeat_record__domain')),
FilteredModelIteratorBuilder('saved_reports.ScheduledReportLog', SimpleFilter('domain')),
UnfilteredModelIteratorBuilder('saved_reports.ScheduledReportsCheckpoint'),
FilteredModelIteratorBuilder('translations.SMSTranslations', SimpleFilter('domain')),
Expand Down
6 changes: 0 additions & 6 deletions corehq/apps/hqadmin/corrupt_couch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from corehq.apps.userreports.models import ReportConfiguration
from corehq.apps.users.models import CommCareUser
from corehq.apps.domain.models import Domain
from corehq.motech.repeaters.models import RepeatRecord
from corehq.toggles.models import Toggle
from corehq.util.couch_helpers import NoSkipArgsProvider
from corehq.util.pagination import ResumableFunctionIterator
Expand Down Expand Up @@ -53,11 +52,6 @@
"type": Application,
"use_domain": True,
},
"receiver_wrapper_repeat_records": {
"type": RepeatRecord,
"use_domain": True,
"view": "repeaters/repeat_records",
},
"meta": {
"type": ReportConfiguration,
"use_domain": True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ code {

a {
cursor: pointer;
}

button {
font-weight: bold !important; // to meet WCAG AA guidelines
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ $dimagi-mango: #FC5F36;


// Base color overrides
$blue: darken(#5D70D2, 20%);
$green: darken(#3FA12A, 10%);
$red: darken($dimagi-sunset, 20%);
$blue: #5D70D2;
$green: #358623;
$red: #E13019;
$teal: #01A2A9;
$yellow: $dimagi-marigold;
$indigo: $dimagi-indigo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@
+
+
+// Base color overrides
+$blue: darken(#5D70D2, 20%);
+$green: darken(#3FA12A, 10%);
+$red: darken($dimagi-sunset, 20%);
+$blue: #5D70D2;
+$green: #358623;
+$red: #E13019;
+$teal: #01A2A9;
+$yellow: $dimagi-marigold;
+$indigo: $dimagi-indigo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

.no-border {
@@ -81,11 +82,6 @@
@@ -81,11 +82,10 @@
}
}

Expand All @@ -39,5 +39,8 @@
-
a {
cursor: pointer;
-}
}
+
+button {
+ font-weight: bold !important; // to meet WCAG AA guidelines
+}
Loading

0 comments on commit 1c635c8

Please sign in to comment.