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" ]
def mkinfo(self, **kwargs): return OnboardingInfo( address="200 N Spring St", non_nyc_city="Los Angeles", state="CA", zipcode="90012", **kwargs, )
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'
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'
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'
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"
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"
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()
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"
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"
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()
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" ]
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
def mkinfo(self, **kwargs): return OnboardingInfo(address='150 court street', borough='BROOKLYN', **kwargs)
def test_it_works_when_empty(self): info = OnboardingInfo() assert info.building_links == [] assert info.get_building_links_html() == ''
def mkinfo(self, **kwargs): return OnboardingInfo(address="150 court street", borough="BROOKLYN", **kwargs)
def build(self): return OnboardingInfo(geometry={ "type": "Point", "coordinates": [-118.24317, 34.05405] })
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"
def test_it_returns_none_when_no_geocoding_info_is_available(self): assert OnboardingInfo().lookup_county() is None
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()
def test_str_works_when_fields_are_not_set(): info = OnboardingInfo() assert str(info) == 'OnboardingInfo object (None)'
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()
def test_no_lookup_when_full_address_is_empty(self): assert OnboardingInfo().maybe_lookup_new_addr_metadata() is False
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
def get_onboarding_info(user) -> OnboardingInfo: if hasattr(user, 'onboarding_info'): return user.onboarding_info return OnboardingInfo()
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"