dr.botzo/tests/test_pi_views.py

26 lines
861 B
Python
Raw Normal View History

"""Test the pi package's views."""
from django.contrib.auth.models import User
from rest_framework.status import HTTP_201_CREATED
from rest_framework.test import APITestCase
from pi.models import PiLog
class PiAPITest(APITestCase):
"""Test pi 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_simulate_creates_simulation(self):
"""Test that the simulate action creates a log entry."""
self.assertEqual(PiLog.objects.count(), 0)
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