File: test_config.py

package info (click to toggle)
python-dcos 0.2.0-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,440 kB
  • sloc: python: 8,196; sh: 194; makefile: 36
file content (112 lines) | stat: -rw-r--r-- 2,567 bytes parent folder | download | duplicates (4)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from dcos import config

import pytest


@pytest.fixture
def conf():
    return config.Toml(_conf())


def test_get_property(conf):
    conf['dcos.mesos_uri'] == 'zk://localhost/mesos'


def test_get_partial_property(conf):
    conf['dcos'] == config.Toml({
        'user': 'group',
        'mesos_uri': 'zk://localhost/mesos'
    })


def test_iterator(conf):
    assert (sorted(list(conf.property_items())) == [
        ('dcos.mesos_uri', 'zk://localhost/mesos'),
        ('dcos.user', 'principal'),
        ('package.repo_uri', 'git://localhost/mesosphere/package-repo.git'),
    ])


@pytest.fixture
def mutable_conf():
    return config.MutableToml(_conf())


def test_mutable_unset_property(mutable_conf):
    expect = config.MutableToml({
        'dcos': {
            'user': 'principal',
            'mesos_uri': 'zk://localhost/mesos'
        },
        'package': {}
    })

    del mutable_conf['package.repo_uri']

    assert mutable_conf == expect


def test_mutable_set_property(mutable_conf):
    expect = config.MutableToml({
        'dcos': {
            'user': 'group',
            'mesos_uri': 'zk://localhost/mesos'
        },
        'package': {
            'repo_uri': 'git://localhost/mesosphere/package-repo.git'
        }
    })

    mutable_conf['dcos.user'] = 'group'

    assert mutable_conf == expect


def test_mutable_test_deep_property(mutable_conf):
    expect = config.MutableToml({
        'dcos': {
            'user': 'principal',
            'mesos_uri': 'zk://localhost/mesos'
        },
        'package': {
            'repo_uri': 'git://localhost/mesosphere/package-repo.git'
        },
        'new': {
            'key': 42
        },
    })

    mutable_conf['new.key'] = 42

    assert mutable_conf == expect


def test_mutable_get_property(mutable_conf):
    mutable_conf['dcos.mesos_uri'] == 'zk://localhost/mesos'


def test_mutable_get_partial_property(mutable_conf):
    mutable_conf['dcos'] == config.MutableToml({
        'user': 'group',
        'mesos_uri': 'zk://localhost/mesos'
    })


def test_mutable_iterator(mutable_conf):
    assert (sorted(list(mutable_conf.property_items())) == [
        ('dcos.mesos_uri', 'zk://localhost/mesos'),
        ('dcos.user', 'principal'),
        ('package.repo_uri', 'git://localhost/mesosphere/package-repo.git'),
    ])


def _conf():
    return {
        'dcos': {
            'user': 'principal',
            'mesos_uri': 'zk://localhost/mesos'
        },
        'package': {
            'repo_uri': 'git://localhost/mesosphere/package-repo.git'
        }
    }