コード例 #1
0
 def test_it_triggers_if_rapidpro_and_campaign_are_configured(
         self, settings, tasks_trigger):
     settings.RAPIDPRO_FOLLOWUP_CAMPAIGN_RH = "Boop Group,date_of_boop"
     settings.RAPIDPRO_API_TOKEN = "blorp"
     trigger_followup_campaign_async("Boop Jones", "5551234567", "RH", "en")
     tasks_trigger.delay.assert_called_once_with("Boop Jones", "5551234567",
                                                 "RH", "en")
コード例 #2
0
    def perform_mutate(cls, form, info):
        request = info.context
        form_data = RhFormInfo.get_dict_from_request(request)
        if form_data is None:
            cls.log(info, "User has not completed the rental history form, aborting mutation.")
            return cls.make_error("You haven't completed all the previous steps yet.")

        rhr = models.RentalHistoryRequest(**form_data)
        rhr.set_user(request.user)
        rhr.full_clean()
        rhr.save()
        slack.sendmsg_async(get_slack_notify_text(rhr), is_safe=True)

        first_name: str = form_data["first_name"]
        last_name: str = form_data["last_name"]
        email_dhcr.send_email_to_dhcr(
            first_name,
            last_name,
            form_data["address"],
            BOROUGH_CHOICES.get_label(form_data["borough"]),
            form_data["zipcode"],
            form_data["apartment_number"]
        )
        trigger_followup_campaign_async(
            f"{first_name} {last_name}",
            form_data["phone_number"],
            "RH"
        )
        RhFormInfo.clear_from_request(request)
        return cls.mutation_success()
コード例 #3
0
 def test_it_triggers_if_rapidpro_and_campaign_are_configured(
         self, settings, tasks_trigger):
     settings.RAPIDPRO_FOLLOWUP_CAMPAIGN_RH = 'Boop Group,date_of_boop'
     settings.RAPIDPRO_API_TOKEN = 'blorp'
     trigger_followup_campaign_async('Boop Jones', '5551234567', 'RH')
     tasks_trigger.delay.assert_called_once_with('Boop Jones', '5551234567',
                                                 'RH')
コード例 #4
0
 def test_task_works(self, settings, monkeypatch):
     settings.RAPIDPRO_FOLLOWUP_CAMPAIGN_RH = 'Boop Group,date_of_boop'
     settings.RAPIDPRO_API_TOKEN = 'blorp'
     dsfc = MagicMock()
     campaign = MagicMock()
     dsfc.get_campaign.return_value = campaign
     monkeypatch.setattr(tasks, 'DjangoSettingsFollowupCampaigns', dsfc)
     trigger_followup_campaign_async('Boop Jones', '5551234567', 'RH')
     dsfc.get_campaign.assert_called_once_with('RH')
     campaign.add_contact.assert_called_once()
     assert campaign.add_contact.call_args.args[1:] == ('Boop Jones',
                                                        '5551234567')
コード例 #5
0
 def test_task_works(self, settings, monkeypatch):
     settings.RAPIDPRO_FOLLOWUP_CAMPAIGN_RH = "Boop Group,date_of_boop"
     settings.RAPIDPRO_API_TOKEN = "blorp"
     dsfc = MagicMock()
     campaign = MagicMock()
     dsfc.get_campaign.return_value = campaign
     monkeypatch.setattr(tasks, "DjangoSettingsFollowupCampaigns", dsfc)
     trigger_followup_campaign_async("Boop Jones", "5551234567", "RH", "en")
     dsfc.get_campaign.assert_called_once_with("RH")
     campaign.add_contact.assert_called_once()
     assert campaign.add_contact.call_args.args[1:] == ("Boop Jones",
                                                        "5551234567")
     assert campaign.add_contact.call_args.kwargs == {"locale": "en"}
コード例 #6
0
    def perform_mutate(cls, form, info):
        request = info.context
        scf = get_scaffolding(request)
        if not scaffolding_has_rental_history_request_info(scf):
            cls.log(
                info,
                "User has not completed the rental history form, aborting mutation."
            )
            return cls.make_error(
                "You haven't completed all the previous steps yet.")

        rhr = models.RentalHistoryRequest(
            first_name=scf.first_name,
            last_name=scf.last_name,
            apartment_number=scf.apt_number,
            phone_number=scf.phone_number,
            address=scf.street,
            address_verified=scf.address_verified,
            borough=scf.borough,
            zipcode=scf.zip_code,
        )
        rhr.set_user(request.user)
        rhr.full_clean()
        rhr.save()
        slack.sendmsg_async(get_slack_notify_text(rhr), is_safe=True)

        email = react_render_email(
            SITE_CHOICES.JUSTFIX,
            project.locales.DEFAULT,
            "rh/email-to-dhcr.txt",
            session=request.session,
        )
        email_dhcr.send_email_to_dhcr(email.subject, email.body)
        trigger_followup_campaign_async(
            f"{scf.first_name} {scf.last_name}",
            scf.phone_number,
            "RH",
            locale=translation.get_language_from_request(request,
                                                         check_path=True),
        )

        # Note that we used to purge the scaffolding information here, but lots
        # of users go on to create an account after this, and we don't want them
        # to have to re-enter all their information, so we'll keep it around.

        return cls.mutation_success()
コード例 #7
0
    def trigger_followup_campaign_async(self, campaign_name: str) -> None:
        from rapidpro import followup_campaigns as fc

        fc.ensure_followup_campaign_exists(campaign_name)

        if self.can_we_sms:
            logging.info(f"Triggering rapidpro campaign '{campaign_name}' on user "
                         f"{self.username}.")
            fc.trigger_followup_campaign_async(
                self.full_name,
                self.phone_number,
                campaign_name
            )
        else:
            logging.info(
                f"Not triggering rapidpro campaign '{campaign_name}' on user "
                f"{self.username} because they opted out."
            )
コード例 #8
0
ファイル: models.py プロジェクト: JustFixNYC/tenants2
    def trigger_followup_campaign_async(self, campaign_name: str) -> None:
        from rapidpro import followup_campaigns as fc

        fc.ensure_followup_campaign_exists(campaign_name)

        if self.can_we_sms:
            logging.info(
                f"Triggering rapidpro campaign '{campaign_name}' on user "
                f"{self.username}.")
            fc.trigger_followup_campaign_async(
                self.
                full_preferred_name,  # Use the user's preferred name when we text them.
                self.phone_number,
                campaign_name,
                locale=self.locale,
            )
        else:
            logging.info(
                f"Not triggering rapidpro campaign '{campaign_name}' on user "
                f"{self.username} because they opted out.")
コード例 #9
0
    def test_task_retries_on_api_errors(self, settings, monkeypatch):
        settings.RAPIDPRO_FOLLOWUP_CAMPAIGN_RH = "Boop Group,date_of_boop"
        settings.RAPIDPRO_API_TOKEN = "blorp"
        dsfc = MagicMock()
        campaign = MagicMock()
        dsfc.get_campaign.return_value = campaign
        campaign.add_contact.side_effect = TembaHttpError("blah")
        retry = MagicMock()

        def fake_retry(exc):
            assert isinstance(exc, TembaHttpError)
            raise Retry()

        retry.side_effect = fake_retry
        monkeypatch.setattr(tasks.trigger_followup_campaign, "retry", retry)
        monkeypatch.setattr(tasks, "DjangoSettingsFollowupCampaigns", dsfc)
        with pytest.raises(Retry):
            trigger_followup_campaign_async("Boop Jones", "5551234567", "RH",
                                            "en")
        dsfc.get_campaign.assert_called_once_with("RH")
        campaign.add_contact.assert_called_once()
コード例 #10
0
 def test_it_does_nothing_if_campaign_is_unconfigured(
         self, settings, tasks_trigger):
     settings.RAPIDPRO_API_TOKEN = "blorp"
     trigger_followup_campaign_async("Boop", "5551234567", "RH", "en")
     tasks_trigger.assert_not_called()
コード例 #11
0
 def test_it_does_nothing_if_rapidpro_is_unconfigured(
         self, settings, tasks_trigger):
     settings.RAPIDPRO_FOLLOWUP_CAMPAIGN_RH = "Boop Group,date_of_boop"
     trigger_followup_campaign_async("Boop", "5551234567", "RH", "en")
     tasks_trigger.assert_not_called()
コード例 #12
0
 def test_it_does_nothing_if_campaign_is_unconfigured(
         self, settings, tasks_trigger):
     settings.RAPIDPRO_API_TOKEN = 'blorp'
     trigger_followup_campaign_async('Boop', '5551234567', 'RH')
     tasks_trigger.assert_not_called()