'Test if we can do logins
django_facebook.connect.connect_user'

def test_connect(self):

    user = get_user_model().objects.all()[:1][0]
    url = self.url
    example_url = reverse('facebook_example')
    with patch('django_facebook.views.connect_user', return_value=(CONNECT_ACTIONS.REGISTER, user)) as wrapped_connect:
        post_data = dict(access_token='short_username', next=('%s?register=1' % example_url))
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(wrapped_connect.call_count, 1)
        self.assertIn('register', response.redirect_chain[0][0])
        self.assertEqual(response.status_code, 200)
    with patch('django_facebook.views.connect_user', return_value=(CONNECT_ACTIONS.REGISTER, user)) as wrapped_connect:
        post_data = dict(access_token='short_username', register_next=('%s?register=1' % example_url))
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(wrapped_connect.call_count, 1)
        self.assertIn('register', response.redirect_chain[0][0])
        self.assertEqual(response.status_code, 200)
    with patch('django_facebook.views.connect_user', return_value=(CONNECT_ACTIONS.LOGIN, user)) as wrapped_connect:
        post_data = dict(access_token='short_username', next=('%s?loggggg=1' % example_url))
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(wrapped_connect.call_count, 1)
        self.assertIn('?loggggg=1', response.redirect_chain[0][0])
        self.assertEqual(response.status_code, 200)
    with patch('django_facebook.views.connect_user', return_value=(CONNECT_ACTIONS.CONNECT, user)) as wrapped_connect:
        post_data = dict(access_token='short_username', next=('%s?loggggg=1' % example_url))
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(wrapped_connect.call_count, 1)
        assert ('?loggggg=1' in response.redirect_chain[0][0])
        self.assertEqual(response.status_code, 200)
    from django_facebook import exceptions as facebook_exceptions
    profile_error = facebook_exceptions.IncompleteProfileError()
    profile_error.form = None
    with patch('django_facebook.views.connect_user', return_value=(CONNECT_ACTIONS.REGISTER, user), side_effect=profile_error) as wrapped_connect:
        post_data = dict(access_token='short_username', next=('%s?loggggg=1' % example_url))
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(wrapped_connect.call_count, 1)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(response.context)
        template = self.get_response_template(response)
        backend = get_registration_backend()
        assert (template.name in backend.get_registration_template())
