Пример #1
0
    def test_subscription_pubsub_two_services(self):
        service1 = SubscriptionService({'db_uri': self.db_uri})
        service2 = SubscriptionService({'db_uri': self.db_uri})

        tracker = {}

        def on_subscription(service, _):
            tracker[service] = True

        service1.pubsub.subscribe('created',
                                  partial(on_subscription, "service1"))
        service2.pubsub.subscribe('created',
                                  partial(on_subscription, "service2"))

        service1.create({
            'name': 'test',
            'owner_tenant_uuid': str(uuid.uuid4()),
            'service': 'http',
            'config': {},
            'events': [],
        })
        assert_that(tracker, has_entries({'service1': True, 'service2': True}))
Пример #2
0
    def test_subscription_log_on_subscription_deleted(self):
        service = SubscriptionService({'db_uri': self.db_uri})
        subscription_uuid_not_found = str(uuid.uuid4())

        service.create_hook_log(
            uuid=str(uuid.uuid4()),
            subscription_uuid=subscription_uuid_not_found,
            status="failure",
            attempts=1,
            max_attempts=3,
            started_at=datetime.datetime.now(),
            ended_at=datetime.datetime.now() + datetime.timedelta(minutes=1),
            event={},
            detail={},
        )
Пример #3
0
    def test_subscription_pubusb_create(self):
        service = SubscriptionService({'db_uri': self.db_uri})

        tracker = {'uuid': None}

        def on_subscription(subscription):
            tracker['uuid'] = subscription.uuid

        service.pubsub.subscribe('created', on_subscription)
        service.create({
            'name': 'test',
            'owner_tenant_uuid': str(uuid.uuid4()),
            'service': 'http',
            'config': {},
            'events': [],
        })
        assert_that(tracker, has_entries({'uuid': is_(not_none())}))
Пример #4
0
 def load(self, dependencies):
     bus_consumer = dependencies['bus_consumer']
     self._config = dependencies['config']
     self.subscription_service = SubscriptionService(self._config)
     bus_consumer.subscribe_to_event_names(
         uuid=uuid.uuid4(),
         event_names=['auth_user_external_auth_added'],
         # tenant_uuid=None,
         user_uuid=None,
         wazo_uuid=None,
         callback=self.on_external_auth_added)
     bus_consumer.subscribe_to_event_names(
         uuid=uuid.uuid4(),
         event_names=['auth_user_external_auth_deleted'],
         # tenant_uuid=None,
         user_uuid=None,
         wazo_uuid=None,
         callback=self.on_external_auth_deleted)
     logger.info('Mobile push notification plugin is started')
Пример #5
0
    def test_purger(self):
        service = SubscriptionService({'db_uri': self.db_uri})
        subscription_uuid = service.create({
            'name':
            'test',
            'owner_tenant_uuid':
            str(uuid.uuid4()),
            'service':
            'http',
            'config': {},
            'events': [],
        }).uuid

        def add_log(days_ago):
            started_at = datetime.datetime.now() - datetime.timedelta(
                days=days_ago)
            service.create_hook_log(
                str(uuid.uuid4()),
                subscription_uuid,
                "failure",
                1,
                3,
                started_at,
                started_at + datetime.timedelta(minutes=1),
                {},
                {},
            )

        for days in range(5):
            add_log(days_ago=days)
            add_log(days_ago=days)

        logs = service.get_logs(subscription_uuid)
        assert_that(len(logs), equal_to(10))

        with service.rw_session() as session:
            days_to_purge = 2
            SubscriptionLogsPurger().purge(days_to_purge, session)

        logs = service.get_logs(subscription_uuid)
        assert_that(len(logs), equal_to(4))