Пример #1
0
    def test_withManifest_succeeds(self, mock_ingest: unittest.mock.MagicMock) -> None:
        # Act
        request_args = {"manifest_path": "gs://fake-bucket/foo/manifest.yaml"}
        headers = {"X-Appengine-Cron": "test-cron"}
        response = self.client.get(
            "/ingest", query_string=request_args, headers=headers
        )

        # Assert
        self.assertEqual(200, response.status_code)
        mock_ingest.assert_called_with(
            ANY, GcsfsFilePath(bucket_name="fake-bucket", blob_name="foo/manifest.yaml")
        )
Пример #2
0
    def test_ingestFails_raisesError(
        self, mock_ingest: unittest.mock.MagicMock
    ) -> None:
        # Arrange
        mock_ingest.side_effect = ValueError("Malformed manifest")

        # Act
        request_args = {"manifest_path": "gs://fake-bucket/foo/manifest.yaml"}
        headers = {"X-Appengine-Cron": "test-cron"}
        with self.assertRaisesRegex(ValueError, "Malformed manifest"):
            self.client.get("/ingest", query_string=request_args, headers=headers)

        # Assert
        mock_ingest.assert_called_with(
            ANY, GcsfsFilePath(bucket_name="fake-bucket", blob_name="foo/manifest.yaml")
        )
Пример #3
0
    def test_ingestFails_raisesError(
            self, mock_ingest: unittest.mock.MagicMock) -> None:
        # Arrange
        mock_ingest.side_effect = ValueError("Malformed manifest")

        # Act
        request_args = {"manifest_path": "gs://fake-bucket/foo/manifest.yaml"}
        headers = {"X-Appengine-Cron": "test-cron"}
        response = self.client.get("/ingest",
                                   query_string=request_args,
                                   headers=headers)

        # Assert
        self.assertEqual(500, response.status_code)
        self.assertEqual("Error ingesting data: 'Malformed manifest'",
                         response.get_data().decode())
        mock_ingest.assert_called_with(
            ANY,
            GcsfsFilePath(bucket_name="fake-bucket",
                          blob_name="foo/manifest.yaml"))