Add tests views
This commit is contained in:
parent
0aa314b4e1
commit
2b5bd18ae5
|
@ -0,0 +1,62 @@
|
||||||
|
from django.test import TestCase, Client
|
||||||
|
from django.urls import reverse
|
||||||
|
from jarvis.people.models import Gymnast
|
||||||
|
from jarvis.followup.models import Chrono, ChronoDetails
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
class ChronoViewTests(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
# Create a user for authentication
|
||||||
|
self.user = User.objects.create_user(username='testuser', password='12345')
|
||||||
|
self.client = Client()
|
||||||
|
self.client.login(username='testuser', password='12345')
|
||||||
|
|
||||||
|
# Create a Chrono and ChronoDetails
|
||||||
|
self.gymnast = Gymnast.objects.create(
|
||||||
|
last_name="Pauchou", first_name="Fred", birthdate="1987-07-03", gender=0
|
||||||
|
)
|
||||||
|
self.chrono = Chrono.objects.create(
|
||||||
|
gymnast=self.gymnast, chrono_type=0, score_type=0, score=15, tof=13
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_remove_jump_chrono_value_success(self):
|
||||||
|
"""Test removing a chrono detail successfully."""
|
||||||
|
url = reverse('remove_jump_chrono_value') # Ensure you have named your URL in urls.py
|
||||||
|
self.chrono_detail = ChronoDetails.objects.create(chrono=self.chrono, order=1, value=9.5)
|
||||||
|
response = self.client.post(url, {'chrono_id': self.chrono.id, 'order': 1})
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertFalse(ChronoDetails.objects.filter(id=self.chrono_detail.id).exists())
|
||||||
|
|
||||||
|
def test_remove_jump_chrono_value_not_found(self):
|
||||||
|
"""Test removing a non-existing chrono detail."""
|
||||||
|
url = reverse('remove_jump_chrono_value') # Ensure you have named your URL in urls.py
|
||||||
|
self.chrono_detail = ChronoDetails.objects.create(chrono=self.chrono, order=1, value=9.5)
|
||||||
|
response = self.client.post(url, {'chrono_id': self.chrono.id, 'order': 999})
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
# def test_remove_jump_chrono_value_missing_parameters(self):
|
||||||
|
# """Test the response when required parameters are missing."""
|
||||||
|
# url = reverse('remove_jump_chrono_value')
|
||||||
|
# self.chrono_detail = ChronoDetails.objects.create(chrono=self.chrono, order=1, value=9.5)
|
||||||
|
# response = self.client.post(url, {'chrono_id': self.chrono.id}) # 'order' is missing
|
||||||
|
# self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
def test_add_jump_chrono_value_success(self):
|
||||||
|
"""Test adding a new chrono detail successfully."""
|
||||||
|
url = reverse('add_jump_chrono_value')
|
||||||
|
response = self.client.post(url, {'chrono_id': self.chrono.id, 'order': 1, 'value': 9.5})
|
||||||
|
self.assertEqual(response.status_code, 201)
|
||||||
|
self.assertTrue(ChronoDetails.objects.filter(chrono=self.chrono, order=1, value=9.5).exists())
|
||||||
|
|
||||||
|
def test_add_jump_chrono_value_conflict(self):
|
||||||
|
"""Test adding a chrono detail that already exists."""
|
||||||
|
ChronoDetails.objects.create(chrono=self.chrono, order=1, value=9.5)
|
||||||
|
url = reverse('add_jump_chrono_value')
|
||||||
|
response = self.client.post(url, {'chrono_id': self.chrono.id, 'order': 1, 'value': 9.5})
|
||||||
|
self.assertEqual(response.status_code, 409)
|
||||||
|
|
||||||
|
# def test_add_jump_chrono_value_missing_parameters(self):
|
||||||
|
# """Test the response when required parameters are missing."""
|
||||||
|
# url = reverse('add_jump_chrono_value')
|
||||||
|
# response = self.client.post(url, {'chrono_id': self.chrono.id, 'order': 1}) # 'value' is missing
|
||||||
|
# self.assertEqual(response.status_code, 400)
|
Loading…
Reference in New Issue