Пример #1
0
    def test_should_return_version_json(self):
        self.resource.on_get(self.req, self.resp)

        parsed_body = jsonutils.loads(self.resp.body)

        self.assertTrue('v1' in parsed_body)
        self.assertEqual('current', parsed_body['v1'])
Пример #2
0
    def test_should_return_version_json(self):
        self.resource.on_get(self.req, self.resp)

        parsed_body = jsonutils.loads(self.resp.body)

        self.assertTrue('v1' in parsed_body)
        self.assertEqual('current', parsed_body['v1'])
Пример #3
0
 def get_token(self, tenant_id):
     if self.cache.cache_exists(tenant_id, CACHE_TOKEN):
         token_dict = jsonutils.loads(
             self.cache.cache_get(tenant_id, CACHE_TOKEN))
         token = load_token_from_dict(token_dict)
         return token
     return None
Пример #4
0
 def get_token(self, tenant_id):
     if self.cache.cache_exists(tenant_id, CACHE_TOKEN):
         token_dict = jsonutils.loads(
             self.cache.cache_get(tenant_id, CACHE_TOKEN))
         token = load_token_from_dict(token_dict)
         return token
     return None
Пример #5
0
 def get_config(self):
     if self.cache.cache_exists('worker_configuration', CACHE_CONFIG):
         config = jsonutils.loads(
             self.cache.cache_get('worker_configuration', CACHE_CONFIG))
         worker_config = WorkerConfiguration(**config)
         return worker_config
     return None
Пример #6
0
 def get_config(self):
     if self.cache.cache_exists('worker_configuration', CACHE_CONFIG):
         config = jsonutils.loads(
             self.cache.cache_get('worker_configuration', CACHE_CONFIG))
         worker_config = WorkerConfiguration(**config)
         return worker_config
     return None
Пример #7
0
    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)
Пример #8
0
    def get_tenant(self, tenant_id):
        if self.cache.cache_exists(tenant_id, CACHE_TENANT):
            tenant_dict = jsonutils.loads(
                self.cache.cache_get(tenant_id, CACHE_TENANT))
            tenant = load_tenant_from_dict(tenant_dict)
            return tenant

        return None
Пример #9
0
    def get_tenant(self, tenant_id):
        if self.cache.cache_exists(tenant_id, CACHE_TENANT):
            tenant_dict = jsonutils.loads(
                self.cache.cache_get(tenant_id, CACHE_TENANT))
            tenant = load_tenant_from_dict(tenant_dict)
            return tenant

        return None
Пример #10
0
    def test_returns_200_on_get(self):
        self.db_handler.find.return_value = [self.worker_dict]
        self.resource.on_get(self.req, self.resp)
        self.assertEquals(self.resp.status, falcon.HTTP_200)
        resp = jsonutils.loads(self.resp.body)
        status = resp['status'][0]

        for key in resp.keys():
            self.assertTrue(key in self.worker.get_status().keys())
Пример #11
0
    def test_returns_200_on_get(self):
        self.db_handler.find.return_value = [self.worker_dict]
        self.resource.on_get(self.req, self.resp)
        self.assertEquals(self.resp.status, falcon.HTTP_200)
        resp = jsonutils.loads(self.resp.body)
        status = resp['status'][0]

        for key in resp.keys():
            self.assertTrue(key in self.worker.get_status().keys())
Пример #12
0
    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)
Пример #13
0
    def test_should_return_token_json(self):
        with patch('meniscus.api.tenant.resources.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id)

        parsed_body = jsonutils.loads(self.resp.body)
        parsed_token = parsed_body['token']
        token_dict = self.token.format()
        for key in token_dict:
            self.assertEqual(parsed_token[key], token_dict[key])
Пример #14
0
    def test_should_return_token_json(self):
        with patch('meniscus.api.tenant.resources.tenant_util.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id)

        parsed_body = jsonutils.loads(self.resp.body)
        parsed_token = parsed_body['token']
        token_dict = self.token.format()
        for key in token_dict:
            self.assertEqual(parsed_token[key], token_dict[key])
Пример #15
0
    def test_returns_200_on_get(self):
        with patch('meniscus.data.model.worker_util.find_worker',
                   MagicMock(return_value=self.worker)):
            self.resource.on_get(self.req, self.resp, self.hostname)
            self.assertEquals(self.resp.status, falcon.HTTP_200)
            resp = jsonutils.loads(self.resp.body)
            status = resp['status']

            for key in resp.keys():
                self.assertTrue(key in self.worker.get_status().keys())
Пример #16
0
    def test_returns_202_on_post(self):
        with patch(
                'meniscus.api.coordinator.resources.worker_util.create_worker',
                MagicMock()):
            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)
Пример #17
0
    def test_should_return_producer_json_on_get(self):
        with patch('meniscus.api.tenant.resources.tenant_util.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id)

        parsed_body = jsonutils.loads(self.resp.body)

        self.assertTrue('event_producers'in parsed_body.keys())
        self.assertEqual(len(self.producers),
                         len(parsed_body['event_producers']))

        for producer in parsed_body['event_producers']:
            self.assertTrue(producer in [p.format() for p in self.producers])
Пример #18
0
    def test_should_return_tenant_json(self):
        with patch('meniscus.api.tenant.resources.tenant_util.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id)

        parsed_body = jsonutils.loads(self.resp.body)

        self.assertTrue('tenant' in parsed_body)
        parsed_tenant = parsed_body['tenant']
        tenant_dict = self.tenant.format()
        for key in tenant_dict:
            self.assertTrue(key in parsed_tenant)
            self.assertEqual(tenant_dict[key], parsed_tenant[key])
Пример #19
0
    def test_should_return_producer_json_on_get(self):
        with patch('meniscus.api.tenant.resources.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id)

        parsed_body = jsonutils.loads(self.resp.body)

        self.assertTrue('event_producers' in parsed_body.keys())
        self.assertEqual(len(self.producers),
                         len(parsed_body['event_producers']))

        for producer in parsed_body['event_producers']:
            self.assertTrue(producer in [p.format() for p in self.producers])
Пример #20
0
    def test_should_return_producer_json(self):
        with patch('meniscus.api.tenant.resources.tenant_util.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id,
                                 self.producer_id)

        parsed_body = jsonutils.loads(self.resp.body)
        parsed_producer = parsed_body['event_producer']
        producer_dict = [p.format() for p in self.producers
                         if p._id == self.producer_id][0]

        for key in producer_dict:
            self.assertEqual(producer_dict[key], parsed_producer[key])
Пример #21
0
    def test_should_return_tenant_json(self):
        with patch('meniscus.api.tenant.resources.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id)

        parsed_body = jsonutils.loads(self.resp.body)

        self.assertTrue('tenant' in parsed_body)
        parsed_tenant = parsed_body['tenant']
        tenant_dict = self.tenant.format()
        for key in tenant_dict:
            self.assertTrue(key in parsed_tenant)
            self.assertEqual(tenant_dict[key], parsed_tenant[key])
Пример #22
0
    def test_should_return_producer_json(self):
        with patch('meniscus.api.tenant.resources.find_tenant',
                   self.tenant_found):
            self.resource.on_get(self.req, self.resp, self.tenant_id,
                                 self.producer_id)

        parsed_body = jsonutils.loads(self.resp.body)
        parsed_producer = parsed_body['event_producer']
        producer_dict = [
            p.format() for p in self.producers if p._id == self.producer_id
        ][0]

        for key in producer_dict:
            self.assertEqual(producer_dict[key], parsed_producer[key])
Пример #23
0
 def test_should_return_200(self):
     self.db_handler.find_one.return_value = self.worker_dict
     self.db_handler.find.return_value = self.downstream
     self.resource.on_get(self.req, self.resp, self.worker_id)
     self.assertEquals(self.resp.status, falcon.HTTP_200)
     resp_body = jsonutils.loads(self.resp.body)
     routes = resp_body['routes']
     for route in routes:
         self.assertTrue('service_domain' in route)
         self.assertTrue('targets' in route)
         targets = route['targets']
         for worker in targets:
             self.assertTrue('worker_id' in worker)
             self.assertTrue('ip_address_v4' in worker)
             self.assertTrue('ip_address_v6' in worker)
             self.assertTrue('status' in worker)
Пример #24
0
def load_body(req, required=[]):
    """
    Helper function for loading an HTTP request body from JSON into a
    Python dictionary
    """
    try:
        raw_json = req.stream.read()

    except Exception:
        abort(falcon.HTTP_500, 'Read Error')

    try:
        parsed_body = jsonutils.loads(raw_json)
        return parsed_body
    except ValueError as ve:
        abort(falcon.HTTP_400, 'Malformed JSON')
Пример #25
0
    return jsonutils.dumps(body)


def load_body(req, validator=None):
    """
    Helper function for loading an HTTP request body from JSON into a
    Python dictionary
    """
    try:
        raw_json = req.stream.read()
    except Exception, ex:
        _LOG.debug(ex)
        abort(falcon.HTTP_500, 'Read Error')

    try:
        obj = jsonutils.loads(raw_json)
    except ValueError, ex:
        _LOG.debug('Malformed JSON: {0}'.format(raw_json))
        abort(falcon.HTTP_400, 'Malformed JSON')

    if validator:
        validation_result = validator.validate(obj)
        if not validation_result[0]:
            _LOG.debug('JSON schema validation failed: {0}'.format(obj))
            abort(falcon.HTTP_400, validation_result[1].message)

    return obj


def handle_api_exception(operation_name=None):
    """
Пример #26
0
    return jsonutils.dumps(body)


def load_body(req, validator=None):
    """
    Helper function for loading an HTTP request body from JSON into a
    Python dictionary
    """
    try:
        raw_json = req.stream.read()
    except Exception, ex:
        _LOG.debug(ex)
        abort(falcon.HTTP_500, 'Read Error')

    try:
        obj = jsonutils.loads(raw_json)
    except ValueError, ex:
        _LOG.debug('Malformed JSON: {0}'.format(raw_json))
        abort(falcon.HTTP_400, 'Malformed JSON')

    if validator:
        validation_result = validator.validate(obj)
        if not validation_result[0]:
            _LOG.debug('JSON schema validation failed: {0}'.format(obj))
            abort(falcon.HTTP_400, validation_result[1].message)

    return obj


def handle_api_exception(operation_name=None):
    """
Пример #27
0
 def test_should_return_version_json(self):
     self.resource.on_get(self.req, self.resp)
     parsed_body = jsonutils.loads(self.resp.body)
     self.assertTrue("v1" in parsed_body)
     self.assertEqual("current", parsed_body["v1"])
Пример #28
0
 def get_routes(self):
     if self.cache.cache_exists('routes', CACHE_CONFIG):
         pipeline_workers = jsonutils.loads(
             self.cache.cache_get('routes', CACHE_CONFIG))
         return pipeline_workers
     return None