예제 #1
0
 def test_delete(self):
     data_item = self._create_data_item(cleanup=False)
     self.assertEqual(1, len(FixtureDataItem.by_domain(self.domain.name)))
     response = self._assert_auth_post_resource(self.single_endpoint(
         data_item._id),
                                                '',
                                                method='DELETE')
     self.assertEqual(response.status_code, 204, response.content)
     self.assertEqual(0, len(FixtureDataItem.by_domain(self.domain.name)))
예제 #2
0
    def obj_get_list(self, bundle, **kwargs):
        domain = kwargs['domain']
        parent_id = bundle.request.GET.get("parent_id", None)
        parent_ref_name = bundle.request.GET.get("parent_ref_name", None)
        references = bundle.request.GET.get("references", None)
        child_type = bundle.request.GET.get("child_type", None)
        type_id = bundle.request.GET.get("fixture_type_id", None)
        type_tag = bundle.request.GET.get("fixture_type", None)

        if parent_id and parent_ref_name and child_type and references:
            parent_fdi = FixtureDataItem.get(parent_id)
            fdis = list(FixtureDataItem.by_field_value(domain, child_type, parent_ref_name, parent_fdi.fields_without_attributes[references]))
        elif type_id or type_tag:
            type_id = type_id or FixtureDataType.by_domain_tag(domain, type_tag).one()
            fdis = list(FixtureDataItem.by_data_type(domain, type_id))
        else:
            fdis = list(FixtureDataItem.by_domain(domain))

        return [convert_fdt(fdi) for fdi in fdis] or []
예제 #3
0
    def test_create(self):
        data_item_json = {
            "data_type_id": self.data_type._id,
            "fields": {
                "state_name": {
                    "field_list": [
                        {"field_value": "Massachusetts", "properties": {"lang": "en"}},
                        {"field_value": "马萨诸塞", "properties": {"lang": "zh"}},
                    ]
                }
            },
        }

        response = self._assert_auth_post_resource(
            self.list_endpoint, json.dumps(data_item_json), content_type='application/json')
        self.assertEqual(response.status_code, 201)
        data_item = FixtureDataItem.by_domain(self.domain.name).first()
        self.addCleanup(data_item.delete)
        self.assertEqual(data_item.data_type_id, self.data_type._id)
        self.assertEqual(len(data_item.fields), 1)
        self.assertEqual(data_item.fields['state_name'].field_list[0].field_value, 'Massachusetts')
        self.assertEqual(data_item.fields['state_name'].field_list[0].properties, {"lang": "en"})
예제 #4
0
    def test_create(self):
        data_item_json = {
            "data_type_id": self.data_type._id,
            "fields": {
                "state_name": {
                    "field_list": [
                        {
                            "field_value": "Massachusetts",
                            "properties": {
                                "lang": "en"
                            }
                        },
                        {
                            "field_value": "马萨诸塞",
                            "properties": {
                                "lang": "zh"
                            }
                        },
                    ]
                }
            },
        }

        response = self._assert_auth_post_resource(
            self.list_endpoint,
            json.dumps(data_item_json),
            content_type='application/json')
        self.assertEqual(response.status_code, 201)
        data_item = FixtureDataItem.by_domain(self.domain.name).first()
        self.addCleanup(data_item.delete)
        self.assertEqual(data_item.data_type_id, self.data_type._id)
        self.assertEqual(len(data_item.fields), 1)
        self.assertEqual(
            data_item.fields['state_name'].field_list[0].field_value,
            'Massachusetts')
        self.assertEqual(
            data_item.fields['state_name'].field_list[0].properties,
            {"lang": "en"})
예제 #5
0
    def obj_get_list(self, bundle, **kwargs):
        domain = kwargs['domain']
        parent_id = bundle.request.GET.get("parent_id", None)
        parent_ref_name = bundle.request.GET.get("parent_ref_name", None)
        references = bundle.request.GET.get("references", None)
        child_type = bundle.request.GET.get("child_type", None)
        type_id = bundle.request.GET.get("fixture_type_id", None)
        type_tag = bundle.request.GET.get("fixture_type", None)

        if parent_id and parent_ref_name and child_type and references:
            parent_fdi = FixtureDataItem.get(parent_id)
            fdis = list(
                FixtureDataItem.by_field_value(
                    domain, child_type, parent_ref_name,
                    parent_fdi.fields_without_attributes[references]))
        elif type_id or type_tag:
            type_id = type_id or FixtureDataType.by_domain_tag(
                domain, type_tag).one()
            fdis = list(FixtureDataItem.by_data_type(domain, type_id))
        else:
            fdis = list(FixtureDataItem.by_domain(domain))

        return [convert_fdt(fdi) for fdi in fdis] or []
예제 #6
0
 def obj_get_list(self, bundle, domain, **kwargs):
     return list(FixtureDataItem.by_domain(domain))
예제 #7
0
파일: v0_1.py 프로젝트: dimagi/commcare-hq
 def obj_get_list(self, bundle, domain, **kwargs):
     return list(FixtureDataItem.by_domain(domain))
예제 #8
0
 def test_delete(self):
     data_item = self._create_data_item(cleanup=False)
     self.assertEqual(1, len(FixtureDataItem.by_domain(self.domain.name)))
     response = self._assert_auth_post_resource(self.single_endpoint(data_item._id), '', method='DELETE')
     self.assertEqual(response.status_code, 204, response.content)
     self.assertEqual(0, len(FixtureDataItem.by_domain(self.domain.name)))