summaryrefslogtreecommitdiffstats
path: root/qa/tasks/mgr/dashboard/test_settings.py
blob: 2d890484a3e04f09326a926ee18c995376709bc2 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-

from __future__ import absolute_import

from .helper import DashboardTestCase, JList, JObj, JAny


class SettingsTest(DashboardTestCase):
    def setUp(self):
        super(SettingsTest, self).setUp()
        self.settings = self._get('/api/settings')

    def tearDown(self):
        self._put(
            '/api/settings',
            {setting['name']: setting['value']
             for setting in self.settings})

    def test_list_settings(self):
        settings = self._get('/api/settings')
        self.assertGreater(len(settings), 10)
        self.assertSchema(
            settings,
            JList(
                JObj({
                    'default': JAny(none=False),
                    'name': str,
                    'type': str,
                    'value': JAny(none=False)
                })))
        self.assertStatus(200)

    def test_get_setting(self):
        setting = self._get('/api/settings/rgw-api-access-key')
        self.assertSchema(
            setting,
            JObj({
                'default': JAny(none=False),
                'name': str,
                'type': str,
                'value': JAny(none=False)
            }))
        self.assertStatus(200)

    def test_set_setting(self):
        self._put('/api/settings/rgw-api-access-key', {'value': 'foo'})
        self.assertStatus(200)

        value = self._get('/api/settings/rgw-api-access-key')['value']
        self.assertEqual('foo', value)

    def test_bulk_set(self):
        self._put('/api/settings', {
            'RGW_API_HOST': 'somehost',
            'RGW_API_PORT': 7777,
        })
        self.assertStatus(200)

        host = self._get('/api/settings/rgw-api-host')['value']
        self.assertStatus(200)
        self.assertEqual('somehost', host)

        port = self._get('/api/settings/rgw-api-port')['value']
        self.assertStatus(200)
        self.assertEqual(7777, port)