예제 #1
0
    def test_ziggy_submission_post_update(self):
        num_ziggys = ZiggyInstance.objects.count()
        response = self.make_ziggy_submission(village_profile_json_path)
        self.assertEqual(response.status_code, 201)
        self.assertEqual(ZiggyInstance.objects.count(), num_ziggys + 1)

        # make update submission
        response = self.make_ziggy_submission(cc_monthly_json_path)
        self.assertEqual(response.status_code, 201)
        self.assertEqual(ZiggyInstance.objects.count(), num_ziggys + 2)

        # check that we only end up with a single updated object within mongo
        entities = [r for r in mongo_ziggys.find({'_id': ENTITY_ID})]
        self.assertEqual(len(entities), 1)

        # check that the sagContactNumber field exists and is unmodified
        entity = entities[0]
        matching_fields = filter(
            ZiggyInstance.field_by_name_exists('sagContactNumber'),
            json.loads(entity['formInstance'])['form']['fields'])
        self.assertEqual(len(matching_fields), 1)
        self.assertEqual(matching_fields[0]['value'], '020-123456')

        # todo: check that the new data has been added
        matching_fields = filter(
            ZiggyInstance.field_by_name_exists('reportingMonth'),
            json.loads(entity['formInstance'])['form']['fields'])
        self.assertEqual(len(matching_fields), 1)
        self.assertEqual(matching_fields[0]['value'], '10-2013')
예제 #2
0
 def test_ziggy_to_formhub_instance(self):
     with open(cc_monthly_json_path) as f:
         json_post = json.load(f)
     ziggy_json = json_post[0]
     zi = ZiggyInstance.create_ziggy_instance(self.user, ziggy_json,
                                              self.user)
     formhub_dict = ziggy_to_formhub_instance(zi)
     expected_formhub_dict = {
         'village_name': 'dygvbh',
         'village_code': 'fjhgh',
         'gps': '',
         'reporting_month': '10-2013',
         'households': '12',
         'village_population': '2',
         'improved_latrines': '5',
         'latrines_smooth_cleanable_floor': '45',
         'latrines_with_lid': '12',
         'latrines_with_superstructure': '8',
         'latrines_signs_of_use': '5',
         'latrines_hand_washers': '12',
         'latrines_all_improved_reqs': '',
         'households_quality_checked': '4',
         'checks_accurate': '9',
         'today': '2013-08-23',
         '_userform_id': 'bob_cc_monthly_report_form'
     }
     self.assertDictEqual(formhub_dict, expected_formhub_dict)
예제 #3
0
 def test_rest_service_ziggy_submission(self):
     with open(cc_monthly_json_path) as f:
         json_post = json.load(f)
     ziggy_json = json_post[0]
     zi = ZiggyInstance.create_ziggy_instance(self.user, ziggy_json,
                                              self.user)
     # check that the HTTP request was made
     with HTTMock(f2dhis_mock):
         services_called = rest_service_ziggy_submission(
             ZiggyInstance, zi, False, True, False)
         # make sure a service was called
         self.assertEqual(services_called, 1)
예제 #4
0
    def test_merge_ziggy_form_instances(self):
        instance_1 = [
            {'name': 'village_name', 'value': 'Ugenya'},
            {'name': 'village_code', 'value': '012-123'},
            {'name': 'village_contact_no', 'value': '050 123456'}]

        instance_2 = [
            {'name': 'village_name', 'value': 'Uriya'},
            {'name': 'village_contact_no', 'value': '050 876543'},
            {'name': 'num_latrines', 'value': 23}]

        merged_instance = ZiggyInstance.merge_ziggy_form_instances(
            instance_1, instance_2)
        expected_merged_instance = [
            # named changed to Uriya
            {'name': 'village_name', 'value': 'Uriya'},
            # village code un-touched
            {'name': 'village_code', 'value': '012-123'},
            # contact no  updated
            {'name': 'village_contact_no', 'value': '050 876543'},
            # num latrines is a new field
            {'name': 'num_latrines', 'value': 23}]

        self.assertEqual(
            filter(ZiggyInstance.field_by_name_exists(
                'village_name'), merged_instance)[0],
            filter(ZiggyInstance.field_by_name_exists(
                'village_name'), expected_merged_instance)[0])
        self.assertEqual(
            filter(ZiggyInstance.field_by_name_exists(
                'village_code'), merged_instance)[0],
            filter(ZiggyInstance.field_by_name_exists(
                'village_code'), expected_merged_instance)[0])
        self.assertEqual(
            filter(ZiggyInstance.field_by_name_exists(
                'village_contact_no'), merged_instance)[0],
            filter(ZiggyInstance.field_by_name_exists(
                'village_contact_no'), expected_merged_instance)[0])
        self.assertEqual(
            filter(ZiggyInstance.field_by_name_exists(
                'num_latrines'), merged_instance)[0],
            filter(ZiggyInstance.field_by_name_exists(
                'num_latrines'), expected_merged_instance)[0])