예제 #1
0
    def test_build_identifier_from_invalid_source_type(self):
        identifiers = [Parameter(target='Id', source='invalid')]

        parent = mock.Mock()
        params = {}
        response = {'Container': {'Frobs': []}}

        with pytest.raises(NotImplementedError):
            build_identifiers(identifiers, parent, params, response)
예제 #2
0
    def test_build_identifier_from_parent_identifier(self):
        identifiers = [Parameter(target='Id', source='identifier', name='Id')]

        parent = mock.Mock()
        parent.id = 'identifier'
        params = {}
        response = {'Container': {'Frobs': []}}

        values = build_identifiers(identifiers, parent, params, response)

        # Verify identifier loaded from responsePath scalar set
        assert values[0][1] == 'identifier'
예제 #3
0
    def test_build_identifier_from_parent_data_member(self):
        identifiers = [Parameter(target='Id', source='data', path='Member')]

        parent = mock.Mock()
        parent.meta = ResourceMeta('test', data={'Member': 'data-member'})
        params = {}
        response = {'Container': {'Frobs': []}}

        values = build_identifiers(identifiers, parent, params, response)

        # Verify identifier loaded from responsePath scalar set
        assert values[0][1] == 'data-member'
예제 #4
0
    def test_build_identifier_from_parent_data_member(self):
        identifiers = [Parameter(target='Id', source='data', path='Member')]

        parent = mock.Mock()
        parent.meta = ResourceMeta('test', data={'Member': 'data-member'})
        params = {}
        response = {'Container': {'Frobs': []}}

        values = build_identifiers(identifiers, parent, params, response)

        self.assertEqual(values[0][1], 'data-member',
                         'Identifier loaded from parent data member not set')
예제 #5
0
    def test_build_identifier_from_parent_identifier(self):
        identifiers = [Parameter(target='Id', source='identifier', name='Id')]

        parent = mock.Mock()
        parent.id = 'identifier'
        params = {}
        response = {'Container': {'Frobs': []}}

        values = build_identifiers(identifiers, parent, params, response)

        self.assertEqual(values[0][1], 'identifier',
                         'Identifier loaded from parent identifier not set')
예제 #6
0
    def test_build_identifier_from_req_param(self):
        identifiers = [
            Parameter(target='Id', source='requestParameter', path='Param')
        ]

        parent = mock.Mock()
        params = {'Param': 'request-param'}
        response = {'Container': {'Frobs': []}}

        values = build_identifiers(identifiers, parent, params, response)

        # Verify identifier loaded from responsePath scalar set
        assert values[0][1] == 'request-param'
예제 #7
0
    def test_build_identifier_from_res_path_scalar(self):
        identifiers = [
            Parameter(target='Id', source='response', path='Container.Frob.Id')
        ]

        parent = mock.Mock()
        params = {}
        response = {'Container': {'Frob': {'Id': 'response-path'}}}

        values = build_identifiers(identifiers, parent, params, response)

        # Verify identifier loaded from responsePath scalar set
        assert values[0][1] == 'response-path'
예제 #8
0
    def test_build_identifier_from_req_param(self):
        identifiers = [
            Parameter(target='Id', source='requestParameter', path='Param')
        ]

        parent = mock.Mock()
        params = {'Param': 'request-param'}
        response = {'Container': {'Frobs': []}}

        values = build_identifiers(identifiers, parent, params, response)

        self.assertEqual(values[0][1], 'request-param',
                         'Identifier loaded from request parameter not set')
예제 #9
0
    def test_build_identifier_from_res_path_list(self):
        identifiers = [
            Parameter(target='Id',
                      source='response',
                      path='Container.Frobs[].Id')
        ]

        parent = mock.Mock()
        params = {}
        response = {'Container': {'Frobs': [{'Id': 'response-path'}]}}

        values = build_identifiers(identifiers, parent, params, response)

        self.assertEqual(values[0][1], ['response-path'],
                         'Identifier loaded from responsePath list not set')