'Use the Google provider to test the custom login/register form feature.'

def test_custom_form(self):

    auth_entry = 'custom1'
    login_url = pipeline.get_login_url(self.provider.provider_id, auth_entry)
    login_url += '&next=/misc/final-destination'
    self.assert_redirect_to_provider_looks_correct(self.client.get(login_url))
    def fake_auth_complete(inst, *args, **kwargs):
        "    Mock    the    backend's    auth_complete()    method    "
        kwargs.update({'response': self.get_response_data(), 'backend': inst})
        return inst.strategy.authenticate(*args, **kwargs)
    complete_url = pipeline.get_complete_url(self.provider.backend_name)
    with patch.object(self.provider.backend_class, 'auth_complete', fake_auth_complete):
        response = self.client.get(complete_url)
    self.assertEqual(response.status_code, 302)
    self.assertEqual(response['Location'], 'http://example.none/auth/custom_auth_entry')
    response = self.client.get(response['Location'])
    self.assertEqual(response.status_code, 200)
    self.assertIn('action="/misc/my-custom-registration-form"    method="post"', response.content)
    data_decoded = base64.b64decode(response.context['data'])
    data_parsed = json.loads(data_decoded)
    self.assertEqual(data_parsed, {'auth_entry': 'custom1', 'backend_name': 'google-oauth2', 'provider_id': 'oa2-google-oauth2', 'user_details': {'username': 'email_value', 'email': 'email_value@example.com', 'fullname': 'name_value', 'first_name': 'given_name_value', 'last_name': 'family_name_value'}})
    secret_key = settings.THIRD_PARTY_AUTH_CUSTOM_AUTH_FORMS['custom1']['secret_key']
    hmac_expected = hmac.new(secret_key, msg=data_decoded, digestmod=hashlib.sha256).digest()
    self.assertEqual(base64.b64decode(response.context['hmac']), hmac_expected)
    (email, password) = (data_parsed['user_details']['email'], 'random_password')
    created_user = UserFactory(email=email, password=password)
    login_response = self.client.post(reverse('login'), {'email': email, 'password': password})
    self.assertEqual(login_response.status_code, 200)
    response = self.client.get(complete_url)
    self.assertEqual(response.status_code, 302)
    self.assertEqual(response['Location'], 'http://example.none/misc/final-destination')
    (_, strategy) = self.get_request_and_strategy()
    self.assert_social_auth_exists_for_user(created_user, strategy)
