Example #1
0
    def test_get_entity_list_xml(self):
        entity_list = []
        expected_list_xml = \
            '<b:entities xmlns:b="http://testnamespace" \
xmlns:atom="http://www.w3.org/2005/Atom"><b:entity type="" id="0">\
<atom:link href="http://localhost:8080/v2/entities/0" rel="self"/>\
<atom:link href="http://localhost:8080/entities/0" rel="bookmark"/></b:entity>\
<b:entity type="" id="1">\
<atom:link href="http://localhost:8080/v2/entities/1" rel="self"/>\
<atom:link href="http://localhost:8080/entities/1" rel="bookmark"/>\
</b:entity><atom:link href="http://markerlink" rel="next"/></b:entities>'

        for i in range(2):
            href = 'http://localhost:8080/v2/entities/' + str(i)
            bookmark = 'http://localhost:8080/entities/' + str(i)
            entdict = {
                'id':
                str(i),
                'type':
                None,
                'links': [{
                    'rel': 'self',
                    'href': href
                }, {
                    'rel': 'bookmark',
                    'href': bookmark
                }],
            }
            entity_list.append(entdict)
        entities_dict = dict(entities=entity_list)
        entities_dict['entities_links'] = [{
            'rel': 'next',
            'href': 'http://markerlink'
        }]
        self.assertEquals(
            util.get_entity_list_xml(entities_dict, {
                'b': 'http://testnamespace',
                'atom': constants.XMLNS_ATOM
            }, 'entities', 'entity', 'b'), expected_list_xml)
        try:
            util.get_entity_list_xml({'a': 23, 'b': 23}, None, None, None)
        except Exception, inst:
            self.assertTrue(isinstance(inst, LookupError))
Example #2
0
    def test_get_entity_list_xml(self):
        entity_list = []
        expected_list_xml = \
            '<b:entities xmlns:b="http://testnamespace" \
xmlns:atom="http://www.w3.org/2005/Atom"><b:entity type="" id="0">\
<atom:link href="http://localhost:8080/v2/entities/0" rel="self"/>\
<atom:link href="http://localhost:8080/entities/0" rel="bookmark"/></b:entity>\
<b:entity type="" id="1">\
<atom:link href="http://localhost:8080/v2/entities/1" rel="self"/>\
<atom:link href="http://localhost:8080/entities/1" rel="bookmark"/>\
</b:entity><atom:link href="http://markerlink" rel="next"/></b:entities>'

        for i in range(2):
            href = 'http://localhost:8080/v2/entities/' + str(i)
            bookmark = 'http://localhost:8080/entities/' + str(i)
            entdict = {'id': str(i), 'type': None,
                       'links': [{'rel': 'self', 'href': href},
                       {'rel': 'bookmark', 'href': bookmark}],
                       }
            entity_list.append(entdict)
        entities_dict = dict(entities=entity_list)
        entities_dict['entities_links'] = [
            {
                'rel': 'next',
                'href': 'http://markerlink'
            }
        ]
        self.assertEquals(util.get_entity_list_xml(entities_dict,
                          {'b': 'http://testnamespace',
                          'atom': constants.XMLNS_ATOM}, 'entities',
                          'entity', 'b'), expected_list_xml)
        try:
            util.get_entity_list_xml({'a': 23, 'b': 23}, None, None,
                                     None)
        except Exception, inst:
            self.assertTrue(isinstance(inst, LookupError))
Example #3
0
        entities_dict['entities_links'] = [
            {
                'rel': 'next',
                'href': 'http://markerlink'
            }
        ]
        self.assertEquals(util.get_entity_list_xml(entities_dict,
                          {'b': 'http://testnamespace',
                          'atom': constants.XMLNS_ATOM}, 'entities',
                          'entity', 'b'), expected_list_xml)
        try:
            util.get_entity_list_xml({'a': 23, 'b': 23}, None, None,
                                     None)
        except Exception, inst:
            self.assertTrue(isinstance(inst, LookupError))
        self.assertEquals(util.get_entity_list_xml(None, None, None,
                          None), '')
        self.assertEquals(util.get_entity_list_xml({}, None, None,
                          None), '')
        self.assertEquals(util.get_entity_list_xml({'abcd': [None]},
                          None, 'abcd', None), '<abcd/>')

    def test_get_query_fields(self):
        req = \
            Request.blank('/test?fields=a,b&fields=utilization&fields=')
        self.assertEquals(util.get_query_fields(req), ['a', 'b',
                          'utilization'])

    def test_get_select_elements_xml(self):
        input_xml = \
            '<outer xmlns="http://space/noprefix"><a><sub>32</sub></a>\
<b>83</b><c>32</c></outer>'
Example #4
0
            entity_list.append(entdict)
        entities_dict = dict(entities=entity_list)
        entities_dict['entities_links'] = [{
            'rel': 'next',
            'href': 'http://markerlink'
        }]
        self.assertEquals(
            util.get_entity_list_xml(entities_dict, {
                'b': 'http://testnamespace',
                'atom': constants.XMLNS_ATOM
            }, 'entities', 'entity', 'b'), expected_list_xml)
        try:
            util.get_entity_list_xml({'a': 23, 'b': 23}, None, None, None)
        except Exception, inst:
            self.assertTrue(isinstance(inst, LookupError))
        self.assertEquals(util.get_entity_list_xml(None, None, None, None), '')
        self.assertEquals(util.get_entity_list_xml({}, None, None, None), '')
        self.assertEquals(
            util.get_entity_list_xml({'abcd': [None]}, None, 'abcd', None),
            '<abcd/>')

    def test_get_query_fields(self):
        req = \
            Request.blank('/test?fields=a,b&fields=utilization&fields=')
        self.assertEquals(util.get_query_fields(req),
                          ['a', 'b', 'utilization'])

    def test_get_select_elements_xml(self):
        input_xml = \
            '<outer xmlns="http://space/noprefix"><a><sub>32</sub></a>\
<b>83</b><c>32</c></outer>'