示例#1
0
class WhenTestingWorkerRegistrationOnPost(unittest.TestCase):
    def setUp(self):

        self.db_handler = MagicMock()
        self.resource = WorkerRegistrationResource(self.db_handler)
        self.body = {'worker_registration':
                     WorkerRegistration('correlation').format()}
        self.body_bad_personality = {'worker_registration':
                                     WorkerRegistration(
                                         'bad_personality').format()}
        self.body_bad = {'worker_registration': 'bad_registration'}
        self.registration = jsonutils.dumps(
            {'worker_registration':
             WorkerRegistration('correlation').format()})
        self.req = MagicMock()
        self.req.stream.read.return_value = self.registration
        self.resp = MagicMock()

    def test_returns_202_on_post(self):
        self.resource.on_post(self.req, self.resp)
        self.assertEquals(self.resp.status, falcon.HTTP_202)

        resp_body = jsonutils.loads(self.resp.body)
        self.assertTrue('personality_module' in resp_body)
        self.assertTrue('worker_id' in resp_body)
        self.assertTrue('worker_token' in resp_body)
示例#2
0
class WhenTestingWorkerRegistrationOnPost(testing.TestBase):

    def before(self):

        self.db_handler = MagicMock()
        self.resource = WorkerRegistrationResource(self.db_handler)
        self.body = {'worker_registration':
                     WorkerRegistration('worker').format()}
        self.body_bad_personality = {'worker_registration':
                                     WorkerRegistration(
                                         'bad_personality').format()}

        self.body_bad = {'worker_registration': 'bad_registration'}
        self.req = MagicMock()
        self.req.content_type = 'application/json'
        self.req.stream.read.return_value = jsonutils.dumps(self.body)
        self.resp = MagicMock()
        self.test_route = '/v1/pairing'
        self.api.add_route(self.test_route, self.resource)

    def test_returns_400_for_bad_personality(self):
        self.simulate_request(
            self.test_route,
            method='POST',
            headers={
                'content-type': 'application/json',
            },
            body=jsonutils.dumps(self.body_bad_personality))
        self.assertEqual(falcon.HTTP_400, self.srmock.status)

    def test_returns_415_for_unsupported_content_type(self):
        self.simulate_request(
            self.test_route,
            method='POST',
            headers={
                'content-type': 'application/xml',
            },
            body=jsonutils.dumps(self.body))
        self.assertEqual(falcon.HTTP_415, self.srmock.status)

    def test_returns_202_for_registered_worker(self):
        self.simulate_request(
            self.test_route,
            method='POST',
            headers={
                'content-type': 'application/json',
            },
            body=jsonutils.dumps(self.body))
        self.assertEqual(falcon.HTTP_202, self.srmock.status)

    def test_returns_202_on_post(self):
        self.resource.on_post(self.req, self.resp)
        self.assertEquals(self.resp.status, falcon.HTTP_202)

        resp_body = jsonutils.loads(self.resp.body)
        worker_identity = resp_body['worker_identity']
        self.assertTrue('personality_module' in worker_identity)
        self.assertTrue('worker_id' in worker_identity)
        self.assertTrue('worker_token' in worker_identity)
示例#3
0
文件: app.py 项目: thomdixon/meniscus
def start_up():
    """
    This persona hosts resources from a few different APIs in order
    to facilitate the bootstrap buildout of a brand new meniscus grid. This
    persona effectively allows the new worker to pair with itself.
    """

    #Datastore adapter/session manager
    datastore = datasource_handler(COORDINATOR_DB)

    # Resources
    versions = VersionResource()
    configuration = PairingConfigurationResource()
    worker_registration = WorkerRegistrationResource(datastore)
    worker_status = WorkerStatusResource(datastore)

    # Routing
    application = api = falcon.API()

    # Pairing Routing
    api.add_route('/', versions)
    api.add_route('/v1/pairing/configure', configuration)

    # Worker Registration Routing
    api.add_route('/v1/pairing', worker_registration)
    api.add_route('/v1/worker/{worker_id}/status', worker_status)

    return application
示例#4
0
    def before(self):

        self.db_handler = MagicMock()
        self.resource = WorkerRegistrationResource(self.db_handler)
        self.body = {'worker_registration':
                     WorkerRegistration('worker').format()}
        self.body_bad_personality = {'worker_registration':
                                     WorkerRegistration(
                                         'bad_personality').format()}

        self.body_bad = {'worker_registration': 'bad_registration'}
        self.req = MagicMock()
        self.req.content_type = 'application/json'
        self.req.stream.read.return_value = jsonutils.dumps(self.body)
        self.resp = MagicMock()
        self.test_route = '/v1/pairing'
        self.api.add_route(self.test_route, self.resource)
示例#5
0
    def setUp(self):

        self.db_handler = MagicMock()
        self.resource = WorkerRegistrationResource(self.db_handler)
        self.body = {'worker_registration':
                     WorkerRegistration('correlation').format()}
        self.body_bad_personality = {'worker_registration':
                                     WorkerRegistration(
                                         'bad_personality').format()}
        self.body_bad = {'worker_registration': 'bad_registration'}
        self.registration = jsonutils.dumps(
            {'worker_registration':
             WorkerRegistration('correlation').format()})
        self.req = MagicMock()
        self.req.stream.read.return_value = self.registration
        self.resp = MagicMock()
示例#6
0
    def before(self):

        self.db_handler = MagicMock()
        self.resource = WorkerRegistrationResource()
        self.body = {'worker_registration':
                     WorkerRegistration('worker').format()}
        self.body_bad_personality = {'worker_registration':
                                     WorkerRegistration(
                                         'bad_personality').format()}

        self.body_bad = {'worker_registration': 'bad_registration'}
        self.req = MagicMock()
        self.req.content_type = 'application/json'
        self.req.stream.read.return_value = jsonutils.dumps(self.body)
        self.resp = MagicMock()
        self.test_route = '/v1/pairing'
        self.api.add_route(self.test_route, self.resource)
示例#7
0
def start_up():
    #Common Resource(s)
    versions = VersionResource()

    #Datastore adapter/session manager
    datastore = datasource_handler(COORDINATOR_DB)

    #Coordinator Resources
    worker_registration = WorkerRegistrationResource(datastore)
    workers_status = WorkersStatusResource(datastore)
    worker_status = WorkerStatusResource(datastore)

    #Tenant Resources
    tenant = TenantResource(datastore)
    user = UserResource(datastore)
    event_producers = EventProducersResource(datastore)
    event_producer = EventProducerResource(datastore)
    token = TokenResource(datastore)

    # Create API
    application = api = falcon.API()

    # Common Routing
    api.add_route('/', versions)

    # Coordinator Routing
    api.add_route('/v1/pairing', worker_registration)

    api.add_route('/v1/worker/{worker_id}/status', worker_status)
    api.add_route('/v1/status', workers_status)

    # Tenant Routing
    api.add_route('/v1/tenant', tenant)
    api.add_route('/v1/tenant/{tenant_id}', user)
    api.add_route('/v1/tenant/{tenant_id}/producers', event_producers)
    api.add_route('/v1/tenant/{tenant_id}/producers/{event_producer_id}',
                  event_producer)

    api.add_route('/v1/tenant/{tenant_id}/token', token)

    return application
示例#8
0
文件: app.py 项目: thomdixon/meniscus
from meniscus.api.tenant.resources import TokenResource
from meniscus.api.version.resources import VersionResource
from meniscus.data.datastore import COORDINATOR_DB, datasource_handler
from meniscus import env
from meniscus.openstack.common import log


log.setup('meniscus')
_LOG = env.get_logger(__name__)

#Common Resource(s)
versions = VersionResource()

#Coordinator Resources
db_handler = datasource_handler(COORDINATOR_DB)
worker_registration = WorkerRegistrationResource(db_handler)
workers_status = WorkersStatusResource(db_handler)
worker_status = WorkerStatusResource(db_handler)

#Tenant Resources
tenant = TenantResource(db_handler)
user = UserResource(db_handler)
event_producers = EventProducersResource(db_handler)
event_producer = EventProducerResource(db_handler)
token = TokenResource(db_handler)

# Create API
application = api = falcon.API()

# Common Routing
api.add_route('/', versions)