update urls.pyes to use path() and add some tests
This commit is contained in:
parent
95396802de
commit
337e4db650
@ -1,5 +1,6 @@
|
||||
"""URL patterns for the countdown views."""
|
||||
from django.conf.urls import include, url
|
||||
from django.conf.urls import include
|
||||
from django.urls import path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from countdown.views import CountdownItemViewSet
|
||||
@ -8,5 +9,5 @@ router = DefaultRouter()
|
||||
router.register(r'items', CountdownItemViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^api/', include(router.urls)),
|
||||
path('api/', include(router.urls)),
|
||||
]
|
||||
|
@ -1,20 +1,16 @@
|
||||
"""URL patterns for the dispatcher API."""
|
||||
from django.urls import path
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from dispatch.views import (DispatchMessage, DispatchMessageByKey, DispatcherList, DispatcherDetail,
|
||||
DispatcherDetailByKey, DispatcherActionList, DispatcherActionDetail)
|
||||
|
||||
from dispatch.views import (DispatcherActionDetail, DispatcherActionList, DispatcherDetail, DispatcherDetailByKey,
|
||||
DispatcherList, DispatchMessage, DispatchMessageByKey)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^api/dispatchers/$', DispatcherList.as_view(), name='dispatch_api_dispatchers'),
|
||||
url(r'^api/dispatchers/(?P<pk>[0-9]+)/$', DispatcherDetail.as_view(), name='dispatch_api_dispatcher_detail'),
|
||||
url(r'^api/dispatchers/(?P<pk>[0-9]+)/message$', DispatchMessage.as_view(), name='dispatch_api_dispatch_message'),
|
||||
url(r'^api/dispatchers/(?P<key>[A-Za-z-]+)/$', DispatcherDetailByKey.as_view(),
|
||||
name='dispatch_api_dispatcher_detail'),
|
||||
url(r'^api/dispatchers/(?P<key>[A-Za-z-]+)/message$', DispatchMessageByKey.as_view(),
|
||||
name='dispatch_api_dispatch_message'),
|
||||
path('api/dispatchers/', DispatcherList.as_view(), name='dispatch_api_dispatchers'),
|
||||
path('api/dispatchers/<pk>/', DispatcherDetail.as_view(), name='dispatch_api_dispatcher_detail'),
|
||||
path('api/dispatchers/<pk>/message', DispatchMessage.as_view(), name='dispatch_api_dispatch_message'),
|
||||
path('api/dispatchers/<key>/', DispatcherDetailByKey.as_view(), name='dispatch_api_dispatcher_detail'),
|
||||
path('api/dispatchers/<key>/message', DispatchMessageByKey.as_view(), name='dispatch_api_dispatch_message'),
|
||||
|
||||
url(r'^api/actions/$', DispatcherActionList.as_view(), name='dispatch_api_actions'),
|
||||
url(r'^api/actions/(?P<pk>[0-9]+)/$', DispatcherActionDetail.as_view(), name='dispatch_api_action_detail'),
|
||||
path('api/actions/', DispatcherActionList.as_view(), name='dispatch_api_actions'),
|
||||
path('api/actions/<pk>/', DispatcherActionDetail.as_view(), name='dispatch_api_action_detail'),
|
||||
]
|
||||
|
@ -1,7 +1,8 @@
|
||||
"""General/baselite/site-wide URLs."""
|
||||
from adminplus.sites import AdminSitePlus
|
||||
from django.conf.urls import include, url
|
||||
from django.conf.urls import include
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
admin.site = AdminSitePlus()
|
||||
@ -9,17 +10,17 @@ admin.sites.site = admin.site
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', TemplateView.as_view(template_name='index.html'), name='index'),
|
||||
path('', TemplateView.as_view(template_name='index.html'), name='index'),
|
||||
|
||||
url(r'^countdown/', include('countdown.urls')),
|
||||
url(r'^dice/', include('dice.urls')),
|
||||
url(r'^dispatch/', include('dispatch.urls')),
|
||||
url(r'^itemsets/', include('facts.urls')),
|
||||
url(r'^karma/', include('karma.urls')),
|
||||
url(r'^markov/', include('markov.urls')),
|
||||
url(r'^pi/', include('pi.urls')),
|
||||
url(r'^races/', include('races.urls')),
|
||||
url(r'^weather/', include('weather.urls')),
|
||||
path('countdown/', include('countdown.urls')),
|
||||
path('dice/', include('dice.urls')),
|
||||
path('dispatch/', include('dispatch.urls')),
|
||||
path('itemsets/', include('facts.urls')),
|
||||
path('karma/', include('karma.urls')),
|
||||
path('markov/', include('markov.urls')),
|
||||
path('pi/', include('pi.urls')),
|
||||
path('races/', include('races.urls')),
|
||||
path('weather/', include('weather.urls')),
|
||||
|
||||
url(r'^admin/', admin.site.urls),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
@ -1,5 +1,4 @@
|
||||
"""URL patterns for the facts web views."""
|
||||
from django.conf.urls import url
|
||||
from django.urls import path
|
||||
|
||||
from facts.views import factcategory_detail, index, rpc_get_facts, rpc_get_random_fact
|
||||
@ -8,6 +7,6 @@ urlpatterns = [
|
||||
path('rpc/<category>/', rpc_get_facts, name='weather_rpc_get_facts'),
|
||||
path('rpc/<category>/random/', rpc_get_random_fact, name='weather_rpc_get_random_fact'),
|
||||
|
||||
url(r'^$', index, name='facts_index'),
|
||||
url(r'^(?P<factcategory_name>.+)/$', factcategory_detail, name='facts_factcategory_detail'),
|
||||
path('', index, name='facts_index'),
|
||||
path('<factcategory_name>/', factcategory_detail, name='facts_factcategory_detail'),
|
||||
]
|
||||
|
@ -1,16 +1,16 @@
|
||||
"""URL patterns for the karma views."""
|
||||
|
||||
from django.conf.urls import url, include
|
||||
from django.conf.urls import include
|
||||
from django.urls import path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from karma.views import key_detail, index, KarmaKeyViewSet
|
||||
from karma.views import KarmaKeyViewSet, index, key_detail
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r'keys', KarmaKeyViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', index, name='karma_index'),
|
||||
url(r'^key/(?P<karma_key>.+)/', key_detail, name='karma_key_detail'),
|
||||
path('', index, name='karma_index'),
|
||||
path('key/<karma_key>/', key_detail, name='karma_key_detail'),
|
||||
|
||||
url(r'^api/', include(router.urls)),
|
||||
path('api/', include(router.urls)),
|
||||
]
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""URL patterns for the pi views."""
|
||||
from django.conf.urls import include, url
|
||||
from django.conf.urls import include
|
||||
from django.urls import path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from pi.views import PiLogViewSet
|
||||
@ -8,5 +9,5 @@ router = DefaultRouter()
|
||||
router.register(r'simulations', PiLogViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^api/', include(router.urls)),
|
||||
path('api/', include(router.urls)),
|
||||
]
|
||||
|
@ -1,8 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
from django.urls import path
|
||||
|
||||
from races.views import index, race_detail
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', index, name='races_index'),
|
||||
url(r'^race/(?P<race_id>[A-Za-z0-9]+)/$', race_detail, name='race_detail'),
|
||||
path('', index, name='races_index'),
|
||||
path('race/<race_id>/', race_detail, name='race_detail'),
|
||||
]
|
||||
|
26
tests/test_countdown_api.py
Normal file
26
tests/test_countdown_api.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""Test the countdown package's webservice."""
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.timezone import now
|
||||
from rest_framework.status import HTTP_200_OK
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from countdown.models import CountdownItem
|
||||
|
||||
|
||||
class CountdownAPITest(APITestCase):
|
||||
"""Test countdown DRF views."""
|
||||
|
||||
def setUp(self):
|
||||
"""Do pre-test stuff."""
|
||||
self.client = self.client_class()
|
||||
self.user = User.objects.create(username='test')
|
||||
self.client.force_authenticate(user=self.user)
|
||||
|
||||
def test_items_retrieval(self):
|
||||
"""Test that the items endpoint returns objects."""
|
||||
CountdownItem.objects.create(at_time=now())
|
||||
|
||||
resp = self.client.get('/countdown/api/items/')
|
||||
|
||||
self.assertEqual(resp.status_code, HTTP_200_OK)
|
||||
self.assertEqual(len(resp.json()), CountdownItem.objects.count())
|
29
tests/test_dispatch_api.py
Normal file
29
tests/test_dispatch_api.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""Test the dispatch package's webservice."""
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework.status import HTTP_200_OK
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from dispatch.models import Dispatcher, DispatcherAction
|
||||
|
||||
|
||||
class DispatchAPITest(APITestCase):
|
||||
"""Test dispatch DRF views."""
|
||||
|
||||
def setUp(self):
|
||||
"""Do pre-test stuff."""
|
||||
self.client = self.client_class()
|
||||
self.user = User.objects.create(username='test')
|
||||
self.client.force_authenticate(user=self.user)
|
||||
|
||||
def test_dispatch_object_retrieval(self):
|
||||
"""Test that the list endpoints returns objects."""
|
||||
dispatcher = Dispatcher.objects.create()
|
||||
DispatcherAction.objects.create(dispatcher=dispatcher)
|
||||
|
||||
resp = self.client.get('/dispatch/api/dispatchers/')
|
||||
self.assertEqual(resp.status_code, HTTP_200_OK)
|
||||
self.assertEqual(len(resp.json()), Dispatcher.objects.count())
|
||||
|
||||
resp = self.client.get('/dispatch/api/actions/')
|
||||
self.assertEqual(resp.status_code, HTTP_200_OK)
|
||||
self.assertEqual(len(resp.json()), DispatcherAction.objects.count())
|
@ -22,4 +22,4 @@ class PiAPITest(APITestCase):
|
||||
resp = self.client.post('/pi/api/simulations/simulate/')
|
||||
|
||||
self.assertEqual(resp.status_code, HTTP_201_CREATED)
|
||||
self.assertEqual(PiLog.objects.count(), 2) # 2 because 0 entry and the real entry
|
||||
self.assertEqual(PiLog.objects.count(), 2)
|
||||
|
29
tests/test_races_views.py
Normal file
29
tests/test_races_views.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""Test the race views."""
|
||||
from unittest import mock
|
||||
|
||||
from django.test import TestCase
|
||||
from django.utils.timezone import now
|
||||
|
||||
from races.models import Race, Racer, RaceUpdate
|
||||
|
||||
|
||||
class RaceViewTest(TestCase):
|
||||
"""Test races views."""
|
||||
|
||||
def setUp(self):
|
||||
"""Do pre-test stuff."""
|
||||
self.client = self.client_class()
|
||||
|
||||
def test_race_display(self):
|
||||
"""Test the display of race info when it's been somewhat populated."""
|
||||
race = Race.objects.create(key='test')
|
||||
racer_a = Racer.objects.create(nick='hank', race=race)
|
||||
racer_b = Racer.objects.create(nick='bob', race=race)
|
||||
RaceUpdate.objects.create(race=race, racer=racer_a, update="test 1")
|
||||
RaceUpdate.objects.create(race=race, racer=racer_b, update="test 2")
|
||||
RaceUpdate.objects.create(race=race, racer=racer_a, update="test 3")
|
||||
|
||||
resp = self.client.get('/races/race/test/')
|
||||
self.assertIn(b'hank — test 1', resp.content)
|
||||
self.assertIn(b'bob — test 2', resp.content)
|
||||
self.assertIn(b'hank — test 3', resp.content)
|
Loading…
Reference in New Issue
Block a user