update urls.pyes to use path() and add some tests
This commit is contained in:
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)
|
||||
Reference in New Issue
Block a user