Пример #1
0
 def test(self):
     with patch("sentry.models.recentsearch.MAX_RECENT_SEARCHES", new=1):
         RecentSearch.objects.create(
             organization=self.organization,
             user=self.user,
             type=0,
             query="hello",
             last_seen=timezone.now() - timedelta(minutes=10),
         )
         remove_excess_recent_searches(self.organization, self.user, 0)
         assert list(RecentSearch.objects.all().values_list("query", flat=True)) == ["hello"]
         RecentSearch.objects.create(
             organization=self.organization, user=self.user, type=0, query="goodbye"
         )
         remove_excess_recent_searches(self.organization, self.user, 0)
         assert list(RecentSearch.objects.all().values_list("query", flat=True)) == ["goodbye"]
Пример #2
0
 def test(self):
     with patch('sentry.models.recentsearch.MAX_RECENT_SEARCHES', new=1):
         RecentSearch.objects.create(
             organization=self.organization,
             user=self.user,
             type=0,
             query='hello',
             last_seen=timezone.now() - timedelta(minutes=10)
         )
         remove_excess_recent_searches(self.organization, self.user, 0)
         assert list(RecentSearch.objects.all().values_list('query', flat=True)) == ['hello']
         RecentSearch.objects.create(
             organization=self.organization,
             user=self.user,
             type=0,
             query='goodbye',
         )
         remove_excess_recent_searches(self.organization, self.user, 0)
         assert list(RecentSearch.objects.all().values_list('query', flat=True)) == ['goodbye']
    def post(self, request, organization):
        serializer = RecentSearchSerializer(data=request.DATA)

        if serializer.is_valid():
            result = serializer.object

            created = RecentSearch.objects.create_or_update(
                organization=organization,
                user=request.user,
                type=result['type'],
                query=result['query'],
                values={'last_seen': timezone.now()}
            )[1]
            if created:
                remove_excess_recent_searches(organization, request.user, result['type'])
            status = 201 if created else 204

            return Response('', status=status)
        return Response(serializer.errors, status=400)
    def post(self, request, organization):
        serializer = RecentSearchSerializer(data=request.DATA)

        if serializer.is_valid():
            result = serializer.object

            created = RecentSearch.objects.create_or_update(
                organization=organization,
                user=request.user,
                type=result['type'],
                query=result['query'],
                values={'last_seen': timezone.now()})[1]
            if created:
                remove_excess_recent_searches(organization, request.user,
                                              result['type'])
            status = 201 if created else 204

            return Response('', status=status)
        return Response(serializer.errors, status=400)
Пример #5
0
    def post(self, request, organization):
        serializer = RecentSearchSerializer(data=request.data)

        if serializer.is_valid():
            result = serializer.validated_data

            created = RecentSearch.objects.create_or_update(
                organization=organization,
                user=request.user,
                type=result["type"],
                query=result["query"],
                values={"last_seen": timezone.now()},
            )[1]
            if created:
                remove_excess_recent_searches(organization, request.user, result["type"])
            status = 201 if created else 204

            return Response("", status=status)
        return Response(serializer.errors, status=400)
 def test(self):
     with patch('sentry.models.recentsearch.MAX_RECENT_SEARCHES', new=1):
         RecentSearch.objects.create(organization=self.organization,
                                     user=self.user,
                                     type=0,
                                     query='hello',
                                     last_seen=timezone.now() -
                                     timedelta(minutes=10))
         remove_excess_recent_searches(self.organization, self.user, 0)
         assert list(RecentSearch.objects.all().values_list(
             'query', flat=True)) == ['hello']
         RecentSearch.objects.create(
             organization=self.organization,
             user=self.user,
             type=0,
             query='goodbye',
         )
         remove_excess_recent_searches(self.organization, self.user, 0)
         assert list(RecentSearch.objects.all().values_list(
             'query', flat=True)) == ['goodbye']