Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/maxkb/urls/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
path(admin_api_prefix, include("system_manage.urls")),
path(admin_api_prefix, include("application.urls")),
path(admin_api_prefix, include("trigger.urls")),
path(admin_api_prefix, include("oss.urls")),
path(admin_api_prefix, include("oss.urls", namespace="admin_oss")),
path(admin_api_prefix, include("homepage.urls")),
path(chat_api_prefix, include("oss.urls")),
path(chat_api_prefix, include("oss.urls", namespace="chat_oss")),
path(chat_api_prefix, include("chat.urls")),
path(f'{admin_ui_prefix[1:]}/', include('oss.retrieval_urls')),
path(f'{chat_ui_prefix[1:]}/', include('oss.retrieval_urls')),
path(f'{admin_ui_prefix[1:]}/', include('oss.retrieval_urls', namespace='admin_oss_retrieval')),
path(f'{chat_ui_prefix[1:]}/', include('oss.retrieval_urls', namespace='chat_oss_retrieval')),
]
init_doc(urlpatterns, chat_urlpatterns)

Expand Down
6 changes: 3 additions & 3 deletions apps/oss/retrieval_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
app_name = 'oss'

urlpatterns = [
re_path(rf'^(.*)/oss/file/(?P<file_id>[\w-]+)/?$',
re_path(r'^(.*)/oss/file/(?P<file_id>[\w-]+)/?$',
views.FileRetrievalView.as_view()),
re_path(rf'oss/file/(?P<file_id>[\w-]+)/?$',
re_path(r'oss/file/(?P<file_id>[\w-]+)/?$',
views.FileRetrievalView.as_view()),
re_path(rf'^/oss/get_url/(?P<url>[\w-]+)?$',
re_path(r'^oss/get_url/(?P<application_id>[\w-]+)/?$',
views.GetUrlView.as_view()),

]
55 changes: 53 additions & 2 deletions apps/oss/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
from django.test import TestCase
from django.test import SimpleTestCase
from django.urls import resolve

# Create your tests here.
from maxkb.const import CONFIG
from oss.views import FileRetrievalView, FileView, GetUrlView


class OssUrlTestCase(SimpleTestCase):
def assert_resolves(self, path, view_class, namespace, kwargs=None):
match = resolve(path)

self.assertIs(match.func.view_class, view_class)
self.assertEqual(match.namespace, namespace)
self.assertEqual(match.kwargs, kwargs or {})

def test_file_api_routes_use_unique_namespaces(self):
self.assert_resolves(
f'{CONFIG.get_admin_path()}/api/oss/file',
FileView,
'admin_oss',
)
self.assert_resolves(
f'{CONFIG.get_chat_path()}/api/oss/file',
FileView,
'chat_oss',
)

def test_file_retrieval_routes_use_unique_namespaces(self):
self.assert_resolves(
f'{CONFIG.get_admin_path()}/oss/file/file-id',
FileRetrievalView,
'admin_oss_retrieval',
{'file_id': 'file-id'},
)
self.assert_resolves(
f'{CONFIG.get_chat_path()}/oss/file/file-id',
FileRetrievalView,
'chat_oss_retrieval',
{'file_id': 'file-id'},
)

def test_get_url_retrieval_routes_pass_application_id(self):
self.assert_resolves(
f'{CONFIG.get_admin_path()}/oss/get_url/application-id',
GetUrlView,
'admin_oss_retrieval',
{'application_id': 'application-id'},
)
self.assert_resolves(
f'{CONFIG.get_chat_path()}/oss/get_url/application-id',
GetUrlView,
'chat_oss_retrieval',
{'application_id': 'application-id'},
)
Loading