Esempio n. 1
0
    def test_bad_group(self):
        """
        Notify if owner_id is set to a NON-case-sharing group
        """
        connection_settings_url = absolute_reverse(
            ConnectionSettingsListView.urlname, args=[TEST_DOMAIN])

        with get_importer() as importer:
            importer.owner_id = self.bad_group._id
            import_patients_with_importer(importer.to_json())
            self.send_mail_mock.delay.assert_called_with(
                'MOTECH Error',
                f'Error importing patients for project space "{TEST_DOMAIN}" '
                'from OpenMRS Importer "<OpenmrsImporter None '
                'admin@http://www.example.com/openmrs>": owner_id '
                f'"{importer.owner_id}" is invalid.\r\n'
                '\r\n'
                f'Project space: {TEST_DOMAIN}\r\n'
                'Remote API base URL: http://www.example.com/openmrs\r\n'
                '\r\n'
                '*Why am I getting this email?*\r\n'
                'This address is configured in CommCare HQ as a notification '
                'address for integration errors.\r\n'
                '\r\n'
                '*How do I unsubscribe?*\r\n'
                'Open Connection Settings in CommCare HQ '
                f'({connection_settings_url}) and remove your email address '
                'from the "Addresses to send notifications" field for remote '
                'connections. If necessary, please provide an alternate '
                'address.',
                from_email=settings.DEFAULT_FROM_EMAIL,
                recipient_list=['*****@*****.**'],
            )
Esempio n. 2
0
 def test_web_user_owner(self):
     """
     Setting owner_id to a web user should not throw an error
     """
     with get_importer() as importer:
         importer.owner_id = self.web_user.user_id
         import_patients_with_importer(importer.to_json())
         self.import_mock.assert_called()
Esempio n. 3
0
 def test_group_owner(self):
     """
     Setting owner_id to a case-sharing group should not throw an error
     """
     with get_importer() as importer:
         importer.owner_id = self.group._id
         import_patients_with_importer(importer.to_json())
         self.import_mock.assert_called()
Esempio n. 4
0
 def test_location_owner(self):
     """
     Setting owner_id to a location should not throw an error
     """
     with get_importer() as importer:
         importer.owner_id = self.locations['Gardens'].location_id
         import_patients_with_importer(importer.to_json())
         self.import_mock.assert_called()
Esempio n. 5
0
 def test_commcare_user_owner(self):
     """
     Setting owner_id to a mobile worker should not throw an error
     """
     with get_importer() as importer:
         importer.owner_id = self.mobile_worker.user_id
         import_patients_with_importer(importer.to_json())
         self.import_mock.assert_called()
Esempio n. 6
0
 def test_group_owner(self):
     """
     Setting owner_id to a case-sharing group should not throw an error
     """
     with get_importer() as importer, \
             patch('corehq.motech.openmrs.tasks.import_patients_of_owner') as import_mock, \
             patch('corehq.motech.openmrs.tasks.b64_aes_decrypt'):
         importer.owner_id = self.group._id
         import_patients_with_importer(importer.to_json())
         import_mock.assert_called()
Esempio n. 7
0
 def test_commcare_user_owner(self):
     """
     Setting owner_id to a mobile worker should not throw an error
     """
     with get_importer() as importer, \
             patch('corehq.motech.openmrs.tasks.import_patients_of_owner') as import_mock, \
             patch('corehq.motech.openmrs.tasks.b64_aes_decrypt'):
         importer.owner_id = self.mobile_worker.user_id
         import_patients_with_importer(importer.to_json())
         import_mock.assert_called()
Esempio n. 8
0
 def test_location_owner(self):
     """
     Setting owner_id to a location should not throw an error
     """
     with get_importer() as importer, \
             patch('corehq.motech.openmrs.tasks.import_patients_of_owner') as import_mock, \
             patch('corehq.motech.openmrs.tasks.b64_aes_decrypt'):
         importer.owner_id = self.locations['Gardens'].location_id
         import_patients_with_importer(importer.to_json())
         import_mock.assert_called()
Esempio n. 9
0
 def test_bad_group(self):
     """
     Notify if owner_id is set to a NON-case-sharing group
     """
     with get_importer() as importer:
         importer.owner_id = self.bad_group._id
         import_patients_with_importer(importer.to_json())
         self.send_mail_mock.delay.assert_called_with(
             'MOTECH Error',
             'Error importing patients for project space "test-domain" from '
             'OpenMRS Importer "<OpenmrsImporter None admin@http://www.example.com/openmrs>": '
             f'owner_id "{importer.owner_id}" is invalid.\r\n'
             'Project space: test-domain\r\n'
             'Remote API base URL: http://www.example.com/openmrs',
             from_email=settings.DEFAULT_FROM_EMAIL,
             recipient_list=['*****@*****.**'],
         )
Esempio n. 10
0
 def test_bad_owner(self):
     """
     Notify on invalid owner_id
     """
     with get_importer() as importer:
         self.assertEqual(importer.owner_id, '123456')
         import_patients_with_importer(importer.to_json())
         self.send_mail_mock.delay.assert_called_with(
             'MOTECH Error',
             'Error importing patients for project space "test-domain" from '
             'OpenMRS Importer "<OpenmrsImporter None admin@http://www.example.com/openmrs>": '
             'owner_id "123456" is invalid.\r\n'
             'Project space: test-domain\r\n'
             'Remote API base URL: http://www.example.com/openmrs',
             from_email=settings.DEFAULT_FROM_EMAIL,
             recipient_list=['*****@*****.**'],
         )