Esempio n. 1
0
    def test_dict_merge_simple(self):
        a = {'key': 'value'}
        b = {'key': 'value'}

        c = utils.dict_merge(a, b)
        assert c == {'key': 'value'}

        a = {'key': 'value'}
        b = {'key2': 'value'}

        c = utils.dict_merge(a, b)
        assert c == {'key': 'value', 'key2': 'value'}
Esempio n. 2
0
    def test_dict_merge_simple(self):
        a = {"key": "value"}
        b = {"key": "value"}

        c = utils.dict_merge(a, b)
        assert c == {"key": "value"}

        a = {"key": "value"}
        b = {"key2": "value"}

        c = utils.dict_merge(a, b)
        assert c == {"key": "value", "key2": "value"}
Esempio n. 3
0
    def test_dict_merge_simple(self):
        a = {'key': 'value'}
        b = {'key': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value'})

        a = {'key': 'value'}
        b = {'key2': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value', 'key2': 'value'})
Esempio n. 4
0
    def test_dict_merge_simple(self):
        a = {'key': 'value'}
        b = {'key': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value'})

        a = {'key': 'value'}
        b = {'key2': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value', 'key2': 'value'})
Esempio n. 5
0
    def test_dict_merge_with_list(self):
        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value', 'names': ['bob', 'kyle', 'kenny',
                                                       'jimbo', 'cartman', 'stan']})

        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'last_names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value',
                             'names': ['bob', 'kyle', 'kenny', 'jimbo'],
                             'last_names': ['kenny', 'cartman', 'stan']})
Esempio n. 6
0
    def test_dict_merge_bad_merge(self):
        """Returns b because it isn't a dict"""
        a = {'key': 'value'}
        b = 'duh'

        c = utils.dict_merge(a, b)
        self.assertEqual(c, b)
Esempio n. 7
0
    def test_dict_merge_bad_merge(self):
        """Returns b because it isn't a dict"""
        a = {"key": "value"}
        b = "duh"

        c = utils.dict_merge(a, b)
        assert c == b
Esempio n. 8
0
    def test_dict_merge_bad_merge(self):
        """Returns b because it isn't a dict"""
        a = {'key': 'value'}
        b = 'duh'

        c = utils.dict_merge(a, b)
        self.assertEqual(c, b)
Esempio n. 9
0
    def test_dict_merge_even_deeper(self):
        a = {
            'key': 'value',
            'here': {'without': 'you'},
            'other': {'scrubs': {'char3': 'Cox'}}

        }

        b = {
            'this': 'that',
            'here': {'with': 'me'},
            'other': {'magic': 'unicorn', 'scrubs': {'char1': 'JD', 'char2': 'Turk'}}
        }

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {
            'key': 'value',
            'this': 'that',
            'here': {'with': 'me', 'without': 'you'},
            'other': {
                'magic': 'unicorn',
                'scrubs': {
                    'char1': 'JD',
                    'char2': 'Turk',
                    'char3': 'Cox'
                }
            }
        })
Esempio n. 10
0
    def _fetch_service_config(self, app):
        try:
            # Get the service from k8s to attach the domain correctly
            svc = self._scheduler.svc.get(app, app).json()
        except KubeException as e:
            raise ServiceUnavailable('Could not fetch Kubernetes Service {}'.format(app)) from e

        # Get minimum structure going if it is missing on the service
        if 'metadata' not in svc or 'annotations' not in svc['metadata']:
            default = {'metadata': {'annotations': {}}}
            svc = dict_merge(svc, default)

        if 'labels' not in svc['metadata']:
            default = {'metadata': {'labels': {}}}
            svc = dict_merge(svc, default)

        return svc
Esempio n. 11
0
 def test_dict_merge_not_dict(self):
     """
     second item is not a dict, which dict_merge will just return
     """
     a = {'key': 'value'}
     b = 'somethig'
     c = utils.dict_merge(a, b)
     self.assertEqual(c, b)
Esempio n. 12
0
 def test_dict_merge_not_dict(self):
     """
     second item is not a dict, which dict_merge will just return
     """
     a = {'key': 'value'}
     b = 'somethig'
     c = utils.dict_merge(a, b)
     self.assertEqual(c, b)
Esempio n. 13
0
    def _fetch_service_config(self, app):
        # Get the service from k8s to attach the domain correctly
        svc = self._scheduler._get_service(app, app).json()
        # Get minimum structure going if it is missing on the service
        if 'metadata' not in svc or 'annotations' not in svc['metadata']:
            default = {'metadata': {'annotations': {}}}
            svc = dict_merge(svc, default)

        return svc
Esempio n. 14
0
    def _fetch_service_config(self, app):
        try:
            # Get the service from k8s to attach the domain correctly
            svc = self._scheduler.svc.get(app, app).json()
        except KubeException as e:
            raise ServiceUnavailable(
                'Could not fetch Kubernetes Service {}'.format(app)) from e

        # Get minimum structure going if it is missing on the service
        if 'metadata' not in svc or 'annotations' not in svc['metadata']:
            default = {'metadata': {'annotations': {}}}
            svc = dict_merge(svc, default)

        if 'labels' not in svc['metadata']:
            default = {'metadata': {'labels': {}}}
            svc = dict_merge(svc, default)

        return svc
Esempio n. 15
0
    def test_dict_merge_with_list(self):
        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        assert c == {
            'key': 'value',
            'names': ['bob', 'kyle', 'kenny', 'jimbo', 'cartman', 'stan']
        }
Esempio n. 16
0
    def test_dict_merge_deeper(self):
        a = {"key": "value", "here": {"without": "you"}}
        b = {"this": "that", "here": {"with": "me"}, "other": {"magic", "unicorn"}}

        c = utils.dict_merge(a, b)
        assert c == {
            "key": "value",
            "this": "that",
            "here": {"with": "me", "without": "you"},
            "other": {"magic", "unicorn"},
        }
Esempio n. 17
0
    def test_dict_merge_with_list(self):
        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(
            c, {
                'key': 'value',
                'names': ['bob', 'kyle', 'kenny', 'jimbo', 'cartman', 'stan']
            })

        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'last_names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(
            c, {
                'key': 'value',
                'names': ['bob', 'kyle', 'kenny', 'jimbo'],
                'last_names': ['kenny', 'cartman', 'stan']
            })
Esempio n. 18
0
    def test_dict_merge_deeper(self):
        a = {'key': 'value', 'here': {'without': 'you'}}
        b = {'this': 'that', 'here': {'with': 'me'}, 'other': {'magic', 'unicorn'}}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {
            'key': 'value',
            'this': 'that',
            'here': {
                'with': 'me',
                'without': 'you'
            },
            'other': {'magic', 'unicorn'}
        })
Esempio n. 19
0
    def test_dict_merge_even_deeper(self):
        a = {"key": "value", "here": {"without": "you"}, "other": {"scrubs": {"char3": "Cox"}}}

        b = {
            "this": "that",
            "here": {"with": "me"},
            "other": {"magic": "unicorn", "scrubs": {"char1": "JD", "char2": "Turk"}},
        }

        c = utils.dict_merge(a, b)
        assert c == {
            "key": "value",
            "this": "that",
            "here": {"with": "me", "without": "you"},
            "other": {"magic": "unicorn", "scrubs": {"char1": "JD", "char2": "Turk", "char3": "Cox"}},
        }
Esempio n. 20
0
    def test_dict_merge_even_deeper(self):
        a = {
            'key': 'value',
            'here': {
                'without': 'you'
            },
            'other': {
                'scrubs': {
                    'char3': 'Cox'
                }
            }
        }

        b = {
            'this': 'that',
            'here': {
                'with': 'me'
            },
            'other': {
                'magic': 'unicorn',
                'scrubs': {
                    'char1': 'JD',
                    'char2': 'Turk'
                }
            }
        }

        c = utils.dict_merge(a, b)
        self.assertEqual(
            c, {
                'key': 'value',
                'this': 'that',
                'here': {
                    'with': 'me',
                    'without': 'you'
                },
                'other': {
                    'magic': 'unicorn',
                    'scrubs': {
                        'char1': 'JD',
                        'char2': 'Turk',
                        'char3': 'Cox'
                    }
                }
            })
Esempio n. 21
0
    def test_dict_merge_deeper(self):
        a = {'key': 'value', 'here': {'without': 'you'}}
        b = {
            'this': 'that',
            'here': {
                'with': 'me'
            },
            'other': {'magic', 'unicorn'}
        }

        c = utils.dict_merge(a, b)
        assert c == {
            'key': 'value',
            'this': 'that',
            'here': {
                'with': 'me',
                'without': 'you'
            },
            'other': {'magic', 'unicorn'}
        }
Esempio n. 22
0
    def test_dict_merge_with_list(self):
        a = {"key": "value", "names": ["bob", "kyle", "kenny", "jimbo"]}
        b = {"key": "value", "names": ["kenny", "cartman", "stan"]}

        c = utils.dict_merge(a, b)
        assert c == {"key": "value", "names": ["bob", "kyle", "kenny", "jimbo", "cartman", "stan"]}