def test_create_event_producer(self):
     self.ds_handler.next_sequence_value = MagicMock(
         return_value=self.producer_id)
     ttl_create_mapping_call = MagicMock()
     save_tenant_call = MagicMock()
     with patch(
             'meniscus.data.model.tenant_util._db_handler',
             self.ds_handler), \
         patch(
             'meniscus.data.model.tenant_util.'
             'mapping_tasks.create_ttl_mapping.delay',
             ttl_create_mapping_call), \
         patch(
             'meniscus.data.model.tenant_util.save_tenant',
             save_tenant_call):
         new_producer_id = tenant_util.create_event_producer(
             self.tenant_obj,
             self.event_producer.name,
             self.event_producer.pattern,
             self.event_producer.durable,
             self.event_producer.encrypted,
             self.event_producer.sinks
         )
         save_tenant_call.assert_called_once_with(self.tenant_obj)
         ttl_create_mapping_call.assert_called_once_with(
             tenant_id=self.tenant_obj.tenant_id,
             producer_pattern=self.event_producer.pattern)
         self.assertEqual(new_producer_id, self.producer_id)
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        Create a a new event Producer for a specified Tenant
        when an HTTP Post is received
        """
        body = validated_body['event_producer']

        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        event_producer_name = body['name']
        event_producer_pattern = body['pattern']

        #if durable or encrypted aren't specified, set to False
        if 'durable' in body.keys():
            event_producer_durable = body['durable']
        else:
            event_producer_durable = False

        if 'encrypted' in body.keys():
            event_producer_encrypted = body['encrypted']
        else:
            event_producer_encrypted = False

        if 'sinks' in body.keys():
            event_producer_sinks = body['sinks']
        else:
            event_producer_sinks = None

        # Check if the tenant already has an event producer with this name
        producer = tenant_util.find_event_producer(
            tenant, producer_name=event_producer_name)
        if producer:
            api.abort(
                falcon.HTTP_400,
                'Event producer with name {0} already exists with id={1}.'
                .format(producer.name, producer.get_id()))

        # Create the new profile for the host
        producer_id = tenant_util.create_event_producer(
            tenant,
            event_producer_name,
            event_producer_pattern,
            event_producer_durable,
            event_producer_encrypted,
            event_producer_sinks)

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/producers/{1}'
                        .format(tenant_id, producer_id))
Exemple #3
0
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        Create a a new event Producer for a specified Tenant
        when an HTTP Post is received
        """
        body = validated_body['event_producer']

        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        event_producer_name = body['name']
        event_producer_pattern = body['pattern']

        #if durable or encrypted aren't specified, set to False
        if 'durable' in body.keys():
            event_producer_durable = body['durable']
        else:
            event_producer_durable = False

        if 'encrypted' in body.keys():
            event_producer_encrypted = body['encrypted']
        else:
            event_producer_encrypted = False

        if 'sinks' in body.keys():
            event_producer_sinks = body['sinks']
        else:
            event_producer_sinks = None

        # Check if the tenant already has an event producer with this name
        producer = tenant_util.find_event_producer(
            tenant, producer_name=event_producer_name)
        if producer:
            api.abort(
                falcon.HTTP_400,
                'Event producer with name {0} already exists with id={1}.'.
                format(producer.name, producer.get_id()))

        # Create the new profile for the host
        producer_id = tenant_util.create_event_producer(
            tenant, event_producer_name, event_producer_pattern,
            event_producer_durable, event_producer_encrypted,
            event_producer_sinks)

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/producers/{1}'.format(tenant_id, producer_id))
 def test_create_event_producer(self):
     self.ds_handler.next_sequence_value = MagicMock(
         return_value=self.producer_id)
     ttl_create_mapping_call = MagicMock()
     save_tenant_call = MagicMock()
     with patch(
             'meniscus.data.model.tenant_util._db_handler',
             self.ds_handler), \
         patch(
             'meniscus.data.model.tenant_util.'
             'mapping_tasks.create_ttl_mapping.delay',
             ttl_create_mapping_call), \
         patch(
             'meniscus.data.model.tenant_util.save_tenant',
             save_tenant_call):
         new_producer_id = tenant_util.create_event_producer(
             self.tenant_obj, self.event_producer.name,
             self.event_producer.pattern, self.event_producer.durable,
             self.event_producer.encrypted, self.event_producer.sinks)
         save_tenant_call.assert_called_once_with(self.tenant_obj)
         ttl_create_mapping_call.assert_called_once_with(
             tenant_id=self.tenant_obj.tenant_id,
             producer_pattern=self.event_producer.pattern)
         self.assertEqual(new_producer_id, self.producer_id)