Skip to content

Commit bb8d718

Browse files
committed
address PR comments
* rename provider_search to provider_directory * clarify behavior of provider_directory.views.landing in development * write some tests about it
1 parent eb560d1 commit bb8d718

File tree

15 files changed

+86
-25
lines changed

15 files changed

+86
-25
lines changed

backend/app/settings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
# SECURITY WARNING: don't run with debug turned on in production!
3333
DEBUG = bool(config('DEBUG'))
34+
TESTING = sys.argv[1:2] == ['test']
35+
3436

3537
if DEBUG:
3638
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
@@ -54,7 +56,7 @@
5456
'django_filters',
5557
'drf_yasg',
5658
'xmlrunner',
57-
'provider_search.apps.ProviderSearch',
59+
'provider_directory.apps.ProviderDirectory',
5860
]
5961

6062
if not TESTING:
@@ -87,9 +89,9 @@
8789
'BACKEND': 'django.template.backends.django.DjangoTemplates',
8890
'DIRS': [
8991
# NOTE: (@abachman-dsac) this setup allows frontend/ to build directly
90-
# into provider_search/static/ and provider_search.views.landing to
92+
# into provider_directory/static/ and provider_directory.views.landing to
9193
# reference the resulting index.html
92-
os.path.join(BASE_DIR, 'provider_search', 'static'),
94+
os.path.join(BASE_DIR, 'provider_directory', 'static'),
9395
],
9496
'APP_DIRS': True,
9597
'OPTIONS': {
@@ -169,7 +171,7 @@
169171

170172
STATICFILES_DIRS = [
171173
os.path.join(BASE_DIR, 'static'),
172-
os.path.join(BASE_DIR, 'provider_search', 'static'),
174+
os.path.join(BASE_DIR, 'provider_directory', 'static'),
173175
]
174176

175177
# STATICFILES_DIRS = [

backend/app/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
urlpatterns = [
2222
path('fhir/', include("npdfhir.urls")),
2323
path('admin/', admin.site.urls),
24-
path('', include('provider_search.urls')),
24+
path('', include('provider_directory.urls')),
2525
] + debug_toolbar_urls()
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.apps import AppConfig
22

3-
class ProviderSearch(AppConfig):
3+
class ProviderDirectory(AppConfig):
44
default_auto_field = 'django.db.models.BigAutoField'
5-
name = 'provider_search'
5+
name = 'provider_directory'
File renamed without changes.
File renamed without changes.

backend/provider_directory/tests/__init__.py

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from datetime import datetime
2+
from http import HTTPStatus
3+
import os
4+
from pathlib import Path
5+
from django.test import TestCase
6+
from django.urls import reverse
7+
8+
TEST_DIR = Path(os.path.dirname(os.path.abspath(__file__)))
9+
STATIC_INDEX = TEST_DIR / '..' / 'static' / 'index.html'
10+
11+
class WithoutStaticIndex(TestCase):
12+
"""
13+
Visiting the index route when no static/index.html asset exists.
14+
"""
15+
16+
@classmethod
17+
def setUpTestData(cls):
18+
if os.path.exists(STATIC_INDEX):
19+
os.unlink(STATIC_INDEX)
20+
21+
def test_index_redirects_to_vite_in_development(self):
22+
"""
23+
When static/index.html doesn't exist, route redirects
24+
"""
25+
response = self.client.get(reverse('index'))
26+
self.assertRedirects(response, 'http://localhost:3000/', fetch_redirect_response=False)
27+
28+
class WithStaticIndex(TestCase):
29+
"""
30+
Visiting the index route when static/index.html asset does exist.
31+
"""
32+
33+
@classmethod
34+
def setUpTestData(cls):
35+
if not os.path.exists(STATIC_INDEX):
36+
with open(STATIC_INDEX, 'a') as index:
37+
index.write(f'\n<!-- test content {datetime.now()} -->')
38+
39+
def test_index_serves_static_file(self):
40+
"""
41+
When static/index.html exists, route serves it
42+
"""
43+
response = self.client.get(reverse('index'))
44+
self.assertContains(response, 'test content', status_code=HTTPStatus.OK)

0 commit comments

Comments
 (0)