30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
"""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())
|