Example #1
0
    def create(cls,
               org,
               user,
               courier_url,
               callback,
               country="EC",
               scheme="tel",
               address="123456",
               port=49999):
        server = cls.Server(port)

        config = {
            Channel.CONFIG_SEND_URL: f"{server.base_url}/send",
            Channel.CONFIG_SEND_METHOD: "POST",
            Channel.CONFIG_CONTENT_TYPE: "application/json",
            Channel.CONFIG_SEND_BODY: '{"text": "{{text}}"}',
        }

        db_channel = Channel.add_config_external_channel(org,
                                                         user,
                                                         country,
                                                         address,
                                                         "EX",
                                                         config,
                                                         "SR", [scheme],
                                                         name="Test Channel")

        return cls(db_channel, server, courier_url, callback)
Example #2
0
    def test_channel(self):
        channel = Channel.add_config_external_channel(self.org, self.admin,
                                                      "US", "+12061111111",
                                                      "KN", {})

        action = SetChannelAction(str(uuid4()), channel)
        action = self._serialize_deserialize(action)

        self.assertEqual(channel, action.channel)
Example #3
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org, self.request.user, data["country"], data["number"], "CT",
            {Channel.CONFIG_API_KEY: data["api_key"]})

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #4
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org, self.request.user, data["country"], data["number"], "CT", {Channel.CONFIG_API_KEY: data["api_key"]}
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #5
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org,
            self.request.user,
            "SO",
            data["number"],
            self.channel_type,
            dict(send_url=data["url"], username=data["username"], password=data["password"]),
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #6
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org, self.request.user, data['country'], data['number'], 'CT',
            dict(api_id=data['api_id'],
                 username=data['username'],
                 password=data['password']))

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #7
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org,
            self.request.user,
            data["country"],
            data["number"],
            self.channel_type,
            {Channel.CONFIG_API_KEY: data["api_key"]},
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #8
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org,
            self.request.user,
            "SO",
            data["number"],
            "SQ",
            dict(send_url=data["url"], username=data["username"], password=data["password"]),
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #9
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org,
            self.request.user,
            "SO",
            data["number"],
            "SQ",
            dict(send_url=data["url"], username=data["username"], password=data["password"]),
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #10
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org,
            self.request.user,
            "PH",
            data["number"],
            self.channel_type,
            dict(app_id=data["app_id"],
                 app_secret=data["app_secret"],
                 passphrase=data["passphrase"]),
            role=Channel.ROLE_SEND + Channel.ROLE_RECEIVE,
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #11
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org,
            self.request.user,
            "PH",
            data["number"],
            "GL",
            dict(app_id=data["app_id"], app_secret=data["app_secret"], passphrase=data["passphrase"]),
            role=Channel.ROLE_SEND + Channel.ROLE_RECEIVE,
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #12
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        self.object = Channel.add_config_external_channel(
            org,
            self.request.user,
            "PH",
            data["number"],
            "GL",
            dict(app_id=data["app_id"], app_secret=data["app_secret"], passphrase=data["passphrase"]),
            role=Channel.ROLE_SEND + Channel.ROLE_RECEIVE,
        )

        return super(AuthenticatedExternalClaimView, self).form_valid(form)
Example #13
0
    def test_ussd_trigger(self, get_ussd_channels):
        self.login(self.admin)

        flow = self.get_flow('ussd_example')

        # check if we have ussd section
        get_ussd_channels.return_value = True
        response = self.client.get(reverse('triggers.trigger_create'))

        self.assertTrue(get_ussd_channels.called)
        self.assertContains(response, 'USSD mobile initiated flow')

        channel = Channel.add_config_external_channel(self.org, self.user,
                                                      "HU", 1234, Channel.TYPE_VUMI_USSD,
                                                      dict(account_key="11111",
                                                           access_token=str(uuid4()),
                                                           transport_name="ussd_transport",
                                                           conversation_key="22222"))

        # flow options should show ussd flow example
        response = self.client.get(reverse("triggers.trigger_ussd"))
        self.assertContains(response, flow.name)

        # try a ussd code with letters instead of numbers
        post_data = dict(channel=channel.pk, keyword='*keyword#', flow=flow.pk)
        response = self.client.post(reverse("triggers.trigger_ussd"), data=post_data)
        self.assertEquals(1, len(response.context['form'].errors))
        self.assertTrue("keyword" in response.context['form'].errors)
        self.assertEquals(response.context['form'].errors['keyword'], [u'USSD code must contain only *,# and numbers'])

        # try a proper ussd code
        post_data = dict(channel=channel.pk, keyword='*111#', flow=flow.pk)
        response = self.client.post(reverse("triggers.trigger_ussd"), data=post_data)
        self.assertEquals(0, len(response.context['form'].errors))
        trigger = Trigger.objects.get(keyword='*111#')
        self.assertEquals(flow.pk, trigger.flow.pk)

        # try a duplicate ussd code
        post_data = dict(channel=channel.pk, keyword='*111#', flow=flow.pk)
        response = self.client.post(reverse("triggers.trigger_ussd"), data=post_data)
        self.assertEquals(2, len(response.context['form'].errors))
        self.assertEquals(response.context['form'].errors['keyword'],
                          [u'Another active trigger uses this code, code must be unique'])
Example #14
0
    def form_valid(self, form):
        user = self.request.user
        data = form.cleaned_data
        org = user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        # Upload icons and get urls
        main_icon_url = upload_icon_to_aws(self.request.FILES.get(MAIN_ICON))
        chat_icon_url = upload_icon_to_aws(self.request.FILES.get(CHAT_ICON))

        # Get a config for Channel and Save on Model
        config = create_config(main_icon_url=main_icon_url,
                               chat_icon_url=chat_icon_url,
                               data=data)

        # Define a channel
        channel = self.request.GET.get("channel", None)
        if channel:  # pragma: needs cover
            # make sure they own it
            channel = self.request.user.get_org().channels.filter(
                pk=channel).first()

        # Define a role
        role = Channel.ROLE_SEND + Channel.ROLE_RECEIVE

        # Configure a External Channel
        self.object = Channel.add_config_external_channel(
            org=org,
            user=self.request.user,
            country=None,
            address=data[CHANNEL_NAME],
            channel_type=self.channel_type,
            config=config,
            role=role,
            schemes=[EXTERNAL_SCHEME],
            parent=channel,
        )

        return super(PushinhoView, self).form_valid(form)
Example #15
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        if not org:  # pragma: no cover
            raise Exception(_("No org for this user, cannot claim"))

        data = form.cleaned_data
        if not data.get('api_url'):
            api_url = Channel.VUMI_GO_API_URL
        else:
            api_url = data.get('api_url')

        self.object = Channel.add_config_external_channel(org, self.request.user,
                                                          data['country'], data['number'], 'VMU',
                                                          dict(account_key=data['account_key'],
                                                               access_token=str(uuid4()),
                                                               conversation_key=data['conversation_key'],
                                                               api_url=api_url),
                                                          role=Channel.ROLE_USSD)

        return super(AuthenticatedExternalClaimView, self).form_valid(form)