Skip to content

Commit

Permalink
Merge pull request #33432 from dimagi/mjr/duplicate_case_rule_filter_…
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
mjriley authored Sep 7, 2023
2 parents 9864606 + d21a393 commit 8c6cdda
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.test import TestCase
from django.test.client import RequestFactory

from corehq.apps.data_interfaces.models import AutomaticUpdateRule
from corehq.apps.reports.standard.cases.filters import DuplicateCaseRuleFilter


class TestDuplicateCaseRuleFilter(TestCase):
def test_get_value_returns_rule(self):
dedupe_rule = self._create_rule(domain='domain')
request = self._create_request_for_rule(dedupe_rule)

value = DuplicateCaseRuleFilter.get_value(request, domain='domain')
self.assertEqual(value, str(dedupe_rule.id))

def test_get_value_returns_none_on_data_from_other_domain(self):
unauthorized_rule = self._create_rule(domain='unauthorized-domain')
request = self._create_request_for_rule(unauthorized_rule)

self.assertIsNone(DuplicateCaseRuleFilter.get_value(request, domain='domain'))

def setUp(self):
self.factory = RequestFactory()

def _create_rule(self, domain):
return AutomaticUpdateRule.objects.create(
domain=domain,
name='test-rule',
case_type='test-case-type',
workflow=AutomaticUpdateRule.WORKFLOW_DEDUPLICATE,
active=True
)

def _create_request_for_rule(self, rule):
return self.factory.get('dedupe_report_url', data={'duplicate_case_rule': rule.id})

0 comments on commit 8c6cdda

Please sign in to comment.