def test_only_subscriber_or_admin_can_unsubscribe(self): alert = self.factory.create_alert() other_user = self.factory.create_user() path = '/api/alerts/{}/subscriptions/{}'.format(alert.id, other_user.id) AlertSubscription.create(alert=alert, user=other_user) response = self.make_request('delete', path) self.assertEqual(response.status_code, 403) response = self.make_request('delete', path, user=self.factory.create_admin()) self.assertEqual(response.status_code, 200) AlertSubscription.create(alert=alert, user=other_user) response = self.make_request('delete', path, user=other_user) self.assertEqual(response.status_code, 200)
def test_only_subscriber_or_admin_can_unsubscribe(self): alert = self.factory.create_alert() other_user = self.factory.create_user() path = '/api/alerts/{}/subscriptions/{}'.format( alert.id, other_user.id) AlertSubscription.create(alert=alert, user=other_user) response = self.make_request('delete', path) self.assertEqual(response.status_code, 403) response = self.make_request('delete', path, user=self.factory.create_admin()) self.assertEqual(response.status_code, 200) AlertSubscription.create(alert=alert, user=other_user) response = self.make_request('delete', path, user=other_user) self.assertEqual(response.status_code, 200)
conf['username'] = settings.WEBHOOK_USERNAME conf['password'] = settings.WEBHOOK_PASSWORD options = ConfigurationContainer(conf, schema) webhook = NotificationDestination.create( org=org, user=user, name="Webhook", type="webhook", options=options ) for alert in Alert.select(): AlertSubscription.create( user=user, destination=webhook, alert=alert ) if settings.HIPCHAT_API_TOKEN: # Have all existing alerts send to HipChat if already configured schema = get_configuration_schema_for_destination_type('hipchat') conf = {} if settings.HIPCHAT_API_URL: conf['url'] = '{url}/room/{room_id}/notification?auth_token={token}'.format( url=settings.HIPCHAT_API_URL, room_id=settings.HIPCHAT_ROOM_ID, token=settings.HIPCHAT_API_TOKEN) else: conf['url'] = 'https://hipchat.com/v2/room/{room_id}/notification?auth_token={token}'.format( room_id=settings.HIPCHAT_ROOM_ID, token=settings.HIPCHAT_API_TOKEN)
conf['username'] = WEBHOOK_USERNAME conf['password'] = WEBHOOK_PASSWORD options = ConfigurationContainer(conf, schema) webhook = NotificationDestination.create( org=org, user=user, name="Webhook", type="webhook", options=options ) for alert in Alert.select(): AlertSubscription.create( user=user, destination=webhook, alert=alert ) if HIPCHAT_API_TOKEN: # Have all existing alerts send to HipChat if already configured schema = get_configuration_schema_for_destination_type('hipchat') conf = {} if HIPCHAT_API_URL: conf['url'] = '{url}/room/{room_id}/notification?auth_token={token}'.format( url=HIPCHAT_API_URL, room_id=HIPCHAT_ROOM_ID, token=HIPCHAT_API_TOKEN) else: conf['url'] = 'https://hipchat.com/v2/room/{room_id}/notification?auth_token={token}'.format( room_id=HIPCHAT_ROOM_ID, token=HIPCHAT_API_TOKEN)