예제 #1
0
    def test_discover_outside_retention(self, emailer, mock_query):
        """
        When a discover query goes outside the retention range, email the user they should
        use a more recent date range.
        """
        de = ExportedData.objects.create(
            user=self.user,
            organization=self.org,
            query_type=ExportQueryType.DISCOVER,
            query_info={
                "project": [self.project.id],
                "field": ["title"],
                "query": ""
            },
        )

        mock_query.side_effect = QueryOutsideRetentionError("test")
        with self.tasks():
            assemble_download(de.id)
        error = emailer.call_args[1]["message"]
        assert error == "Invalid date range. Please try a more recent date range."

        # unicode
        mock_query.side_effect = QueryOutsideRetentionError("\xfc")
        with self.tasks():
            assemble_download(de.id)
        error = emailer.call_args[1]["message"]
        assert error == "Invalid date range. Please try a more recent date range."
예제 #2
0
    def test_issue_by_tag_outside_retention(self, emailer, mock_query,
                                            mock_get_tag_key):
        """
        When an issues by tag query goes outside the retention range, it returns 0 results.
        This gives us an empty CSV with just the headers.
        """
        de = ExportedData.objects.create(
            user=self.user,
            organization=self.org,
            query_type=ExportQueryType.ISSUES_BY_TAG,
            query_info={
                "project": [self.project.id],
                "group": self.event.group_id,
                "key": "foo"
            },
        )

        mock_query.side_effect = QueryOutsideRetentionError("test")
        with self.tasks():
            assemble_download(de.id)
        de = ExportedData.objects.get(id=de.id)
        assert de.date_finished is not None
        assert de.date_expired is not None
        assert de.file is not None
        assert isinstance(de.file, File)
        assert de.file.headers == {"Content-Type": "text/csv"}
        assert de.file.size is not None
        assert de.file.checksum is not None
        # Convert raw csv to list of line-strings
        header = de.file.getfile().read().strip()
        assert header == b"value,times_seen,last_seen,first_seen"
예제 #3
0
    def test_handling_snuba_errors(self, mock_query):
        mock_query.side_effect = RateLimitExceeded("test")

        self.login_as(user=self.user)
        project = self.create_project()

        self.store_event(
            data={"event_id": "a" * 32, "message": "how to make fast"}, project_id=project.id
        )

        with self.feature("organizations:discover-basic"):
            response = self.client.get(
                self.url,
                data={"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]},
                format="json",
            )

        assert response.status_code == 400, response.content
        assert (
            response.data["detail"]
            == "Query timeout. Please try again. If the problem persists try a smaller date range or fewer projects."
        )

        mock_query.side_effect = QueryExecutionError("test")
        with self.feature("organizations:discover-basic"):
            response = self.client.get(
                self.url,
                data={"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]},
                format="json",
            )

        assert response.status_code == 400, response.content
        assert response.data["detail"] == "Invalid query."

        mock_query.side_effect = QueryIllegalTypeOfArgument("test")
        with self.feature("organizations:discover-basic"):
            response = self.client.get(
                self.url,
                data={"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]},
                format="json",
            )

        assert response.status_code == 400, response.content
        assert response.data["detail"] == "Invalid query. Argument to function is wrong type."

        mock_query.side_effect = QueryOutsideRetentionError("test")
        with self.feature("organizations:discover-basic"):
            response = self.client.get(
                self.url,
                data={"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]},
                format="json",
            )

        assert response.status_code == 400, response.content
        assert response.data["detail"] == "Invalid date range. Please try a more recent date range."