コード例 #1
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
    def test_it_works_for_nyc_users(self, smsoutbox, mailoutbox):
        request = self.graphql_client.request
        self.populate_phone_number()
        update_scaffolding(request, self.NYC_SCAFFOLDING)
        assert SCAFFOLDING_SESSION_KEY in request.session
        assert self.execute()["errors"] == []
        user = JustfixUser.objects.get(phone_number="5551234567")
        assert user.first_name == "zlorp"
        assert user.last_name == "zones"
        assert user.preferred_first_name == ""
        assert user.email == "*****@*****.**"
        oi = user.onboarding_info
        assert oi.non_nyc_city == ""
        assert oi.borough == "MANHATTAN"
        assert oi.state == "NY"
        assert oi.address == "123 boop way"
        assert oi.apt_number == "3B"
        assert oi.agreed_to_norent_terms is False
        assert oi.agreed_to_justfix_terms is False
        assert oi.agreed_to_evictionfree_terms is True

        # This will only get filled out if geocoding is enabled, which it's not.
        assert oi.zipcode == ""

        assert get_last_queried_phone_number(request) is None
        assert SCAFFOLDING_SESSION_KEY not in request.session
コード例 #2
0
 def perform_mutate(cls, form, info: ResolveInfo):
     request = info.context
     scf = get_scaffolding(request)
     city = scf.city
     state = scf.state
     if not (city and state):
         return cls.make_error(
             "You haven't provided your city and state yet!")
     cleaned_data, is_valid = cls.validate_address(form.cleaned_data,
                                                   city=city,
                                                   state=state)
     if not is_zip_code_valid_for_state(cleaned_data["zip_code"], state):
         return cls.make_error(
             _("Please enter a valid ZIP code for %(state_name)s.") %
             {"state_name": US_STATE_CHOICES.get_label(state)},
             field="zip_code",
         )
     if is_valid and is_lnglat_in_nyc(cleaned_data["lnglat"]):
         return cls.make_error(
             _("Your address appears to be within New York City. Please "
               'go back and enter "New York City" as your city.'),
             code="ADDRESS_IS_IN_NYC",
         )
     update_scaffolding(request, cleaned_data)
     return cls.mutation_success(is_valid=is_valid)
コード例 #3
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
    def test_it_works_for_national_users(self):
        request = self.graphql_client.request
        self.populate_phone_number()
        update_scaffolding(request, self.NATIONAL_SCAFFOLDING)
        assert SCAFFOLDING_SESSION_KEY in request.session
        assert self.execute()["errors"] == []
        user = JustfixUser.objects.get(phone_number="5551234567")
        assert user.first_name == "boop"
        assert user.last_name == "jones"
        assert user.preferred_first_name == "bip"
        assert user.email == "*****@*****.**"
        oi = user.onboarding_info
        assert oi.non_nyc_city == "Albany"
        assert oi.borough == ""
        assert oi.state == "NY"
        assert oi.zipcode == "12345"
        assert oi.address == "1200 Bingy Bingy Way"
        assert oi.apt_number == "5A"
        assert oi.agreed_to_norent_terms is False
        assert oi.agreed_to_justfix_terms is False
        assert oi.agreed_to_evictionfree_terms is True

        assert oi.can_we_sms is True
        assert oi.can_rtc_sms is True
        assert oi.can_hj4a_sms is True

        assert get_last_queried_phone_number(request) is None
        assert SCAFFOLDING_SESSION_KEY not in request.session
コード例 #4
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
def test_is_city_in_nyc_works(graphql_client, city, state, expected):
    update_scaffolding(graphql_client.request, {"city": city, "state": state})

    actual = graphql_client.execute("""
        query { session { onboardingScaffolding { isCityInNyc } } }
        """)["data"]["session"]["onboardingScaffolding"]["isCityInNyc"]

    assert actual is expected
コード例 #5
0
ファイル: schema.py プロジェクト: JustFixNYC/tenants2
    def perform_mutate(cls, form, info: ResolveInfo):
        if info.context.user.is_authenticated:
            cls.perform_mutate_for_logged_in_user(form, info)
        else:
            update_scaffolding(
                info.context,
                with_keys_renamed(form.cleaned_data, form.to_scaffolding_keys))

        return cls.mutation_success()
コード例 #6
0
 def test_it_creates_account_without_email_required(self, smsoutbox,
                                                    mailoutbox):
     request = self.graphql_client.request
     self.populate_phone_number()
     update_scaffolding(request, self.LA_SCAFFOLDING)
     assert SCAFFOLDING_SESSION_KEY in request.session
     assert self.execute(self.INPUT_WITHOUT_EMAIL)["errors"] == []
     user = JustfixUser.objects.get(phone_number="5551234567")
     assert user.email == ""
コード例 #7
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
def test_is_in_los_angeles_works(graphql_client, zip_code, expected):
    update_scaffolding(
        graphql_client.request,
        {
            "zip_code": zip_code,
        },
    )

    actual = graphql_client.execute("""
        query { session { onboardingScaffolding { isInLosAngeles } } }
        """)["data"]["session"]["onboardingScaffolding"]["isInLosAngeles"]

    assert actual is expected
コード例 #8
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
def test_scaffolding_defaults_work(graphql_client):
    update_scaffolding(graphql_client.request, {"firstName": ""})
    result = graphql_client.execute("""
        query {
          session {
            onboardingScaffolding {
              firstName,
              canReceiveRttcComms,
              canReceiveSajeComms,
            }
          }
        }
        """)["data"]["session"]["onboardingScaffolding"]
    assert result == {
        "firstName": "",
        "canReceiveRttcComms": None,
        "canReceiveSajeComms": None,
    }
コード例 #9
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
 def test_it_validates_addresses(self, settings, requests_mock):
     settings.MAPBOX_ACCESS_TOKEN = "blah"
     update_scaffolding(self.request, {
         "city": "Los Angeles",
         "state": "CA"
     })
     mock_la_results("200 north spring, Los Angeles, CA 90012",
                     requests_mock)
     output = self.execute(input={
         "street": "200 north spring",
         "zipCode": "90012",
     })
     assert output["errors"] == []
     assert output["isValid"] is True
     assert output["session"]["onboardingScaffolding"] == {
         "street": "200 North Spring Street",
         "zipCode": "90012",
         "aptNumber": "2",
     }
コード例 #10
0
 def perform_mutate(cls, form, info: ResolveInfo):
     request = info.context
     user = request.user
     ld = LandlordDetails.objects.get_or_create(user=user)[0]
     ld.name = form.cleaned_data["name"]
     ld.is_looked_up = False
     has_email_address = form.cleaned_data["has_email_address"]
     has_mailing_address = form.cleaned_data["has_mailing_address"]
     if not has_email_address:
         ld.email = ""
     if not has_mailing_address:
         ld.clear_address()
     ld.save()
     update_scaffolding(
         request,
         {
             "has_landlord_email_address": has_email_address,
             "has_landlord_mailing_address": has_mailing_address,
         },
     )
     return cls.mutation_success()
コード例 #11
0
    def test_it_works_for_la_users(self, smsoutbox, mailoutbox):
        request = self.graphql_client.request
        self.populate_phone_number()
        update_scaffolding(request, self.LA_SCAFFOLDING)
        assert SCAFFOLDING_SESSION_KEY in request.session
        assert self.execute()["errors"] == []
        user = JustfixUser.objects.get(phone_number="5551234567")
        assert user.first_name == "zanet"
        assert user.last_name == "zones"
        assert user.email == "*****@*****.**"
        oi = user.onboarding_info
        assert oi.non_nyc_city == "Los Angeles"
        assert oi.state == "CA"
        assert oi.address == "1200 Bingy Bingy Way"
        assert oi.apt_number == "5A"
        assert oi.agreed_to_norent_terms is False
        assert oi.agreed_to_justfix_terms is False
        assert oi.agreed_to_evictionfree_terms is False
        assert oi.agreed_to_laletterbuilder_terms is True
        assert oi.zipcode == "12345"

        assert get_last_queried_phone_number(request) is None
        assert SCAFFOLDING_SESSION_KEY not in request.session
コード例 #12
0
 def perform_mutate_for_anonymous_user(cls, form, info: ResolveInfo):
     update_scaffolding(info.context,
                        {cls.comms_field_name: cls.get_opt_in(form)})
     return cls.mutation_success()
コード例 #13
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
 def test_it_returns_error_when_national_addr_but_incomplete_scaffolding(
         self):
     self.populate_phone_number()
     scaff = {**self.NATIONAL_SCAFFOLDING, "street": ""}
     update_scaffolding(self.graphql_client.request, scaff)
     assert self.execute()["errors"] == self.INCOMPLETE_ERR
コード例 #14
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
 def test_it_returns_error_when_national_addr_but_no_phone_number(self):
     update_scaffolding(self.graphql_client.request,
                        self.NATIONAL_SCAFFOLDING)
     assert self.execute()["errors"] == self.INCOMPLETE_ERR
コード例 #15
0
ファイル: test_schema.py プロジェクト: JustFixNYC/tenants2
 def set_prior_info(self):
     update_scaffolding(self.request, {"city": "Brooklyn", "state": "NY"})