vendredi 17 avril 2020

testing stripe on boarding view django

i am trying to test the view pasted below. However i can't figure out how i would go about doing this. I can get so far as mocking the get request, but how can i grab the values from the view to test them against values they should be.

Here is the view :

class StripeAuthorizeView(LoginRequiredMixin, View):

    def get(self, request):

        url = 'https://connect.stripe.com/express/oauth/authorize?'
        user = self.request.user
        if user.account_type == 'Business':
            business_type = 'company'
        else:
            business_type = 'individual'
        params = {
            'response_type': 'code',
            'scope': 'read_write',
            'client_id': settings.STRIPE_CONNECT_CLIENT_ID,
            'redirect_uri': f'http://127.0.0.1:8000/accounts/stripe/oauth/callback',
            'stripe_user[email]' : user.email,
            'stripe_user[business_type]' : business_type,
            'stripe_user[url]' : 'http://127.0.0.1:8000/accounts/user/%s/' %user.pk,
        }
        url = f'{url}?{urllib.parse.urlencode(params)}'
        return redirect(url)

I need to be able to test that the url is the correct url, the view is sending the correct client id and pre filling in the correct fields, eg user.email etc. The scary thing is if i can't write some tests for it, if someone was to accidentally change them it will cripple my platform. Really need to be testing that the view is getting passed the correct data to the stripe api.

Any help will really be helped.

Aucun commentaire:

Enregistrer un commentaire