Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions tests/integration/files_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Live integration tests for the Files planner: deep scan and shallow scan.

Run with:
python3 -m unittest tests.integration.files_test -v
"""

import unittest

from tests.integration import harness

_BATCH_FOLDER = "suggested_batches"
_BATCH_HEADER = ["Entity"]
_SITE_COLUMN = "Site URL/Name"


class _FilesScanTest:
"""Scans the entries of one case from the scan inputs file in one scan mode.

Subclasses set CASE ("sharepoint_site" or "onedrive_user") and SHALLOW.
"""

CASE = ""
SHALLOW = False

@classmethod
def setUpClass(cls):
cls.case = harness.case_or_skip("files", cls.CASE)
if cls.SHALLOW and not cls.case.get("shallow_scan", True):
raise unittest.SkipTest(f"Shallow scan is turned off for the '{cls.CASE}' case.")
cls.run_ = harness.run_planner("files", cls.case, {"shallow_scan": cls.SHALLOW})

def setUp(self):
check = self.run_.certificate_check
if check is not None:
self.assertTrue(
check["ok"],
"Shallow scan needs a certificate that is registered on the app. If this is a new "
"certificate, upload certificate/<tenant>_<client>/certificate.pem to the app "
f"registration. Detail: {check['detail']}",
)
self.assertEqual(self.run_.errors, [], "The scan reported errors.")
self.assertIsNotNone(self.run_.result, "The scan did not report completion.")

def _report_rows(self):
return harness.read_csv(self.run_.find_file("site_report_"))

def test_run_log_has_no_errors_or_warnings(self):
self.assertEqual(harness.log_problems(self.run_), [])

def test_report_lists_every_entry_once(self):
sites = [row[_SITE_COLUMN] for row in self._report_rows()]
self.assertEqual(len(sites), len(self.case["input"]["rows"]), "Expected one report row per scanned entry.")
self.assertEqual(len(sites), len(set(sites)), "An entry is listed more than once.")

def test_batch_files_have_the_right_header(self):
self.assertEqual(harness.batch_file_problems(self.run_, _BATCH_FOLDER, _BATCH_HEADER), [])

def test_no_library_failed(self):
if not self.SHALLOW:
self.skipTest("Only shallow scan reports failed libraries.")
for row in self._report_rows():
self.assertEqual(int(row["Failed DL Count"]), 0, self.run_.redact(row[_SITE_COLUMN]))


class SharePointDeepScanTest(_FilesScanTest, unittest.TestCase):
CASE = "sharepoint_site"


class SharePointShallowScanTest(_FilesScanTest, unittest.TestCase):
CASE = "sharepoint_site"
SHALLOW = True


class OneDriveDeepScanTest(_FilesScanTest, unittest.TestCase):
CASE = "onedrive_user"


class OneDriveShallowScanTest(_FilesScanTest, unittest.TestCase):
CASE = "onedrive_user"
SHALLOW = True


if __name__ == "__main__":
unittest.main()
Loading