Exemple #1
0
def test_send_sms_works_if_user_allows_it(smsoutbox):
    user = OnboardingInfoFactory(can_we_sms=True,
                                 user__phone_number='5551234500').user
    user.send_sms('hello there')
    assert len(smsoutbox) == 1
    assert smsoutbox[0].to == '+15551234500'
    assert smsoutbox[0].body == 'hello there'
def create_user_with_all_decl_info(hdd=None, oinfo=None):
    hdd = HardshipDeclarationDetailsFactory(**(hdd or {}))
    oi = OnboardingInfoFactory(user=hdd.user, **(oinfo or {}))
    CountyFactory()
    OnboardingInfoFactory.set_geocoded_point(oi, 0.1, 0.1)
    LandlordDetailsV2Factory(user=hdd.user)
    return hdd.user
Exemple #3
0
def test_relief_attempts_form_saves_data_to_db(db, graphql_client):
    oi = OnboardingInfoFactory()
    graphql_client.request.user = oi.user
    result = _exec_relief_attempts_form(graphql_client,
                                        {"hasCalled311": "True"})
    oi.refresh_from_db()
    assert result["errors"] == []
    assert oi.has_called_311 is True
Exemple #4
0
def test_from_user_works_with_onboarded_user():
    info = OnboardingInfoFactory(can_we_sms=True)
    fields = Fields.from_user(info.user)
    assert fields.onboarding_info__can_we_sms is True
    assert fields.onboarding_info__address_for_mailing == \
        "150 court street\nApartment 2\nBrooklyn, NY"
    assert fields.onboarding_info__lease_type == 'RENT_STABILIZED'

    info.can_we_sms = False
    info.save()
    fields = Fields.from_user(info.user)
    assert fields.onboarding_info__can_we_sms is False
def test_fill_nycha_info_works(db, loaded_nycha_csv_data):
    oinfo = OnboardingInfoFactory(pad_bbl='')
    v = hp.HPActionVariables()
    fill_nycha_info(v, oinfo.user)
    assert v.user_is_nycha_tf is None

    oinfo.pad_bbl = '1234567890'
    fill_nycha_info(v, oinfo.user)
    assert v.user_is_nycha_tf is False

    oinfo.pad_bbl = '2022150116'
    fill_nycha_info(v, oinfo.user)
    assert v.user_is_nycha_tf is True
def test_user_to_hpactionvars_populates_onboarding_info(db):
    oi = OnboardingInfoFactory.create(apt_number='2B', borough='BROOKLYN')
    v = user_to_hpactionvars(oi.user)
    assert v.tenant_address_apt_no_te == '2B'
    assert v.court_county_mc == hp.CourtCountyMC.KINGS
    assert v.court_location_mc == hp.CourtLocationMC.KINGS_COUNTY
    v.to_answer_set()
def test_csv_works(outreach_client):
    OnboardingInfoFactory()
    res = outreach_client.get('/admin/download-data/userstats.csv')
    assert res.status_code == 200
    assert res['Content-Type'] == 'text/csv'
    lines = b''.join(res.streaming_content).decode('utf-8').splitlines()
    assert len(lines) == 2
Exemple #8
0
 def test_it_triggers_followup_campaign_if_user_allows_sms(self, db):
     OnboardingInfoFactory(
         can_we_sms=True).user.trigger_followup_campaign_async("LOC")
     self.trigger.assert_called_once_with("Bip Jones",
                                          "5551234567",
                                          "LOC",
                                          locale="en")
 def test_it_does_not_send_message_twice(self):
     OnboardingInfoFactory()
     RemindBoops().remind_users()
     assert len(self.smsoutbox) == 1
     self.smsoutbox[:] = []
     RemindBoops().remind_users()
     assert len(self.smsoutbox) == 0
Exemple #10
0
def test_csv_works(outreach_client):
    OnboardingInfoFactory()
    res = outreach_client.get("/admin/download-data/userstats.csv")
    assert res.status_code == 200
    assert res["Content-Type"] == "text/csv"
    lines = b"".join(res.streaming_content).decode("utf-8").splitlines()
    assert len(lines) == 2
def test_it_works(db, django_file_storage):
    with freeze_time("2020-01-02"):
        de = DocusignEnvelopeFactory(
            status=HP_DOCUSIGN_STATUS_CHOICES.SIGNED,
            docs__kind=HP_ACTION_CHOICES.EMERGENCY,
            docs__user__email="*****@*****.**",
        )
        OnboardingInfoFactory(user=de.docs.user)
        HPActionDetailsFactory(
            user=de.docs.user,
            sue_for_harassment=True,
            sue_for_repairs=False,
        )
    with connection.cursor() as cursor:
        execute_ehpa_filings_query(cursor)
        rows = list(generate_json_rows(cursor))
        assert rows == [{
            "created_at": datetime(2020, 1, 2, tzinfo=utc),
            "first_name": "Boop",
            "last_name": "Jones",
            "borough": "BROOKLYN",
            "phone_number": "5551234567",
            "email": "*****@*****.**",
            "sue_for_harassment": True,
            "sue_for_repairs": False,
        }]
Exemple #12
0
 def test_it_raises_err_when_letter_already_sent(self):
     letter = LetterFactory(user=self.user)
     UpcomingLetterRentPeriodFactory(
         user=self.user, rent_period=letter.rent_periods.all()[0])
     OnboardingInfoFactory(user=self.user)
     assert self.execute()["errors"] == one_field_err(
         "You have already sent a letter for one of the rent periods!")
    def test_it_ignores_users_with_invalid_numbers(self):
        user = OnboardingInfoFactory().user
        r = RemindBoops()
        assert r.get_queryset().count() == 1  # type: ignore

        pl = PhoneNumberLookup(phone_number=user.phone_number, is_valid=False)
        pl.save()
        assert r.get_queryset().count() == 0  # type: ignore
def test_loc_reminder_is_not_sent_when_not_enough_time_has_passed(db, smsoutbox):
    with freeze_time("2018-01-01"):
        OnboardingInfoFactory()
    with freeze_time("2018-01-02"):
        call_command("sendreminders")

    assert len(smsoutbox) == 0
    assert Reminder.objects.count() == 0
def test_user_to_hpactionvars_populates_tiny_ll_info_from_nycdb(
        db, nycdb, use_bin):
    tiny = nycdb.load_hpd_registration('tiny-landlord.json')
    oinfo = OnboardingInfoFactory(**onboarding_info_pad_kwarg(tiny, use_bin))
    v = user_to_hpactionvars(oinfo.user)
    assert v.landlord_entity_name_te == "BOOP JONES"
    assert v.landlord_entity_or_individual_mc == hp.LandlordEntityOrIndividualMC.INDIVIDUAL
    v.to_answer_set()
Exemple #16
0
 def test_returns_empty_instance_if_lookup_fails(self, requests_mock):
     mock_lookup_failure(requests_mock)
     oi = OnboardingInfoFactory()
     info = LandlordDetails.create_lookup_for_user(oi.user)
     assert info.name == ''
     assert info.address == ''
     assert info.lookup_date is not None
     assert info.is_looked_up is False
def test_loc_reminder_is_not_sent_when_signup_intent_is_not_loc(db, smsoutbox):
    with freeze_time("2018-01-01"):
        OnboardingInfoFactory(signup_intent="HP")
    with freeze_time("2018-05-04"):
        call_command("sendreminders")

    assert len(smsoutbox) == 0
    assert Reminder.objects.count() == 0
Exemple #18
0
def test_send_sms_does_nothing_if_user_does_not_allow_it(smsoutbox):
    user = OnboardingInfoFactory(can_we_sms=False).user
    assert user.send_sms("hello there") == twilio.SendSmsResult(
        err_code=twilio.TWILIO_USER_OPTED_OUT_ERR)
    user.send_sms_async("hello there")
    user.chain_sms_async(["hello there"])
    assert len(smsoutbox) == 0
def test_loc_reminder_is_not_sent_when_loc_exists(db, smsoutbox):
    with freeze_time("2018-01-01"):
        info = OnboardingInfoFactory()
        LetterRequestFactory(user=info.user)
    with freeze_time("2018-05-04"):
        call_command("sendreminders")

    assert len(smsoutbox) == 0
    assert Reminder.objects.count() == 0
Exemple #20
0
 def test_it_updates_existing_ll_details(self, requests_mock, nycdb):
     ld = LandlordDetailsV2Factory()
     assert ld.name == "Landlordo Calrissian"
     mock_lookup_success(requests_mock, nycdb)
     OnboardingInfoFactory(user=ld.user)
     info = LandlordDetails.create_or_update_lookup_for_user(ld.user)
     assert info.pk == ld.pk
     ld.refresh_from_db()
     assert ld.name == "BOOP JONES"
Exemple #21
0
 def test_returns_filled_instance_if_lookup_succeeds(
         self, requests_mock, nycdb):
     mock_lookup_success(requests_mock, nycdb)
     oi = OnboardingInfoFactory()
     info = LandlordDetails.create_lookup_for_user(oi.user)
     assert info.name == 'BOOP JONES'
     assert info.address == "124 99TH STREET\nBrooklyn, NY 11999"
     assert info.lookup_date is not None
     assert info.is_looked_up is True
Exemple #22
0
    def setup_fixture(self, db):
        from onboarding.tests.factories import OnboardingInfoFactory
        from rapidpro.tests.factories import UserContactGroupFactory

        self.redacted = "REDACTED"
        self.pad_bbl = "1234567890"
        oi = OnboardingInfoFactory(pad_bbl=self.pad_bbl)
        UserContactGroupFactory(user=oi.user, group__uuid="1", group__name="Boop")
        UserContactGroupFactory(user=oi.user, group__uuid="2", group__name="Goop")
Exemple #23
0
 def test_it_ccs_housing_court_if_possible(self, db, django_file_storage):
     onb = OnboardingInfoFactory(borough="BRONX")
     docs = HPActionDocumentsFactory(user=onb.user)
     set_config(bronx_court_email="*****@*****.**")
     ed = docusign.create_envelope_definition_for_hpa(docs)
     assert len(ed.recipients.carbon_copies) == 2
     hc = ed.recipients.carbon_copies[1]
     assert hc.name == "Bronx Housing Court"
     assert hc.email == "*****@*****.**"
Exemple #24
0
 def test_it_ignores_ll_when_use_recommended_is_set(self, requests_mock,
                                                    nycdb):
     mock_lookup_success(requests_mock, nycdb)
     self.set_user(OnboardingInfoFactory().user)
     result = self.execute(
         input={
             "useRecommended": True,
             "landlord": [self.MISSING_ZIP_CODE_MAILING_ADDRESS],
         })
     assert result["errors"] == []
def test_it_does_nothing_in_dry_run(db, settings, requests_mock):
    settings.AMPLITUDE_API_KEY = "blop"
    OnboardingInfoFactory()
    mock = requests_mock.post(AMP_BATCH_URL)

    call_command("export_to_amplitude", "--dry-run")

    assert mock.call_count == 0
    for sync in models.Sync.objects.all():
        assert sync.last_synced_at == EPOCH
Exemple #26
0
def test_it_includes_latest_ehpa_sign_date(db, django_file_storage):
    oi = OnboardingInfoFactory()
    with freeze_time("2020-08-21"):
        DocusignEnvelopeFactory(status="SIGNED", docs__user=oi.user)
    with connection.cursor() as cur:
        execute_user_stats_query(cur)
        result = list(generate_json_rows(cur))
        assert len(result) == 1
        assert result[0]["latest_signed_ehpa_date"].date().isoformat(
        ) == "2020-08-21"
Exemple #27
0
    def test_it_shows_discontinued_message(self, use_evictionfree_site,
                                           settings):
        settings.IS_EFNY_SUSPENDED = True
        self.create_landlord_details()
        OnboardingInfoFactory(user=self.user)
        HardshipDeclarationDetailsFactory(user=self.user)

        with freezegun.freeze_time("2021-01-26"):
            assert self.execute()["errors"] == one_field_err(
                "This tool has been suspended! Please reload the page for more details."
            )
Exemple #28
0
def test_json_works(outreach_client):
    user = OnboardingInfoFactory().user
    UserContactGroupFactory(user=user, group__uuid="1", group__name="Boop")
    UserContactGroupFactory(user=user, group__uuid="2", group__name="Goop")

    res = outreach_client.get("/admin/download-data/userstats.json")
    assert res.status_code == 200
    assert res["Content-Type"] == "application/json"
    records = json.loads(b"".join(res.streaming_content).decode("utf-8"))
    assert len(records) == 1
    assert records[0]["user_id"] == user.pk
    assert records[0]["rapidpro_contact_groups"] == ["Boop", "Goop"]
def test_json_works(outreach_client):
    user = OnboardingInfoFactory().user
    UserContactGroupFactory(user=user, group__uuid='1', group__name='Boop')
    UserContactGroupFactory(user=user, group__uuid='2', group__name='Goop')

    res = outreach_client.get('/admin/download-data/userstats.json')
    assert res.status_code == 200
    assert res['Content-Type'] == 'application/json'
    records = json.loads(b''.join(res.streaming_content).decode('utf-8'))
    assert len(records) == 1
    assert records[0]['user_id'] == user.pk
    assert records[0]['rapidpro_contact_groups'] == ['Boop', 'Goop']
Exemple #30
0
    def test_it_works(
        self,
        allow_lambda_http,
        use_norent_site,
        requests_mock,
        mailoutbox,
        smsoutbox,
        settings,
        mocklob,
    ):
        settings.IS_DEMO_DEPLOYMENT = False
        settings.LANGUAGES = project.locales.ALL.choices
        UpcomingLetterRentPeriodFactory(user=self.user)
        self.user.locale = "es"
        self.user.save()
        self.create_landlord_details()
        OnboardingInfoFactory(user=self.user)
        assert self.execute()["errors"] == []

        assert UpcomingLetterRentPeriod.objects.get_for_user(self.user) == []
        letter = Letter.objects.get(user=self.graphql_client.request.user)
        assert len(letter.rent_periods.all()) == 1
        assert str(letter.latest_rent_period.payment_date) == "2020-05-01"
        assert letter.locale == "es"
        assert "unable to pay rent" in letter.html_content
        assert "Boop Jones" in letter.html_content
        assert 'lang="en"' in letter.html_content
        assert 'lang="es"' in letter.localized_html_content
        assert letter.letter_sent_at is not None
        assert letter.tracking_number == mocklob.sample_letter[
            "tracking_number"]
        assert letter.fully_processed_at is not None

        assert len(mailoutbox) == 2
        ll_mail = mailoutbox[0]
        assert ll_mail.to == ["*****@*****.**"]
        assert "letter attached" in ll_mail.body
        assert "Boop Jones" in ll_mail.body
        assert "sent on behalf" in ll_mail.subject
        assert len(ll_mail.attachments) == 1
        assert letter.letter_emailed_at is not None

        user_mail = mailoutbox[1]
        assert user_mail.to == ["*****@*****.**"]
        assert "https://example.com/es/faqs" in user_mail.body
        assert "Hola Boop" in user_mail.body
        assert "Tu carta de NoRent y pasos siguientes importantes" in user_mail.subject

        assert len(smsoutbox) == 1
        assert "Boop Jones" in smsoutbox[0].body
        assert "USPS" in smsoutbox[0].body

        assert len(user_mail.attachments) == 1