def test_simple(self): activity = create_incident_activity( self.incident, IncidentActivityType.COMMENT, user=self.user, comment='hello', ) send_subscriber_notifications(activity.id) # User shouldn't receive an email for their own activity self.send_async.assert_not_called() # NOQA self.send_async.reset_mock() non_member_user = self.create_user(email='*****@*****.**') subscribe_to_incident(activity.incident, non_member_user) member_user = self.create_user(email='*****@*****.**') self.create_member([self.team], user=member_user, organization=self.organization) subscribe_to_incident(activity.incident, member_user) send_subscriber_notifications(activity.id) self.send_async.assert_called_once_with([member_user.email]) assert not IncidentSubscription.objects.filter( incident=activity.incident, user=non_member_user, ).exists() assert IncidentSubscription.objects.filter( incident=activity.incident, user=member_user, ).exists()
def test_subscribed(self): incident = self.create_incident(date_started=timezone.now() - timedelta(minutes=5)) serializer = DetailedIncidentSerializer() result = serialize(incident, serializer=serializer, user=self.user) assert not result['isSubscribed'] subscribe_to_incident(incident, self.user) result = serialize(incident, serializer=serializer, user=self.user) assert result['isSubscribed']
def test_simple(self): self.create_member( user=self.user, organization=self.organization, role="owner", teams=[self.team] ) self.login_as(self.user) incident = self.create_incident() subscribe_to_incident(incident, self.user) with self.feature("organizations:incidents"): self.get_valid_response(self.organization.slug, incident.identifier, status_code=200) assert not IncidentSubscription.objects.filter(incident=incident, user=self.user).exists()
def post(self, request, organization, incident): """ Subscribes the authenticated user to the incident. `````````````````````````````````````````````````` Subscribes the user to the incident. If they are already subscribed then no-op. :auth: required """ subscribe_to_incident(incident, request.user) return Response({}, status=201)
def test_simple(self): incident = self.create_incident() assert list(get_incident_subscribers(incident)) == [] subscription = subscribe_to_incident(incident, self.user)[0] assert list(get_incident_subscribers(incident)) == [subscription]