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.assertEquals(3, len(values))
        value = values[0]
        self.assertEquals('{0}/device-list'.format(parent), value.path)
        self.assertEquals(nso.State.ABSENT, value.state)
        value = values[1]
        self.assertEquals('{0}/device-list{{one}}'.format(parent), value.path)
        self.assertEquals(nso.State.PRESENT, value.state)
        value = values[2]
        self.assertEquals('{0}/device-list{{two}}'.format(parent), value.path)
        self.assertEquals(nso.State.PRESENT, value.state)

        self.assertEqual(0, len(calls))
    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.assertEquals(2, len(values))
        value = values[0]
        self.assertEquals('{0}/a'.format(parent), value.path)
        self.assertEquals('1', value.value)
        value = values[1]
        self.assertEquals('{0}/b'.format(parent), value.path)
        self.assertEquals('2', value.value)

        self.assertEqual(0, len(calls))
    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.assertEquals(1, len(values))
        value = values[0]
        self.assertEquals(parent, value.path)
        self.assertEquals('set', value.state)
        self.assertEquals('an:id-two', value.value)

        self.assertEqual(0, len(calls))
Ejemplo n.º 4
0
    def test_sort_by_deps(self, open_url_mock):
        calls = [
            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',
            'c': '3',
        }

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

        self.assertEqual(0, len(calls))
Ejemplo n.º 5
0
    def test_identityref_key(self, open_url_mock):
        calls = [
            MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
            get_schema_response('/an:id-name-values/id-name-value'),
            MockResponse('get_module_prefix_map', {}, 200,
                         '{{"result": {0}}}'.format(MODULE_PREFIX_MAP)),
            MockResponse(
                'exists',
                {'path': '/an:id-name-values/id-name-value{an:id-one}'}, 200,
                '{"result": {"exists": true}}')
        ]
        open_url_mock.side_effect = lambda *args, **kwargs: mock_call(
            calls, *args, **kwargs)

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

        vb = nso.ValueBuilder(nso.JsonRpc('http://localhost:8080/jsonrpc', 10))
        vb.build(parent, 'id-name-value', [{
            'name': 'ansible-nso:id-one',
            'value': '1'
        }], schema)
        self.assertEquals(1, len(vb.values))
        value = vb.values[0]
        self.assertEquals(
            '{0}/id-name-value{{an:id-one}}/value'.format(parent), value.path)
        self.assertEquals('set', value.state)
        self.assertEquals('1', value.value)

        self.assertEqual(0, len(calls))
Ejemplo n.º 6
0
    def test_nested_choice(self, open_url_mock):
        calls = [
            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'))
        vb.build(parent, None, [{'name': 'direct', 'direct-child': 'direct-value'},
                                {'name': 'nested', 'nested-child': 'nested-value'}], schema)
        self.assertEquals(2, len(vb.values))
        value = vb.values[0]
        self.assertEquals('{0}{{direct}}/direct-child'.format(parent), value.path)
        self.assertEquals('set', value.state)
        self.assertEquals('direct-value', value.value)

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

        self.assertEqual(0, len(calls))
Ejemplo n.º 7
0
    def test_leaf_list_type(self, open_url_mock):
        calls = [
            MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
            get_schema_response('/test:test')
        ]
        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'))
        vb.build(parent, None, {'device-list': ['one', 'two']}, schema)
        self.assertEquals(1, len(vb.values))
        value = vb.values[0]
        self.assertEquals('{0}/device-list'.format(parent), value.path)
        self.assertEquals(['one', 'two'], value.value)

        self.assertEqual(0, len(calls))