'Verify that the given URL redirects to the consent page when consent is required,
and doesn\'t redirect to the consent page when consent is not required.
Arguments:
* self: ignored
* client: the TestClient instance to be used
* url: URL to test
* status_code: expected status code of URL when no data sharing consent is required.'

def verify_consent_required(self, client, url, status_code=200):

    with mock.patch('openedx.features.enterprise_support.api.enterprise_enabled', return_value=True):
        with mock.patch('openedx.features.enterprise_support.api.consent_necessary_for_course') as mock_consent_necessary:
            mock_consent_necessary.return_value = True
            response = client.get(url)
            assert (response.status_code == 302)
            assert ('grant_data_sharing_permissions' in response.url)
            mock_consent_necessary.return_value = False
            response = client.get(url)
            assert (response.status_code == status_code)
            if (status_code == 302):
                assert ('grant_data_sharing_permissions' not in response.url)
            return response
