Python falcon.HTTP_204 Examples

The following are 28 code examples of falcon.HTTP_204(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module falcon , or try the search function .
Example #1
Source File: test_metrics.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def test_send_metrics(self):
        request_body = {
            "name": "mon.fake_metric",
            "dimensions": {
                "hostname": "host0",
                "db": "vegeta"
            },
            "timestamp": 1405630174123,
            "value": 1.0,
            "value_meta": {
                "key1": "value1",
                "key2": "value2"
            }}
        response = self.simulate_request(path='/v2.0/metrics',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID,
                                                  'Content-Type': 'application/json'},
                                         body=json.dumps(request_body),
                                         method='POST')
        self.assertEqual(falcon.HTTP_204, response.status) 
Example #2
Source File: test_logs.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_payload_size_not_exceeded(self, _, __):
        _init_resource(self)

        max_log_size = 1000
        body = json.dumps({
            'message': 't' * (max_log_size - 100)
        })

        content_length = len(body)
        self.conf_override(max_log_size=max_log_size, group='service')

        res = self.simulate_request(
            path='/log/single',
            method='POST',
            headers={
                headers.X_ROLES.name: ROLES,
                headers.X_DIMENSIONS.name: '',
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=body
        )
        self.assertEqual(falcon.HTTP_204, res.status) 
Example #3
Source File: test_logs.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_delegate_cross_tenant_id_ok_role(self,
                                                          log_creator,
                                                          log_publisher):
        resource = _init_resource(self)
        resource._log_creator = log_creator
        resource._kafka_publisher = log_publisher

        res = self.simulate_request(
            path='/log/single',
            method='POST',
            query_string='tenant_id=1',
            headers={
                headers.X_ROLES.name: ROLES,
                headers.X_DIMENSIONS.name: 'a:1',
                'Content-Type': 'application/json',
                'Content-Length': '0'
            }
        )
        self.assertEqual(falcon.HTTP_204, res.status)

        self.assertEqual(1, log_publisher.send_message.call_count)
        self.assertEqual(1, log_creator.new_log.call_count)
        self.assertEqual(1, log_creator.new_log_envelope.call_count) 
Example #4
Source File: test_logs.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_empty_cross_tenant_id_ok_role(self,
                                                       log_creator,
                                                       kafka_publisher):
        logs_resource = _init_resource(self)
        logs_resource._log_creator = log_creator
        logs_resource._kafka_publisher = kafka_publisher

        res = self.simulate_request(
            path='/log/single',
            method='POST',
            headers={
                headers.X_ROLES.name: ROLES,
                headers.X_DIMENSIONS.name: 'a:1',
                'Content-Type': 'application/json',
                'Content-Length': '0'
            }
        )
        self.assertEqual(falcon.HTTP_204, res.status)

        self.assertEqual(1, kafka_publisher.send_message.call_count)
        self.assertEqual(1, log_creator.new_log.call_count)
        self.assertEqual(1, log_creator.new_log_envelope.call_count) 
Example #5
Source File: test_logs.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_empty_cross_tenant_id_wrong_role(self,
                                                          log_creator,
                                                          kafka_publisher):
        logs_resource = _init_resource(self)
        logs_resource._log_creator = log_creator
        logs_resource._kafka_publisher = kafka_publisher

        res = self.simulate_request(
            path='/log/single',
            method='POST',
            headers={
                headers.X_ROLES.name: ROLES,
                headers.X_DIMENSIONS.name: 'a:1',
                'Content-Type': 'application/json',
                'Content-Length': '0'
            }
        )
        self.assertEqual(falcon.HTTP_204, res.status)

        self.assertEqual(1, kafka_publisher.send_message.call_count)
        self.assertEqual(1, log_creator.new_log.call_count)
        self.assertEqual(1, log_creator.new_log_envelope.call_count) 
Example #6
Source File: test_logs_v3.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_send_unicode_messages(self, _):
        _init_resource(self)

        messages = [m['input'] for m in base.UNICODE_MESSAGES]
        v3_body, _ = _generate_v3_payload(messages=messages)
        payload = json.dumps(v3_body, ensure_ascii=False)
        content_length = len(payload.encode('utf8') if PY3 else payload)
        res = self.simulate_request(
            path='/logs',
            method='POST',
            headers={
                headers.X_ROLES.name: ROLES,
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, res.status) 
Example #7
Source File: test_logs_v3.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_empty_cross_tenant_id_ok_role(self,
                                                       bulk_processor):
        logs_resource = _init_resource(self)
        logs_resource._processor = bulk_processor

        v3_body, _ = _generate_v3_payload(1)
        payload = json.dumps(v3_body)
        content_length = len(payload)
        res = self.simulate_request(
            path='/logs',
            method='POST',
            headers={
                headers.X_ROLES.name: ROLES,
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, res.status)
        self.assertEqual(1, bulk_processor.send_message.call_count) 
Example #8
Source File: test_logs_v3.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_empty_cross_tenant_id_wrong_role(self,
                                                          bulk_processor):
        logs_resource = _init_resource(self)
        logs_resource._processor = bulk_processor

        v3_body, _ = _generate_v3_payload(1)
        payload = json.dumps(v3_body)
        content_length = len(payload)
        res = self.simulate_request(
            path='/logs',
            method='POST',
            headers={
                headers.X_ROLES.name: ROLES,
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, res.status)
        self.assertEqual(1, bulk_processor.send_message.call_count) 
Example #9
Source File: test_logs_v3.py    From monasca-log-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_cross_tenant_id(self, bulk_processor):
        logs_resource = _init_resource(self)
        logs_resource._processor = bulk_processor

        v3_body, v3_logs = _generate_v3_payload(1)
        payload = json.dumps(v3_body)
        content_length = len(payload)
        res = self.simulate_request(
            path='/logs',
            method='POST',
            query_string='tenant_id=1',
            headers={
                headers.X_ROLES.name: ROLES,
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, res.status)
        logs_resource._processor.send_message.assert_called_with(
            logs=v3_logs,
            global_dimensions=v3_body['dimensions'],
            log_tenant_id='1') 
Example #10
Source File: test_logs.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def test_should_send_unicode_messages(self, _):
        _init_resource(self)

        messages = [m['input'] for m in base.UNICODE_MESSAGES]
        body, _ = _generate_payload(messages=messages)
        payload = json.dumps(body, ensure_ascii=False)
        response = self.simulate_request(
            path='/logs',
            method='POST',
            headers={
                'X-Roles': ROLES,
                'Content-Type': 'application/json'
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, response.status) 
Example #11
Source File: test_logs.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_empty_cross_tenant_id_ok_role(self,
                                                       bulk_processor):
        logs_resource = _init_resource(self)
        logs_resource._processor = bulk_processor

        body, _ = _generate_payload(1)
        payload = json.dumps(body)
        content_length = len(payload)
        response = self.simulate_request(
            path='/logs',
            method='POST',
            headers={
                'X-Roles': ROLES,
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, response.status)
        self.assertEqual(1, bulk_processor.send_message.call_count) 
Example #12
Source File: test_logs.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_empty_cross_tenant_id_wrong_role(self,
                                                          bulk_processor):
        logs_resource = _init_resource(self)
        logs_resource._processor = bulk_processor

        body, _ = _generate_payload(1)
        payload = json.dumps(body)
        content_length = len(payload)
        response = self.simulate_request(
            path='/logs',
            method='POST',
            headers={
                'X-Roles': ROLES,
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, response.status)
        self.assertEqual(1, bulk_processor.send_message.call_count) 
Example #13
Source File: test_logs.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def test_should_pass_cross_tenant_id(self, bulk_processor):
        logs_resource = _init_resource(self)
        logs_resource._processor = bulk_processor

        body, logs = _generate_payload(1)
        payload = json.dumps(body)
        content_length = len(payload)
        response = self.simulate_request(
            path='/logs',
            method='POST',
            query_string='tenant_id=1',
            headers={
                'X_ROLES': ROLES,
                'Content-Type': 'application/json',
                'Content-Length': str(content_length)
            },
            body=payload
        )
        self.assertEqual(falcon.HTTP_204, response.status)
        logs_resource._processor.send_message.assert_called_with(
            logs=logs,
            global_dimensions=body['dimensions'],
            log_tenant_id='1') 
Example #14
Source File: app.py    From iris-relay with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def on_get(self, req, resp):
        token = req.get_param('token', True)
        data = {}
        for key in self.data_keys:
            data[key] = req.get_param(key, True)

        if not self.validate_token(token, data):
            raise falcon.HTTPForbidden('Invalid token for these given values', '')

        endpoint = self.config['iris']['hook']['gmail_one_click']

        try:
            result = self.iclient.post(endpoint, data)
        except MaxRetryError:
            logger.exception('Hitting iris-api failed for gmail oneclick')
        else:
            if result.status == 204:
                resp.status = falcon.HTTP_204
                return
            else:
                logger.error('Unexpected status code from api %s for gmail oneclick', result.status)

        raise falcon.HTTPInternalServerError('Internal Server Error', 'Invalid response from API') 
Example #15
Source File: health.py    From drydock with Apache License 2.0 5 votes vote down vote up
def get(self, req, resp):
        """
        Returns updated response with body if extended.
        """
        health_check = HealthCheck()
        # Test database connection
        try:
            now = self.state_manager.get_now()
            if now is None:
                raise Exception('None received from database for now()')
        except Exception as ex:
            hcm = HealthCheckMessage(
                msg='Unable to connect to database', error=True)
            health_check.add_detail_msg(msg=hcm)

        # Test MaaS connection
        try:
            task = self.orchestrator.create_task(
                action=hd_fields.OrchestratorAction.Noop)
            maas_validation = ValidateNodeServices(task, self.orchestrator,
                                                   self.state_manager)
            maas_validation.start()
            if maas_validation.task.get_status() == ActionResult.Failure:
                raise Exception('MaaS task failure')
        except Exception as ex:
            hcm = HealthCheckMessage(
                msg='Unable to connect to MaaS', error=True)
            health_check.add_detail_msg(msg=hcm)

        if self.extended:
            resp.body = json.dumps(health_check.to_dict())

        if health_check.is_healthy() and self.extended:
            resp.status = falcon.HTTP_200
        elif health_check.is_healthy():
            resp.status = falcon.HTTP_204
        else:
            resp.status = falcon.HTTP_503 
Example #16
Source File: health.py    From drydock with Apache License 2.0 5 votes vote down vote up
def get(self, req, resp):
        """
        Returns updated response with body if extended.
        """
        health_check = HealthCheck()
        # Test database connection
        try:
            now = self.state_manager.get_now()
            if now is None:
                raise Exception('None received from database for now()')
        except Exception:
            hcm = HealthCheckMessage(
                msg='Unable to connect to database', error=True)
            health_check.add_detail_msg(msg=hcm)

        # Test MaaS connection
        try:
            task = self.orchestrator.create_task(
                action=hd_fields.OrchestratorAction.Noop)
            maas_validation = ValidateNodeServices(task, self.orchestrator,
                                                   self.state_manager)
            maas_validation.start()
            if maas_validation.task.get_status() == ActionResult.Failure:
                raise Exception('MaaS task failure')
        except Exception:
            hcm = HealthCheckMessage(
                msg='Unable to connect to MaaS', error=True)
            health_check.add_detail_msg(msg=hcm)

        if self.extended:
            resp.body = json.dumps(health_check.to_dict())

        if health_check.is_healthy() and self.extended:
            resp.status = falcon.HTTP_200
        elif health_check.is_healthy():
            resp.status = falcon.HTTP_204
        else:
            resp.status = falcon.HTTP_503 
Example #17
Source File: test_health_controller.py    From armada with Apache License 2.0 5 votes vote down vote up
def test_get_health_status(self):
        """
        Validate that /api/v1.0/health returns 204.
        """
        result = self.app.simulate_get('/api/v1.0/health')
        self.assertEqual(result.status, falcon.HTTP_204) 
Example #18
Source File: test_health_controller.py    From armada with Apache License 2.0 5 votes vote down vote up
def test_get_health_status(self):
        """
        Validate that /api/v1.0/health returns 204.
        """
        result = self.app.simulate_get('/api/v1.0/health')
        self.assertEqual(result.status, falcon.HTTP_204) 
Example #19
Source File: test_clients.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_client_info_0['project_id'],
                                common.fake_client_info_0['client_id'])
        result = self.mock_req.body
        expected_result = {'client_id': common.fake_client_info_0['client_id']}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #20
Source File: test_actions.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_action_0['project_id'],
                                common.fake_action_0['action_id'])
        result = self.mock_req.body
        expected_result = {'action_id': common.fake_action_0['action_id']}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #21
Source File: logs.py    From monasca-log-api with Apache License 2.0 5 votes vote down vote up
def process_on_post_request(self, req, res):
        try:
            req.validate(self.SUPPORTED_CONTENT_TYPES)
            tenant_id = (req.project_id if req.project_id
                         else req.cross_project_id)

            log = self.get_log(request=req)
            envelope = self.get_envelope(
                log=log,
                tenant_id=tenant_id
            )
            if CONF.monitoring.enable:
                self._logs_size_gauge.send(name=None,
                                           value=int(req.content_length))
                self._logs_in_counter.increment()
        except Exception:
            # any validation that failed means
            # log is invalid and rejected
            if CONF.monitoring.enable:
                self._logs_rejected_counter.increment()
            raise

        self._kafka_publisher.send_message(envelope)

        res.status = falcon.HTTP_204
        res.add_link(
            target=str(_get_v3_link(req)),
            rel='current',  # [RFC5005]
            title='V3 Logs',
            type_hint='application/json'
        )
        res.append_header('DEPRECATED', 'true') 
Example #22
Source File: test_jobs.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_job_0_project_id,
                                common.fake_job_0_job_id)
        result = self.mock_req.body
        expected_result = {'job_id': common.fake_job_0_job_id}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #23
Source File: test_backups.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_data_0_wrapped_backup_metadata[
                                    'project_id'],
                                common.fake_data_0_backup_id)
        result = self.mock_req.body
        expected_result = {'backup_id': common.fake_data_0_backup_id}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #24
Source File: test_clients.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_client_info_0['client_id'])
        result = self.mock_req.body
        expected_result = {'client_id': common.fake_client_info_0['client_id']}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #25
Source File: test_actions.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_action_0['action_id'])
        result = self.mock_req.body
        expected_result = {'action_id': common.fake_action_0['action_id']}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #26
Source File: test_jobs.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_job_0_job_id)
        result = self.mock_req.body
        expected_result = {'job_id': common.fake_job_0_job_id}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #27
Source File: test_backups.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_data_0_backup_id)
        result = self.mock_req.body
        expected_result = {'backup_id': common.fake_data_0_backup_id}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result) 
Example #28
Source File: test_sessions.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_delete_removes_proper_data(self):
        self.resource.on_delete(self.mock_req, self.mock_req,
                                common.fake_session_0['session_id'])
        result = self.mock_req.body
        expected_result = {'session_id': common.fake_session_0['session_id']}
        self.assertEqual(falcon.HTTP_204, self.mock_req.status)
        self.assertEqual(expected_result, result)