예제 #1
0
    def test_sort_by_deps_not_included(self, open_url_mock):
        calls = [
            MockResponse('get_system_setting', {'operation': 'version'}, 200,
                         '{"result": "4.5"}'),
            MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
            get_schema_response('/test:deps')
        ]
        open_url_mock.side_effect = lambda *args, **kwargs: mock_call(
            calls, *args, **kwargs)

        parent = "/test:deps"
        schema_data = json.loads(SCHEMA_DATA['/test:deps'])
        schema = schema_data['data']

        values = {'a': '1', 'b': '2'}

        vb = nso.ValueBuilder(
            nso.JsonRpc('http://localhost:8080/jsonrpc', 10, False))
        vb.build(parent, None, values, schema)
        values = list(vb.values)
        self.assertEqual(2, len(values))
        value = values[0]
        self.assertEqual('{0}/a'.format(parent), value.path)
        self.assertEqual('1', value.value)
        value = values[1]
        self.assertEqual('{0}/b'.format(parent), value.path)
        self.assertEqual('2', value.value)

        self.assertEqual(0, len(calls))
예제 #2
0
    def test_leaf_list_type_45(self, open_url_mock):
        calls = [
            MockResponse('get_system_setting', {'operation': 'version'}, 200,
                         '{"result": "4.5"}'),
            MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
            get_schema_response('/test:test/device-list')
        ]
        open_url_mock.side_effect = lambda *args, **kwargs: mock_call(
            calls, *args, **kwargs)

        parent = "/test:test"
        schema_data = json.loads(SCHEMA_DATA['/test:test'])
        schema = schema_data['data']

        vb = nso.ValueBuilder(
            nso.JsonRpc('http://localhost:8080/jsonrpc', 10, False))
        vb.build(parent, None, {'device-list': ['one', 'two']}, schema)
        values = list(vb.values)
        self.assertEqual(3, len(values))
        value = values[0]
        self.assertEqual('{0}/device-list'.format(parent), value.path)
        self.assertEqual(nso.State.ABSENT, value.state)
        value = values[1]
        self.assertEqual('{0}/device-list{{one}}'.format(parent), value.path)
        self.assertEqual(nso.State.PRESENT, value.state)
        value = values[2]
        self.assertEqual('{0}/device-list{{two}}'.format(parent), value.path)
        self.assertEqual(nso.State.PRESENT, value.state)

        self.assertEqual(0, len(calls))
예제 #3
0
    def test_identityref_leaf(self, open_url_mock):
        calls = [
            MockResponse('get_system_setting', {'operation': 'version'}, 200,
                         '{"result": "4.5"}'),
            MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
            get_schema_response('/an:id-name-leaf'),
            MockResponse('get_module_prefix_map', {}, 200,
                         '{{"result": {0}}}'.format(MODULE_PREFIX_MAP))
        ]
        open_url_mock.side_effect = lambda *args, **kwargs: mock_call(
            calls, *args, **kwargs)

        parent = "/an:id-name-leaf"
        schema_data = json.loads(SCHEMA_DATA['/an:id-name-leaf'])
        schema = schema_data['data']

        vb = nso.ValueBuilder(
            nso.JsonRpc('http://localhost:8080/jsonrpc', 10, False))
        vb.build(parent, None, 'ansible-nso:id-two', schema)
        values = list(vb.values)
        self.assertEqual(1, len(values))
        value = values[0]
        self.assertEqual(parent, value.path)
        self.assertEqual('set', value.state)
        self.assertEqual('an:id-two', value.value)

        self.assertEqual(0, len(calls))
예제 #4
0
    def test_nested_choice(self, open_url_mock):
        calls = [
            MockResponse('get_system_setting', {'operation': 'version'}, 200,
                         '{"result": "4.5"}'),
            MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
            get_schema_response('/test:test'),
            MockResponse('exists', {'path': '/test:test{direct}'}, 200,
                         '{"result": {"exists": true}}'),
            MockResponse('exists', {'path': '/test:test{nested}'}, 200,
                         '{"result": {"exists": true}}')
        ]
        open_url_mock.side_effect = lambda *args, **kwargs: mock_call(
            calls, *args, **kwargs)

        parent = "/test:test"
        schema_data = json.loads(SCHEMA_DATA['/test:test'])
        schema = schema_data['data']

        vb = nso.ValueBuilder(
            nso.JsonRpc('http://localhost:8080/jsonrpc', 10, False))
        vb.build(parent, None, [{
            'name': 'direct',
            'direct-child': 'direct-value'
        }, {
            'name': 'nested',
            'nested-child': 'nested-value'
        }], schema)
        values = list(vb.values)
        self.assertEqual(2, len(values))
        value = values[0]
        self.assertEqual('{0}{{direct}}/direct-child'.format(parent),
                         value.path)
        self.assertEqual('set', value.state)
        self.assertEqual('direct-value', value.value)

        value = values[1]
        self.assertEqual('{0}{{nested}}/nested-child'.format(parent),
                         value.path)
        self.assertEqual('set', value.state)
        self.assertEqual('nested-value', value.value)

        self.assertEqual(0, len(calls))