Example #1
0
def test_borough_label_works():
    info = OnboardingInfo()
    assert info.borough_label == ''

    info.borough = 'STATEN_ISLAND'
    assert info.borough_label == 'Staten Island'

    info.borough = 'MANHATTAN'
    assert info.borough_label == 'Manhattan'
Example #2
0
def test_borough_label_works():
    info = OnboardingInfo()
    assert info.borough_label == ""

    info.borough = "STATEN_ISLAND"
    assert info.borough_label == "Staten Island"

    info.borough = "MANHATTAN"
    assert info.borough_label == "Manhattan"
Example #3
0
def test_full_address_works():
    info = OnboardingInfo()
    assert info.full_address == ''

    info.borough = 'STATEN_ISLAND'
    assert info.full_address == ''

    info.address = '123 Boop street'
    assert info.full_address == '123 Boop street, Staten Island'
Example #4
0
def test_city_works():
    info = OnboardingInfo()
    assert info.city == ''

    info.borough = 'STATEN_ISLAND'
    assert info.city == 'Staten Island'

    info.borough = 'MANHATTAN'
    assert info.city == 'New York'
Example #5
0
def test_full_nyc_address_works():
    info = OnboardingInfo()
    assert info.full_nyc_address == ""

    info.borough = "STATEN_ISLAND"
    assert info.full_nyc_address == ""

    info.address = "123 Boop street"
    assert info.full_nyc_address == "123 Boop street, Staten Island"
Example #6
0
def test_blank_fields_work(db):
    user = UserFactory()
    oi = OnboardingInfo(
        user=user,
        signup_intent="LOC",
        address="123 Boop Ave.",
        state="NY",
        can_we_sms=False,
    )
    oi.full_clean()
Example #7
0
 def mkinfo(self, **kwargs):
     return OnboardingInfo(
         address="200 N Spring St",
         non_nyc_city="Los Angeles",
         state="CA",
         zipcode="90012",
         **kwargs,
     )
Example #8
0
    def verify(self, info: OnboardingInfo) -> int:
        assert not info.geocoded_address

        kind = get_kind(info)
        self.log(
            f"Verifying {kind} address for {info.user} (last login @ {info.user.last_login})."
        )
        self.log(f"User admin link: {info.user.admin_url}")

        assert (
            info.maybe_lookup_new_addr_metadata()
        ), "Looking up address metadata should be triggered when no geocoded address exists!"

        self.convert_national_to_nyc_addr_if_needed(info)
        addr = get_addr(info)

        if not info.geocoded_address:
            self.log(
                f"Unable to geocode address for '{addr}'. The geocoding service may be down "
                f"or no addresses matched.")
            return 0

        expected = get_expected_geocoded_addr(info)
        actual = strip_suffix(info.geocoded_address)
        actual_kind = get_kind(info)
        save = False

        if expected.lower() == actual.lower():
            self.log(
                f"Geocoded address '{actual}' exactly matches user address.")
            save = True
        else:
            self.print_with_label(f"User entered {kind} address", expected)
            self.print_with_label(f"Geocoded {actual_kind} address", actual)

            if self.confirm():
                save = True

        if save:
            self.log("Updating database.")
            info.save()
            return 1

        return 0
Example #9
0
def test_city_works():
    info = OnboardingInfo()
    assert info.city == ""

    info.non_nyc_city = "Beetville"
    assert info.city == "Beetville"

    info.non_nyc_city = ""
    info.borough = "STATEN_ISLAND"
    assert info.city == "Staten Island"

    info.borough = "MANHATTAN"
    assert info.city == "New York"
Example #10
0
def test_save_sets_geographic_metadata(db, requests_mock, settings):
    requests_mock.get(settings.GEOCODING_SEARCH_URL, json=EXAMPLE_SEARCH)
    user = UserFactory()
    oi = OnboardingInfo(
        user=user,
        signup_intent="LOC",
        address="150 court st",
        address_verified=True,
        borough="BROOKLYN",
        state="NY",
        can_we_sms=True,
    )
    oi.full_clean()
    oi.save()
    assert oi.geocoded_point is not None
    assert oi.zipcode == "11201"
Example #11
0
    def convert_national_to_nyc_addr_if_needed(self,
                                               info: OnboardingInfo) -> bool:
        if not (info.geocoded_address and info.non_nyc_city
                and info.state == US_STATE_CHOICES.NY):
            return False

        info.update_geocoded_point_from_geometry()
        county = info.lookup_county()
        assert county, f"geocoded NYC address '{info.geocoded_address}' should have a county!"

        if county in NYC_COUNTY_BOROUGHS:
            self.log(
                f"National address at '{info.geocoded_address}' appears to be in NYC."
            )
            info.borough = NYC_COUNTY_BOROUGHS[county]
            info.non_nyc_city = ""
            info.geocoded_address = ""
            assert info.maybe_lookup_new_addr_metadata()
            return True

        return False
Example #12
0
    def perform_mutate(cls, form: forms.OnboardingStep4Form,
                       info: ResolveInfo):
        request = info.context
        phone_number = form.cleaned_data['phone_number']
        password = form.cleaned_data['password'] or None
        prev_steps = cls.__extract_all_step_session_data(request)
        if prev_steps is None:
            cls.log(
                info,
                "User has not completed previous steps, aborting mutation.")
            return cls.make_error(
                "You haven't completed all the previous steps yet.")
        with transaction.atomic():
            user = JustfixUser.objects.create_user(
                username=JustfixUser.objects.generate_random_username(),
                first_name=prev_steps['first_name'],
                last_name=prev_steps['last_name'],
                phone_number=phone_number,
                password=password,
            )

            oi = OnboardingInfo(user=user,
                                **pick_model_fields(OnboardingInfo,
                                                    **prev_steps,
                                                    **form.cleaned_data))
            oi.full_clean()
            oi.save()

        user.send_sms_async(
            f"Welcome to {get_site_name()}, {user.first_name}! "
            f"We'll be sending you notifications from this phone number.", )
        slack.sendmsg_async(
            f"{slack.hyperlink(text=user.first_name, href=user.admin_url)} "
            f"from {slack.escape(oi.borough_label)} has signed up!",
            is_safe=True)

        user.backend = settings.AUTHENTICATION_BACKENDS[0]
        login(request, user)

        for step in SESSION_STEPS:
            step.clear_from_request(request)

        return cls.mutation_success()
Example #13
0
def test_address_lines_for_mailing():
    info = OnboardingInfo()
    assert info.address_lines_for_mailing == []

    info.address = "150 Boop Way"
    assert info.address_lines_for_mailing == ["150 Boop Way"]

    info.apt_number = "2"
    assert info.address_lines_for_mailing == ["150 Boop Way", "Apartment 2"]

    info.borough = "MANHATTAN"
    assert info.address_lines_for_mailing == [
        "150 Boop Way", "Apartment 2", "New York, NY"
    ]

    info.zipcode = "11201"
    assert info.address_lines_for_mailing == [
        "150 Boop Way", "Apartment 2", "New York, NY 11201"
    ]
Example #14
0
def complete_onboarding(request, info, password: Optional[str]) -> JustfixUser:
    with transaction.atomic():
        user = JustfixUser.objects.create_user(
            username=JustfixUser.objects.generate_random_username(),
            first_name=info["first_name"],
            last_name=info["last_name"],
            preferred_first_name=info.get("preferred_first_name", ""),
            email=info["email"],
            phone_number=info["phone_number"],
            password=password,
            locale=translation.get_language_from_request(request,
                                                         check_path=True),
        )

        oi = OnboardingInfo(user=user,
                            **pick_model_fields(OnboardingInfo, **info))
        oi.full_clean()
        oi.save()

    partner = referral.get_partner(request)
    via = ""
    if partner:
        partner.users.add(user)
        via = f", via our partner {partner.name}"

    slack.sendmsg_async(
        f"{slack.hyperlink(text=user.best_first_name, href=user.admin_url)} "
        f"from {slack.escape(oi.city)}, {slack.escape(oi.state)} has signed up for "
        f"{slack.escape(SIGNUP_INTENT_CHOICES.get_label(oi.signup_intent))} in "
        f"{slack.escape(LOCALE_CHOICES.get_label(user.locale))}{via}!",
        is_safe=True,
    )

    user.backend = settings.AUTHENTICATION_BACKENDS[0]
    login(request, user)

    return user
Example #15
0
 def mkinfo(self, **kwargs):
     return OnboardingInfo(address="150 court street",
                           borough="BROOKLYN",
                           **kwargs)
Example #16
0
 def mkinfo(self, **kwargs):
     return OnboardingInfo(address='150 court street',
                           borough='BROOKLYN',
                           **kwargs)
Example #17
0
 def test_it_works_when_empty(self):
     info = OnboardingInfo()
     assert info.building_links == []
     assert info.get_building_links_html() == ''
Example #18
0
 def test_it_returns_none_when_no_geocoding_info_is_available(self):
     assert OnboardingInfo().lookup_county() is None
Example #19
0
 def test_it_returns_none_when_no_county_matches(self, db):
     CountyFactory()
     oi = OnboardingInfo(state="NY", geocoded_point=Point(50, 50))
     assert oi.lookup_county() is None
Example #20
0
def get_onboarding_info(user) -> OnboardingInfo:
    if hasattr(user, 'onboarding_info'):
        return user.onboarding_info
    return OnboardingInfo()
Example #21
0
def test_str_works_when_fields_are_set():
    info = OnboardingInfo(user=UserFactory.build(),
                          created_at=datetime.datetime(2018, 1, 2))
    assert str(
        info) == "Boop Jones's onboarding info from Tuesday, January 02 2018"
Example #22
0
def test_str_works_when_fields_are_not_set():
    info = OnboardingInfo()
    assert str(info) == 'OnboardingInfo object (None)'
Example #23
0
 def test_it_shows_bis_link_when_bin_is_present(self):
     info = OnboardingInfo(pad_bin='1234')
     assert 'DOB BIS' in info.get_building_links_html()
Example #24
0
 def test_it_shows_wow_link_when_bbl_is_present(self):
     info = OnboardingInfo(pad_bbl='1234')
     assert 'Who Owns What' in info.get_building_links_html()
Example #25
0
 def test_no_lookup_when_full_address_is_empty(self):
     assert OnboardingInfo().maybe_lookup_new_addr_metadata() is False
Example #26
0
def test_address_lines_for_mailing():
    info = OnboardingInfo()
    assert info.address_lines_for_mailing == []

    info.address = "150 Boop Way"
    assert info.address_lines_for_mailing == ["150 Boop Way"]

    info.apt_number = "2"
    assert info.address_lines_for_mailing == ["150 Boop Way", "Apartment 2"]

    info.borough = "MANHATTAN"
    info.state = "NY"
    assert info.address_lines_for_mailing == [
        "150 Boop Way", "Apartment 2", "New York, NY"
    ]

    info.zipcode = "11201"
    assert info.address_lines_for_mailing == [
        "150 Boop Way", "Apartment 2", "New York, NY 11201"
    ]

    info.borough = ""
    info.non_nyc_city = "Beetville"
    info.state = "OH"
    info.zipcode = "43210"
    assert info.address_lines_for_mailing == [
        "150 Boop Way", "Apartment 2", "Beetville, OH 43210"
    ]
Example #27
0
 def build(self):
     return OnboardingInfo(geometry={
         "type": "Point",
         "coordinates": [-118.24317, 34.05405]
     })
Example #28
0
 def test_it_returns_county_when_county_matches(self, db):
     CountyFactory()
     oi = OnboardingInfo(state="NY", geocoded_point=Point(0.1, 0.1))
     assert oi.lookup_county() == "Funkypants"
Example #29
0
 def set_geocoded_point(cls, model: OnboardingInfo, x: float, y: float):
     model.geometry = {"type": "Point", "coordinates": [x, y]}
     model.update_geocoded_point_from_geometry()