Пример #1
0
    def test_case_fields(self):

        expected_fields = [
            {"help_text": "", "key": "properties__level", "label": "Level", "type": "unicode"},
            {"help_text": "", "key": "properties__mood", "label": "Mood", "type": "unicode"},
            {"help_text": "", "key": "properties__move_type", "label": "Move type", "type": "unicode"},
            {"help_text": "", "key": "properties__name", "label": "Name", "type": "unicode"},
            {"help_text": "", "key": "properties__opened_on", "label": "Opened on", "type": "unicode"},
            {"help_text": "", "key": "properties__owner_id", "label": "Owner id", "type": "unicode"},
            {"help_text": "", "key": "properties__prop1", "label": "Prop1", "type": "unicode"},
            {"help_text": "", "key": "properties__type", "label": "Type", "type": "unicode"},
            {"help_text": "", "key": "date_closed", "label": "Date closed", "type": "unicode"},
            {"help_text": "", "key": "xform_ids", "label": "XForm IDs", "type": "unicode"},
            {"help_text": "", "key": "properties__date_opened", "label": "Date opened", "type": "unicode"},
            {"help_text": "", "key": "properties__external_id", "label": "External ID", "type": "unicode"},
            {"help_text": "", "key": "properties__case_name", "label": "Case name", "type": "unicode"},
            {"help_text": "", "key": "properties__case_type", "label": "Case type", "type": "unicode"},
            {"help_text": "", "key": "user_id", "label": "User ID", "type": "unicode"},
            {"help_text": "", "key": "date_modified", "label": "Date modified", "type": "unicode"},
            {"help_text": "", "key": "case_id", "label": "Case ID", "type": "unicode"},
            {"help_text": "", "key": "properties__owner_id", "label": "Owner ID", "type": "unicode"},
            {"help_text": "", "key": "resource_uri", "label": "Resource URI", "type": "unicode"}
        ]

        request = Client().get(self.test_url).wsgi_request
        bundle = Resource().build_bundle(data={}, request=request)

        factory = CaseFactory(domain="joto")
        factory.create_case(
            case_type='teddiursa',
            owner_id='owner1',
            case_name='dre',
            update={'prop1': 'blah', 'move_type': 'scratch', 'mood': 'happy', 'level': '100'}
        )

        actual_fields = ZapierCustomFieldCaseResource().obj_get_list(bundle)
        for i in range(len(actual_fields)):
            self.assertEqual(expected_fields[i], actual_fields[i].get_content())
Пример #2
0
    ZapierCustomFieldCaseResource,
    ZapierCustomTriggerFieldFormResource,
    ZapierXFormInstanceResource,
)
from corehq.apps.zapier.views import (
    SubscribeView,
    UnsubscribeView,
    ZapierCreateCase,
    ZapierUpdateCase,
)

hq_api = CommCareHqApi(api_name='v0.5')
hq_api.register(ZapierXFormInstanceResource())
hq_api.register(ZapierCustomTriggerFieldFormResource())
hq_api.register(ZapierCustomActionFieldCaseResource())
hq_api.register(ZapierCustomFieldCaseResource())
hq_api.register(ZapierApplicationResource())

urlpatterns = [
    url(r'^subscribe/$', SubscribeView.as_view(), name=SubscribeView.urlname),
    url(r'^unsubscribe/$',
        UnsubscribeView.as_view(),
        name=UnsubscribeView.urlname),
    url(r'^create_case/$',
        ZapierCreateCase.as_view(),
        name=ZapierCreateCase.urlname),
    url(r'^update_case/$',
        ZapierUpdateCase.as_view(),
        name=ZapierUpdateCase.urlname),
    url(r'^api/', include(hq_api.urls)),
]
Пример #3
0
    def test_case_fields(self):

        expected_fields = [{
            "help_text": "",
            "key": "properties__level",
            "label": "Level",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__mood",
            "label": "Mood",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__move_type",
            "label": "Move type",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__name",
            "label": "Name",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__prop1",
            "label": "Prop1",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__type",
            "label": "Type",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "date_closed",
            "label": "Date closed",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "xform_ids",
            "label": "XForm IDs",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__date_opened",
            "label": "Date opened",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__external_id",
            "label": "External ID",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__case_name",
            "label": "Case name",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__case_type",
            "label": "Case type",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "user_id",
            "label": "User ID",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "date_modified",
            "label": "Date modified",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "case_id",
            "label": "Case ID",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "properties__owner_id",
            "label": "Owner ID",
            "type": "unicode"
        }, {
            "help_text": "",
            "key": "resource_uri",
            "label": "Resource URI",
            "type": "unicode"
        }]

        request = Client().get(self.test_url).wsgi_request
        bundle = Resource().build_bundle(data={}, request=request)

        actual_fields = [
            field.get_content()
            for field in ZapierCustomFieldCaseResource().obj_get_list(bundle)
        ]
        self.assertItemsEqual(expected_fields, actual_fields)