def test_clone_repeaters(self): from corehq.apps.repeaters.models import Repeater from corehq.apps.repeaters.models import CaseRepeater from corehq.apps.repeaters.models import FormRepeater from custom.enikshay.integrations.nikshay.repeaters import NikshayRegisterPatientRepeater self.assertEqual(0, len(Repeater.by_domain(self.new_domain))) self.assertEqual( 0, len(NikshayRegisterPatientRepeater.by_domain(self.new_domain))) case_repeater = CaseRepeater( domain=self.old_domain, url='case-repeater-url', ) case_repeater.save() self.addCleanup(case_repeater.delete) form_repeater = FormRepeater( domain=self.old_domain, url='form-repeater-url', ) form_repeater.save() self.addCleanup(form_repeater.delete) custom_repeater = NikshayRegisterPatientRepeater( domain=self.old_domain, url='99dots') custom_repeater.save() self.addCleanup(custom_repeater.delete) self.make_clone(include=['repeaters']) cloned_repeaters = Repeater.by_domain(self.new_domain) self.assertEqual(3, len(cloned_repeaters)) self.assertEqual( {'CaseRepeater', 'FormRepeater', 'NikshayRegisterPatientRepeater'}, {repeater.doc_type for repeater in cloned_repeaters}) # test cache clearing cloned_niksay_repeaters = NikshayRegisterPatientRepeater.by_domain( self.new_domain) self.assertEqual(1, len(cloned_niksay_repeaters))
class TestNikshayRegisterPatientRepeater(NikshayRepeaterTestBase): def setUp(self): super(TestNikshayRegisterPatientRepeater, self).setUp() self.repeater = NikshayRegisterPatientRepeater(domain=self.domain, url='case-repeater-url', username='******') self.repeater.white_listed_case_types = ['episode'] self.repeater.save() def test_not_available_for_domain(self): self.assertFalse( NikshayRegisterPatientRepeater.available_for_domain(self.domain)) @flag_enabled('NIKSHAY_INTEGRATION') def test_available_for_domain(self): self.assertTrue( NikshayRegisterPatientRepeater.available_for_domain(self.domain)) @run_with_all_backends def test_trigger(self): # nikshay not enabled self.create_case(self.episode) self.assertEqual(0, len(self.repeat_records().all())) # nikshay enabled, should register a repeat record self._create_nikshay_enabled_case() self.assertEqual(1, len(self.repeat_records().all())) # # set as registered, should not register a new repeat record self._create_nikshay_registered_case() self.assertEqual(1, len(self.repeat_records().all())) @run_with_all_backends def test_trigger_different_case_type(self): # different case type self.create_case(self.person) self._create_nikshay_enabled_case(case_id=self.person_id) self.assertEqual(0, len(self.repeat_records().all()))
class TestNikshayRegisterPatientRepeater(ENikshayLocationStructureMixin, NikshayRepeaterTestBase): def setUp(self): super(TestNikshayRegisterPatientRepeater, self).setUp() self.repeater = NikshayRegisterPatientRepeater( domain=self.domain, url='case-repeater-url', username='******' ) self.repeater.white_listed_case_types = ['episode'] self.repeater.save() def test_not_available_for_domain(self): self.assertFalse(NikshayRegisterPatientRepeater.available_for_domain(self.domain)) @flag_enabled('NIKSHAY_INTEGRATION') def test_available_for_domain(self): self.assertTrue(NikshayRegisterPatientRepeater.available_for_domain(self.domain)) def test_trigger(self): # nikshay not enabled self.create_case(self.episode) self.assertEqual(0, len(self.repeat_records().all())) person = self.create_case(self.person)[0] with self.assertRaisesMessage( NikshayLocationNotFound, "Location with id {location_id} not found. This is the owner for person with " "id: {person_id}".format(location_id=person.owner_id, person_id=self.person_id) ): self._create_nikshay_enabled_case() # nikshay enabled, should register a repeat record self.assign_person_to_location(self.phi.location_id) self._create_nikshay_enabled_case() self.assertEqual(1, len(self.repeat_records().all())) # # set as registered, should not register a new repeat record self._create_nikshay_registered_case() self.assertEqual(1, len(self.repeat_records().all())) def test_trigger_different_case_type(self): # different case type self.create_case(self.person) self._create_nikshay_enabled_case(case_id=self.person_id) self.assertEqual(0, len(self.repeat_records().all())) def test_trigger_test_submission(self): self.phi.metadata['is_test'] = 'yes' self.phi.save() self.create_case(self.episode) self.assign_person_to_location(self.phi.location_id) self._create_nikshay_enabled_case() self.assertEqual(0, len(self.repeat_records().all())) def test_trigger_non_test_submission(self): self.phi.metadata['is_test'] = 'no' self.phi.save() self.create_case(self.episode) self.assign_person_to_location(self.phi.location_id) self._create_nikshay_enabled_case() self.assertEqual(1, len(self.repeat_records().all()))