class TestTextPlainRendering(unittest.TestCase):
    """
    Test the text / plain rendering. This is simple since it's derived from
    text/occi rendering.
    """

    registry = NonePersistentRegistry()

    def setUp(self):
        self.rendering = TextPlainRendering(self.registry)

    def test_data_routines_for_sanity(self):
        """
        Test if set and get data are overwritten and work properly
        """
        headers = {}
        body = (
            "Category: foo\n"
            "Category: foo,bar\n"
            "Link: bar\n"
            "Link: foo,bar\n"
            "X-OCCI-Location: foo,bar\n"
            "X-OCCI-Location: bar\n"
            "X-OCCI-Attribute: foo\n"
            "X-OCCI-Attribute: bar,foo\n"
        )
        data = self.rendering.get_data(headers, body)
        headers, body = self.rendering.set_data(data)
        self.assertTrue(body.count("Category") == 3)
        self.assertTrue(body.count("Link") == 3)
        self.assertTrue(body.count("X-OCCI-Attribute") == 3)
        self.assertTrue(body.count("X-OCCI-Location") == 3)
示例#2
0
class TestTextPlainRendering(unittest.TestCase):
    '''
    Test the text / plain rendering. This is simple since it's derived from
    text/occi rendering.
    '''

    registry = NonePersistentRegistry()

    def setUp(self):
        self.rendering = TextPlainRendering(self.registry)

    def test_data_routines_for_sanity(self):
        '''
        Test if set and get data are overwritten and work properly
        '''
        headers = {}
        body = 'Category: foo\n' \
            'Category: foo,bar\n' \
            'Link: bar\n' \
            'Link: foo,bar\n' \
            'X-OCCI-Location: foo,bar\n' \
            'X-OCCI-Location: bar\n' \
            'X-OCCI-Attribute: foo\n' \
            'X-OCCI-Attribute: bar,foo\n'
        data = self.rendering.get_data(headers, body)
        headers, body = self.rendering.set_data(data)
        self.assertTrue(body.count('Category') == 3)
        self.assertTrue(body.count('Link') == 3)
        self.assertTrue(body.count('X-OCCI-Attribute') == 3)
        self.assertTrue(body.count('X-OCCI-Location') == 3)
示例#3
0
文件: service.py 项目: engjoy/pyssf
    def __init__(self, registry=None):

        if registry is None:
            self.registry = NonePersistentRegistry()
        elif isinstance(registry, Registry):
            self.registry = registry
        else:
            raise AttributeError('Registry needs to derive from abstract' \
                                 ' class \'Registry\'')

        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))
        self.registry.set_renderer('text/plain',
                                   TextPlainRendering(self.registry))
        self.registry.set_renderer('text/uri-list',
                                   TextUriListRendering(self.registry))
        self.registry.set_renderer('text/html', HTMLRendering(self.registry))

        application = tornado.web.Application([
            (r"/-/", QueryHandler, dict(registry=self.registry)),
            (r"/.well-known/org/ogf/occi/-/", QueryHandler,
             dict(registry=self.registry)),
            (r"(.*)/", CollectionHandler, dict(registry=self.registry)),
            (r"(.*)", ResourceHandler, dict(registry=self.registry)),
        ])

        self.http_server = tornado.httpserver.HTTPServer(application)
示例#4
0
    def setUp(self):
        self.registry.set_hostname('http://127.0.0.1')
        self.app = Application([(r"(.*)/", CollectionWrapper)])

        self.registry.set_renderer('text/plain',
                                   TextPlainRendering(self.registry))
        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))
        self.registry.set_renderer('text/uri-list',
                                   TextUriListRendering(self.registry))

        self.mixin = Mixin('foo', 'mystuff')

        self.compute = Resource('/compute/1', COMPUTE, [])
        self.compute.attributes = {'foo2': 'bar2'}
        self.network = Resource('/network/1', NETWORK, [IPNETWORK])
        self.network_interface = Link('/network/interface/1', NETWORKINTERFACE,
                                      [IPNETWORKINTERFACE], self.compute,
                                      self.network)

        self.registry.set_backend(COMPUTE, SimpleComputeBackend())
        self.registry.set_backend(NETWORK, KindBackend())
        self.registry.set_backend(self.mixin, MixinBackend())
        self.registry.set_backend(START, SimpleComputeBackend())

        self.registry.add_resource(self.compute.identifier, self.compute)
        self.registry.add_resource(self.network.identifier, self.network)
        self.registry.add_resource(self.network_interface.identifier,
                                   self.network_interface)
示例#5
0
    def setUp(self):
        self.app = Application([(r"(.*)", ResourceWrapper)])
        self.registry.set_renderer('text/plain',
                                   TextPlainRendering(self.registry))
        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))

        self.registry.set_backend(COMPUTE, SimpleComputeBackend())
        self.registry.set_backend(NETWORK, KindBackend())
        self.registry.set_backend(NETWORKINTERFACE, KindBackend())
        self.registry.set_backend(START, SimpleComputeBackend())

        self.compute = Resource('/compute/1', COMPUTE, [])
        self.network = Resource('/network/1', NETWORK, [IPNETWORK])

        self.registry.add_resource('/compute/1', self.compute)
        self.registry.add_resource('/network/1', self.network)
 def setUp(self):
     self.rendering = TextPlainRendering(self.registry)
示例#7
0
 def setUp(self):
     self.rendering = TextPlainRendering(self.registry)