Exemple #1
0
 def test_handle_bad_nikshay_response(self):
     self._create_nikshay_enabled_case()
     payload_generator = NikshayRegisterPatientPayloadGenerator(None)
     response = {
         "Nikshay_Message": "Success",
         "Results": [
             {
                 "FieldName": "BadResponse",
                 "Fieldvalue": "Borked",
             }
         ]
     }
     payload_generator.handle_success(
         MockResponse(
             201,
             response,
         ),
         self.cases[self.episode_id],
         None,
     )
     updated_episode_case = CaseAccessors(self.domain).get_case(self.episode_id)
     self._assert_case_property_equal(updated_episode_case, 'nikshay_registered', 'false')
     self._assert_case_property_equal(
         updated_episode_case,
         'nikshay_error',
         'No Nikshay ID received: {}'.format(response)
     )
Exemple #2
0
 def test_handle_success(self):
     nikshay_id = "NIKSHAY!"
     self._create_nikshay_enabled_case()
     payload_generator = NikshayRegisterPatientPayloadGenerator(None)
     payload_generator.handle_success(
         MockResponse(
             201,
             {
                 "Nikshay_Message": "Success",
                 "Results": [
                     {
                         "FieldName": "NikshayId",
                         "Fieldvalue": nikshay_id,
                     }
                 ]
             }
         ),
         self.cases[self.episode_id],
         None,
     )
     updated_episode_case = CaseAccessors(self.domain).get_case(self.episode_id)
     self._assert_case_property_equal(updated_episode_case, 'nikshay_registered', 'true')
     self._assert_case_property_equal(updated_episode_case, 'nikshay_error', '')
     self._assert_case_property_equal(updated_episode_case, 'nikshay_id', nikshay_id)
     self.assertEqual(updated_episode_case.external_id, nikshay_id)
Exemple #3
0
 def test_handle_failure(self):
     message = {
         "Nikshay_Message":
         "Success",
         "Results": [{
             "FieldName":
             "NikshayId",
             "Fieldvalue":
             "The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_PatientsDetails_TBUnits\". The conflict occurred in database \"nikshay\", table \"dbo.TBUnits\".\u000d\u000a \u000d\u000aDM-ABC-01-16-0001\u000d\u000aThe statement has been terminated."  # noqa. yes, this is a real response.
         }]
     }
     payload_generator = NikshayRegisterPatientPayloadGenerator(None)
     payload_generator.handle_failure(
         MockResponse(
             400,
             message,
         ),
         self.cases[self.episode_id],
         None,
     )
     updated_episode_case = CaseAccessors(self.domain).get_case(
         self.episode_id)
     self._assert_case_property_equal(updated_episode_case,
                                      'nikshay_registered', 'false')
     self._assert_case_property_equal(updated_episode_case, 'nikshay_error',
                                      unicode(message))
Exemple #4
0
    def test_payload_properties(self):
        episode_case = self._create_nikshay_enabled_case()
        payload = (json.loads(
            NikshayRegisterPatientPayloadGenerator(None).get_payload(None, episode_case))
        )
        self.assertEqual(payload['Source'], ENIKSHAY_ID)
        self.assertEqual(payload['Local_ID'], self.person_id)
        self.assertEqual(payload['regBy'], "tbu-dmdmo01")

        # From Person
        self.assertEqual(payload['pname'], u"Peregrine เՇร ค Շгคק")
        self.assertEqual(payload['page'], '20')
        self.assertEqual(payload['pgender'], 'M')
        self.assertEqual(payload['paddress'], 'Mt. Everest')
        self.assertEqual(payload['pmob'], self.primary_phone_number)
        self.assertEqual(payload['cname'], 'Mrs. Everestie')
        self.assertEqual(payload['caddress'], 'Mrs. Everestie')
        self.assertEqual(payload['cmob'], self.secondary_phone_number)
        self.assertEqual(payload['pcategory'], '2')

        # From Episode
        self.assertEqual(payload['sitedetail'], 2)
        self.assertEqual(payload['Ptype'], '6')
        self.assertEqual(payload['poccupation'], 4)
        self.assertEqual(payload['dotname'], u'𝔊𝔞𝔫𝔡𝔞𝔩𝔣 𝔗𝔥𝔢 𝔊𝔯𝔢𝔶')
        self.assertEqual(payload['dotmob'], '066000666')
        self.assertEqual(payload['disease_classification'], 'EP')
        self.assertEqual(payload['pregdate'], '2014-09-09')
        self.assertEqual(payload['ptbyr'], '2014')
        self.assertEqual(payload['dotpType'], '5')
        self.assertEqual(payload['dotdesignation'], 'ngo_volunteer')
        self.assertEqual(payload['dateofInitiation'], '2015-03-03')
Exemple #5
0
 def test_handle_duplicate(self):
     payload_generator = NikshayRegisterPatientPayloadGenerator(None)
     payload_generator.handle_failure(
         MockResponse(
             409,
             {
                 "Nikshay_Message": "Conflict",
                 "Results": [
                     {
                         "FieldName": "NikshayId",
                         "Fieldvalue": "Dublicate Entry"
                     }
                 ]
             }
         ),
         self.cases[self.episode_id],
         None,
     )
     updated_episode_case = CaseAccessors(self.domain).get_case(self.episode_id)
     self._assert_case_property_equal(updated_episode_case, 'nikshay_registered', 'true')
     self._assert_case_property_equal(updated_episode_case, 'nikshay_error', 'duplicate')
Exemple #6
0
    def test_username_password(self):
        episode_case = self._create_nikshay_enabled_case()
        username = "******"
        password = "******"

        MockRepeater = namedtuple('MockRepeater', 'username password')
        MockRepeatRecord = namedtuple('MockRepeatRecord', 'repeater')

        repeat_record = MockRepeatRecord(MockRepeater(username=username, password=password))
        payload = (json.loads(
            NikshayRegisterPatientPayloadGenerator(None).get_payload(repeat_record, episode_case))
        )
        self.assertEqual(payload['regBy'], username)
        self.assertEqual(payload['password'], password)