示例#1
0
    def test_recipient_case_owner_location_parent(self):
        parent_location = SQLLocation.objects.create(
            domain=self.domain,
            name='parent test',
            site_code='parent',
            location_type=self.parent_location_type)

        child_location = SQLLocation.objects.create(
            domain=self.domain,
            name='child test',
            site_code='child',
            location_type=self.child_location_type,
            parent=parent_location)

        self.user.set_location(child_location.couch_location)

        with create_test_case(self.domain,
                              'test-case',
                              'test-name',
                              owner_id=self.user.get_id) as case:
            self.assertEqual(case.owner_id, self.user.get_id)
            handler = CaseReminderHandler(
                domain=self.domain,
                recipient=RECIPIENT_CASE_OWNER_LOCATION_PARENT)
            reminder = CaseReminder(domain=self.domain, case_id=case.case_id)

            # Test the recipient is returned correctly
            with patch('corehq.apps.reminders.models.CaseReminder.handler',
                       new=handler):
                self.assertEqual(reminder.recipient, [parent_location])

            # Remove parent location
            parent_location.delete()
            child_location.parent = None
            child_location.save()
            with patch('corehq.apps.reminders.models.CaseReminder.handler',
                       new=handler):
                self.assertIsNone(reminder.recipient)

            # Remove child location
            self.user.unset_location()
            child_location.delete()
            with patch('corehq.apps.reminders.models.CaseReminder.handler',
                       new=handler):
                self.assertIsNone(reminder.recipient)

            # Remove case
            reminder.case_id = None
            with patch('corehq.apps.reminders.models.CaseReminder.handler',
                       new=handler):
                self.assertIsNone(reminder.recipient)
示例#2
0
    def test_recipient_case_owner_location_parent(self):
        parent_location = SQLLocation.objects.create(
            domain=self.domain,
            name='parent test',
            site_code='parent',
            location_type=self.parent_location_type
        )

        child_location = SQLLocation.objects.create(
            domain=self.domain,
            name='child test',
            site_code='child',
            location_type=self.child_location_type,
            parent=parent_location
        )

        self.user.set_location(child_location.couch_location)

        with create_test_case(self.domain, 'test-case', 'test-name', owner_id=self.user.get_id) as case:
            self.assertEqual(case.owner_id, self.user.get_id)
            handler = CaseReminderHandler(domain=self.domain, recipient=RECIPIENT_CASE_OWNER_LOCATION_PARENT)
            reminder = CaseReminder(domain=self.domain, case_id=case.case_id)

            # Test the recipient is returned correctly
            with patch('corehq.apps.reminders.models.CaseReminder.handler', new=handler):
                self.assertEqual(reminder.recipient, [parent_location])

            # Remove parent location
            parent_location.delete()
            child_location.parent = None
            child_location.save()
            with patch('corehq.apps.reminders.models.CaseReminder.handler', new=handler):
                self.assertIsNone(reminder.recipient)

            # Remove child location
            self.user.unset_location()
            child_location.delete()
            with patch('corehq.apps.reminders.models.CaseReminder.handler', new=handler):
                self.assertIsNone(reminder.recipient)

            # Remove case
            reminder.case_id = None
            with patch('corehq.apps.reminders.models.CaseReminder.handler', new=handler):
                self.assertIsNone(reminder.recipient)
示例#3
0
    def test_host_case_owner_location(self):
        parent_location = SQLLocation.objects.create(
            domain=self.domain,
            name='parent test',
            site_code='parent',
            location_type=self.parent_location_type)
        self.addCleanup(parent_location.delete)

        child_location = SQLLocation.objects.create(
            domain=self.domain,
            name='child test',
            site_code='child',
            location_type=self.child_location_type,
            parent=parent_location)
        self.addCleanup(child_location.delete)

        with create_test_case(self.domain, 'test-extension-case',
                              'name') as extension_case:
            with create_test_case(self.domain, 'test-host-case',
                                  'name') as host_case:

                update_case(
                    self.domain,
                    host_case.case_id,
                    case_properties={'owner_id': child_location.location_id})
                set_parent_case(self.domain,
                                extension_case,
                                host_case,
                                relationship='extension')

                handler1 = CaseReminderHandler(
                    domain=self.domain, recipient='HOST_CASE_OWNER_LOCATION')
                handler2 = CaseReminderHandler(
                    domain=self.domain,
                    recipient='HOST_CASE_OWNER_LOCATION_PARENT')
                reminder = CaseReminder(domain=self.domain,
                                        case_id=extension_case.case_id)

                # Test the recipients are returned correctly
                with patch('corehq.apps.reminders.models.CaseReminder.handler',
                           new=handler1):
                    self.assertEqual(reminder.recipient, [child_location])

                with patch('corehq.apps.reminders.models.CaseReminder.handler',
                           new=handler2):
                    self.assertEqual(reminder.recipient, [parent_location])

                # Remove parent location reference
                child_location.parent = None
                child_location.save()
                with patch('corehq.apps.reminders.models.CaseReminder.handler',
                           new=handler2):
                    self.assertIsNone(reminder.recipient)

                # Test location that does not exist
                update_case(self.domain,
                            host_case.case_id,
                            case_properties={'owner_id': 'does-not-exist'})
                with patch('corehq.apps.reminders.models.CaseReminder.handler',
                           new=handler1):
                    self.assertIsNone(reminder.recipient)

                # Test on a case that is not an extension case
                reminder.case_id = host_case.case_id
                with patch('corehq.apps.reminders.models.CaseReminder.handler',
                           new=handler1):
                    self.assertIsNone(reminder.recipient)

                # Test on a blank case id
                reminder.case_id = None
                with patch('corehq.apps.reminders.models.CaseReminder.handler',
                           new=handler1):
                    self.assertIsNone(reminder.recipient)