blob: 72c9ed95185debb0ff89784c293d23e970c3ca5d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
from pathlib import Path
from django.conf import settings
from django.test import TestCase
from django.urls import reverse
TESTING_RESOURCES_PATH = Path(
settings.BASE_DIR, "pydis_site", "apps", "resources", "tests", "testing_resources"
)
class TestResourcesView(TestCase):
def test_resources_index_200(self):
"""Check does index of resources app return 200 HTTP response."""
url = reverse("resources:index")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_resources_with_valid_argument(self):
"""Check that you can resolve the resources when passing a valid argument."""
url = reverse("resources:index", kwargs={"resource_type": "book"})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_resources_with_invalid_argument(self):
"""Check that you can resolve the resources when passing an invalid argument."""
url = reverse("resources:index", kwargs={"resource_type": "urinal-cake"})
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
class TestResourceFilterView(TestCase):
def test_resource_filter_response(self):
"""Check that the filter endpoint returns JSON-formatted filters."""
url = reverse('resources:filters')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
content = response.json()
self.assertIn('difficulty', content)
self.assertIsInstance(content['difficulty'], list)
|