27 lines
884 B
Python
27 lines
884 B
Python
"""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())
|