diff --git a/requirements.txt b/requirements.txt index 6d98319a..ea7a9b73 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -django<4.0.0 +django<5 globus_sdk<4.0.0 social-auth-app-django<6.0.0>=3.0.0 python-jose[cryptography]>=3.0.1 diff --git a/tests/mocks.py b/tests/mocks.py index ac01c72f..ef82c4e6 100644 --- a/tests/mocks.py +++ b/tests/mocks.py @@ -2,12 +2,9 @@ import pytz import pathlib from django.contrib.auth.models import User -from django.urls import path, include from social_django.models import UserSocialAuth -from globus_portal_framework.urls import register_custom_index import globus_sdk -from globus_portal_framework.views import logout import json mocks_path = pathlib.Path(__file__).parent / 'data' @@ -98,51 +95,3 @@ def mock_user(username, resource_servers): user.save() soc_auth.save() return user - - -# def get_logged_in_client(username, tokens): -# c = Client() -# user = mock_user(username, tokens) -# # Password is set in mocks, and is always 'globusrocks' for this func -# c.login(username=username, password='globusrocks') -# return c - -# -# def globus_client_is_loaded_with_authorizer(client): -# return isinstance(client.kwargs.get('authorizer'), -# globus_sdk.AccessTokenAuthorizer) - - -def rebuild_index_urlpatterns(old_urlpatterns, indices): - """ - This fixes pre-complied paths not matching new test paths. Since paths - are compiled at import time, if you override settings with new - SEARCH_INDEXES, your new search indexes won't have urls that match due to - the regexes already being compiled. The problem stems from the UrlConverter - containing explicit names of the SEARCH_INDEXES which don't handle change - well. Use this function to rebuild the names to pick up on your test index - names. - :param old_urlpatterns: patterns you want to rebuild - :param indices: The list of new search indices you're using - Example: ['mytestindex', 'myothertestindex'] - :return: urlpatterns - """ - urlpatterns = [ - path('logout/', logout, name='logout'), - path('', include('social_django.urls', namespace='social')), - # FIXME Remove after merging #55 python-social-auth-upgrade - path('', include('django.contrib.auth.urls')) - ] - - register_custom_index('custom_index', indices) - - for url in old_urlpatterns: - if '' in str(url.pattern): - new_pattern = str(url.pattern).split('/') - new_pattern[0] = '' - new_pattern = '/'.join(new_pattern) - urlpatterns.append(path(new_pattern, url.callback, name=url.name)) - else: - urlpatterns.append(url) - - return urlpatterns diff --git a/tests/test_urls.py b/tests/test_urls.py index a7a7ae15..3eeabff8 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -4,43 +4,12 @@ from django.urls import reverse, path from django.http import HttpResponse -import tests -from tests.mocks import rebuild_index_urlpatterns - -from globus_portal_framework.urls import (search_urlpatterns, - register_custom_index, - urlpatterns as dgpf_urlpatterns) - -urlpatterns = [] - - -@pytest.fixture -@pytest.mark.urls('tests.test_urls') -def register_patterns(settings): - SEARCH_INDEXES = { - 'myindex': { - # Randomly generated and not real - 'uuid': '1e0be00f-8156-499e-980d-f7fb26157c02' - }, - 'my_custom_index': { - # Randomly generated and not real - 'uuid': '1e0be00f-8156-499e-980d-f7fb26157c02' - } - } - settings.SEARCH_INDEXES = SEARCH_INDEXES - register_custom_index('my_custom_index', ['my_custom_index']) - - urlpatterns = rebuild_index_urlpatterns( - search_urlpatterns + dgpf_urlpatterns, - list(SEARCH_INDEXES.keys())) - custom_search = mock.Mock( - return_value=HttpResponse('custom_search_view')) - custom_path = path('/', custom_search, - name='search') - urlpatterns.insert(0, custom_path) - setattr(tests.test_urls, 'urlpatterns', urlpatterns) +from globus_portal_framework.urls import register_custom_index +urlpatterns = [ + path('/foo/bar', lambda r, index: HttpResponse('hello foo'), name='foo') +] def test_register_non_existent_index_raises_error(settings): settings.SEARCH_INDEXES = {'myindex': { @@ -52,15 +21,7 @@ def test_register_non_existent_index_raises_error(settings): @pytest.mark.urls('tests.test_urls') -def test_custom_search_view(client, register_patterns): - r = client.get(reverse('search', args=['my_custom_index'])) - assert r.status_code == 200 - assert r.content == b'custom_search_view' - - -@pytest.mark.urls('tests.test_urls') -def test_regular_search_view_not_affected(client, register_patterns, - mock_data_search): - r = client.get(reverse('search', args=['myindex'])) +def test_custom_index_converter_view(client): + r = client.get(reverse('foo', args=['my_custom_index'])) assert r.status_code == 200 - assert b'custom_search_view' not in r.content + assert r.content == b'hello foo'