コード例 #1
0
ファイル: test_http_handler.py プロジェクト: occi/occi-py
class DiscoveryHandlerTestCase(HandlerTestCaseBase):
    def setUp(self):
        super(DiscoveryHandlerTestCase, self).setUp()
        self.handler = DiscoveryHandler(self.backend, translator=self.translator)

    def test_get(self):
        headers = [('Accept', 'text/occi')]
        request = HttpRequest(headers, '')
        response = self.handler.get(request)
        self.assertEqual(response.status, 200)
        self.assertEqual(response.body, '')
        self.assertEqual(response.headers[0], ('Content-Type', 'text/occi'))
        self.assertEqual(len(response.headers), len(self.backend.registry.all()) + 1)

        expected_headers = []
        expected_headers.append(('Category', 'entity; scheme="http://schemas.ogf.org/occi/core#"; class="kind"; title="Entity type"; attributes="occi.core.id{immutable} occi.core.title"'))
        expected_headers.append(('Category', 'resource; scheme="http://schemas.ogf.org/occi/core#"; class="kind"; title="Resource type"; rel="http://schemas.ogf.org/occi/core#entity"; attributes="occi.core.summary"'))
        expected_headers.append(('Category', 'link; scheme="http://schemas.ogf.org/occi/core#"; class="kind"; title="Link type"; rel="http://schemas.ogf.org/occi/core#entity"; attributes="occi.core.source{required} occi.core.target{required}"'))
        expected_headers.append(('Category', 'compute; scheme="http://schemas.ogf.org/occi/infrastructure#"; class="kind"; title="Compute Resource"; rel="http://schemas.ogf.org/occi/core#resource"; attributes="%s"; actions="%s"; location="/api/compute/"' % (
            'occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.speed occi.compute.memory occi.compute.state{immutable}',
            ' '.join([str(cat) for cat in ComputeKind.actions]))))

        self._verify_headers(response.headers[1:5], expected_headers)

    def test_post(self):
        location='my_stuff/'
        path = self.BASE_URL + '/' + location
        headers = [('Content-Type', 'text/occi')]
        headers.append(('Category', 'my_stuff; scheme="http://example.com/occi/custom#"; class=mixin; location=%s' % path))
        headers.append(('Category', 'taggy; scheme="http://example.com/occi/custom#"; class=mixin; location=taggy/'))
        request = HttpRequest(headers, '')
        response = self.handler.post(request)
        self.assertEqual(response.body, 'OK')
        self.assertEqual(response.status, 200)
        self.assertEqual(self.backend.registry.lookup_location(location),
                'http://example.com/occi/custom#my_stuff')
        self.assertEqual(self.backend.registry.lookup_location('taggy/'),
                'http://example.com/occi/custom#taggy')

    def test_delete(self):
        self.test_post()
        headers = [('Content-Type', 'text/occi')]
        headers.append(('Category', 'taggy; scheme="http://example.com/occi/custom#"'))
        request = HttpRequest(headers, '')
        response = self.handler.delete(request)
        self.assertEqual(response.body, 'OK')
        self.assertEqual(response.status, 200)
        self.assertEqual(self.backend.registry.lookup_location('my_stuff/'),
                'http://example.com/occi/custom#my_stuff')
        self.assertEqual(self.backend.registry.lookup_location('taggy/'), None)
コード例 #2
0
    def __init__(self, *args, **kwargs):
        super(TornadoHttpServer, self).__init__(*args, **kwargs)

        self.application = tornado.web.Application([
            (self.base_path + r'/*/-/', TornadoRequestHandler,
             dict(handler=DiscoveryHandler(self.backend,
                                           translator=self.translator))),
            (self.base_path + r'/.well-known/org/ogf/occi/-/',
             TornadoRequestHandler,
             dict(handler=DiscoveryHandler(self.backend,
                                           translator=self.translator))),
            (self.base_path + r'/', TornadoRequestHandler,
             dict(handler=CollectionHandler(self.backend,
                                            translator=self.translator),
                  args=[''])),
            (self.base_path + r'/(.+/)', TornadoRequestHandler,
             dict(handler=CollectionHandler(self.backend,
                                            translator=self.translator))),
            (self.base_path + r'/(.+[^/])', TornadoRequestHandler,
             dict(handler=EntityHandler(self.backend,
                                        translator=self.translator))),
        ])
コード例 #3
0
ファイル: test_http_handler.py プロジェクト: nyren/occi-py
 def setUp(self):
     super(DiscoveryHandlerTestCase, self).setUp()
     self.handler = DiscoveryHandler(self.backend, translator=self.translator)
コード例 #4
0
 def setUp(self):
     super(DiscoveryHandlerTestCase, self).setUp()
     self.handler = DiscoveryHandler(self.backend,
                                     translator=self.translator)
コード例 #5
0
class DiscoveryHandlerTestCase(HandlerTestCaseBase):
    def setUp(self):
        super(DiscoveryHandlerTestCase, self).setUp()
        self.handler = DiscoveryHandler(self.backend,
                                        translator=self.translator)

    def test_get(self):
        headers = [('Accept', 'text/occi')]
        request = HttpRequest(headers, '')
        response = self.handler.get(request)
        self.assertEqual(response.status, 200)
        self.assertEqual(response.body, '')
        self.assertEqual(response.headers[0],
                         ('Content-Type', 'text/occi; charset=utf-8'))
        self.assertEqual(len(response.headers),
                         len(self.backend.registry.all()) + 1)

        expected_headers = []
        expected_headers.append((
            'Category',
            'entity; scheme="http://schemas.ogf.org/occi/core#"; class="kind"; title="Entity type"; attributes="occi.core.id{immutable} occi.core.title"'
        ))
        expected_headers.append((
            'Category',
            'resource; scheme="http://schemas.ogf.org/occi/core#"; class="kind"; title="Resource type"; rel="http://schemas.ogf.org/occi/core#entity"; attributes="occi.core.summary"'
        ))
        expected_headers.append((
            'Category',
            'link; scheme="http://schemas.ogf.org/occi/core#"; class="kind"; title="Link type"; rel="http://schemas.ogf.org/occi/core#entity"; attributes="occi.core.source{required} occi.core.target{required}"'
        ))
        expected_headers.append((
            'Category',
            'compute; scheme="http://schemas.ogf.org/occi/infrastructure#"; class="kind"; title="Compute Resource"; rel="http://schemas.ogf.org/occi/core#resource"; attributes="%s"; actions="%s"; location="/api/compute/"'
            %
            ('occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.speed occi.compute.memory occi.compute.state{immutable}',
             ' '.join([str(cat) for cat in ComputeKind.actions]))))

        self._verify_headers(response.headers[1:5], expected_headers)

    def test_get_filter(self):
        request_headers = [('Accept', 'text/plain')]
        request_headers.append(('Content-Type', 'text/occi'))
        request_headers.append((
            'Category',
            'storage; scheme="http://schemas.ogf.org/occi/infrastructure#"; class="kind"'
        ))
        request = HttpRequest(request_headers, '')
        response = self.handler.get(request)
        self.assertEqual(response.status, 200)
        self.assertEqual(response.headers[0],
                         ('Content-Type', 'text/plain; charset=utf-8'))

        expected_body = []
        expected_body.append(
            self._category_header(StorageKind) +
            '; rel="http://schemas.ogf.org/occi/core#resource"' +
            '; attributes="%s"; actions="%s"; location="%s"' %
            ('occi.storage.size{required} occi.storage.state{immutable}',
             ' '.join([str(cat)
                       for cat in StorageKind.actions]), '/api/storage/'))
        self._verify_body(response.body, expected_body)

    def test_post(self):
        location = 'my_stuff/'
        path = self.BASE_URL + '/' + location
        headers = [('Content-Type', 'text/occi; charset=utf-8')]
        headers.append((
            'Category',
            'my_stuff; scheme="http://example.com/occi/custom#"; class=mixin; location=%s'
            % path))
        headers.append((
            'Category',
            'taggy; scheme="http://example.com/occi/custom#"; class=mixin; location=taggy/'
        ))
        request = HttpRequest(headers, '')
        response = self.handler.post(request)
        self.assertEqual(response.body, 'OK')
        self.assertEqual(response.status, 200)
        self.assertEqual(self.backend.registry.lookup_location(location),
                         'http://example.com/occi/custom#my_stuff')
        self.assertEqual(self.backend.registry.lookup_location('taggy/'),
                         'http://example.com/occi/custom#taggy')

    def test_delete(self):
        self.test_post()
        headers = [('Content-Type', 'text/occi; charset=utf-8')]
        headers.append(
            ('Category', 'taggy; scheme="http://example.com/occi/custom#"'))
        request = HttpRequest(headers, '')
        response = self.handler.delete(request)
        self.assertEqual(response.body, 'OK')
        self.assertEqual(response.status, 200)
        self.assertEqual(self.backend.registry.lookup_location('my_stuff/'),
                         'http://example.com/occi/custom#my_stuff')
        self.assertEqual(self.backend.registry.lookup_location('taggy/'), None)