aboutsummaryrefslogtreecommitdiffstats
path: root/api/tests/test_snake_names.py
blob: fcb70abd5dd409daaa47525ae3157c53a24217cc (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
41
42
43
44
45
46
47
from django_hosts.resolvers import reverse

from .base import APISubdomainTestCase
from ..models import SnakeName



class StatusTests(APISubdomainTestCase):
    def setUp(self):
        super().setUp()
        self.client.force_authenticate(user=None)

    def test_cannot_read_snake_names(self):
        url = reverse('snakename-list', host='api')
        response = self.client.get(url)

        self.assertEqual(response.status_code, 401)


class EmptyDatabaseSnakeNameTests(APISubdomainTestCase):
    def test_endpoint_unauthed_returns_empty_list(self):
        url = reverse('snakename-list', host='api')
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(), [])


class SnakeNameListTests(APISubdomainTestCase):
    @classmethod
    def setUpTestData(cls):
        cls.snake_python = SnakeName.objects.create(name='Python', scientific='Totally.')

    def test_endpoint_returns_all_snakes(self):
        url = reverse('snakename-list', host='api')
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response.json(),
            [
                {
                    'name': 'Python',
                    'scientific': 'Totally.'
                }
            ]
        )