Exemplo n.º 1
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"
    ]
Exemplo n.º 2
0
 def mkinfo(self, **kwargs):
     return OnboardingInfo(
         address="200 N Spring St",
         non_nyc_city="Los Angeles",
         state="CA",
         zipcode="90012",
         **kwargs,
     )
Exemplo n.º 3
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'
Exemplo n.º 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'
Exemplo n.º 5
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'
Exemplo n.º 6
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"
Exemplo n.º 7
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"
Exemplo n.º 8
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()
Exemplo n.º 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"
Exemplo n.º 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"
Exemplo n.º 11
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()
Exemplo n.º 12
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"
    ]
Exemplo n.º 13
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
Exemplo n.º 14
0
 def mkinfo(self, **kwargs):
     return OnboardingInfo(address='150 court street',
                           borough='BROOKLYN',
                           **kwargs)
Exemplo n.º 15
0
 def test_it_works_when_empty(self):
     info = OnboardingInfo()
     assert info.building_links == []
     assert info.get_building_links_html() == ''
Exemplo n.º 16
0
 def mkinfo(self, **kwargs):
     return OnboardingInfo(address="150 court street",
                           borough="BROOKLYN",
                           **kwargs)
Exemplo n.º 17
0
 def build(self):
     return OnboardingInfo(geometry={
         "type": "Point",
         "coordinates": [-118.24317, 34.05405]
     })
Exemplo n.º 18
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"
Exemplo n.º 19
0
 def test_it_returns_none_when_no_geocoding_info_is_available(self):
     assert OnboardingInfo().lookup_county() is None
Exemplo n.º 20
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()
Exemplo n.º 21
0
def test_str_works_when_fields_are_not_set():
    info = OnboardingInfo()
    assert str(info) == 'OnboardingInfo object (None)'
Exemplo n.º 22
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()
Exemplo n.º 23
0
 def test_no_lookup_when_full_address_is_empty(self):
     assert OnboardingInfo().maybe_lookup_new_addr_metadata() is False
Exemplo n.º 24
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
Exemplo n.º 25
0
def get_onboarding_info(user) -> OnboardingInfo:
    if hasattr(user, 'onboarding_info'):
        return user.onboarding_info
    return OnboardingInfo()
Exemplo n.º 26
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"