mirror of
https://github.com/ae-utbm/sith.git
synced 2025-10-21 20:28:29 +00:00
add test cases
This commit is contained in:
44
club/tests/test_api.py
Normal file
44
club/tests/test_api.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from core.models import User
|
||||
|
||||
|
||||
class TestClubSearch(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.url = reverse("api:search_club")
|
||||
cls.client = Client()
|
||||
cls.user = User.objects.get(username="root")
|
||||
|
||||
def test_inactive_club(self):
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(self.url, {"is_active": False})
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.json()
|
||||
names = [item["name"] for item in data["results"]]
|
||||
assert "AE" not in names
|
||||
assert "Troll Penché" not in names
|
||||
|
||||
def test_excluded_id(self):
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(self.url, {"exclude_ids": [1]})
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.json()
|
||||
names = [item["name"] for item in data["results"]]
|
||||
assert "AE" not in names
|
||||
|
||||
def test_club_search(self):
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(self.url, {"search": "AE"})
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.json()
|
||||
names = [item["name"] for item in data["results"]]
|
||||
assert len(names) > 1
|
||||
|
||||
def test_anonymous_user_unauthorized(self):
|
||||
response = self.client.get(self.url)
|
||||
assert response.status_code == 401
|
Reference in New Issue
Block a user