test_mirrorstatus.py 1.75 KB
Newer Older
Jelle van der Waa's avatar
Jelle van der Waa committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from django.test import TestCase

from mirrors.tests import create_mirror_url


class MirrorStatusTest(TestCase):
    def test_status(self):
        response = self.client.get('/mirrors/status/')
        self.assertEqual(response.status_code, 200)

    def test_json_endpoint(self):
        # Disables the cache_function's cache
        with self.settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}):
            response = self.client.get('/mirrors/status/json/')
            self.assertEqual(response.status_code, 200)
Jelle van der Waa's avatar
Jelle van der Waa committed
16
17
18
19
20
21
22
            data = response.json()
            self.assertEqual(data['urls'], [])

            mirror_url = create_mirror_url()

            response = self.client.get('/mirrors/status/json/')
            self.assertEqual(response.status_code, 200)
Jelle van der Waa's avatar
Jelle van der Waa committed
23
            data = response.json()
Jelle van der Waa's avatar
Jelle van der Waa committed
24
25
26
27
28
29

            self.assertEqual(len(data['urls']), 1)
            mirror = data['urls'][0]
            self.assertEqual(mirror['url'], mirror_url.url)

        mirror_url.delete()
30
31
32
33
34
35
36

    def test_json_tier(self):
        response = self.client.get('/mirrors/status/tier/99/json/')
        self.assertEqual(response.status_code, 404)

        response = self.client.get('/mirrors/status/tier/1/json/')
        self.assertEqual(response.status_code, 200)
Jelle van der Waa's avatar
Jelle van der Waa committed
37
        data = response.json()
38
39
40
41
42
43
44
45
        self.assertEqual(data['urls'], [])

        mirror_url = create_mirror_url()

        # Disables the cache_function's cache
        with self.settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}):
            response = self.client.get('/mirrors/status/json/')
            self.assertEqual(response.status_code, 200)
Jelle van der Waa's avatar
Jelle van der Waa committed
46
            data = response.json()
47
48
49
            self.assertNotEqual(data['urls'], [])

        mirror_url.delete()