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
77 changes: 77 additions & 0 deletions tests/integration/chat_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 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 Teams and Chat planner.

The planner has two scans: a deep scan, which reads the user's teams, channels
and chats, and a "Last 6 Months" scan, which estimates from Microsoft's usage
reports for the tenant and reads no messages.

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

import unittest

from tests.integration import harness

_ID_COLUMN = "Source MicrosoftTeamsID"
_TYPE_COLUMN = "Source Type"
_BATCH_FOLDER = "suggested batches"
_BATCH_HEADER = [_ID_COLUMN, _TYPE_COLUMN]


class _ChatScanTest:
"""Scans the user in the scan inputs file in one scan mode.

Subclasses set OPTIONS to the planner settings that select the mode.
"""

OPTIONS = {}

@classmethod
def setUpClass(cls):
cls.case = harness.case_or_skip("chat")
cls.run_ = harness.run_planner("chat", cls.case, cls.OPTIONS)
cls.users = [row[0] for row in cls.case["input"]["rows"] if row[1].lower() == "user"]

def setUp(self):
self.assertEqual(self.run_.errors, [], "The scan reported errors.")
self.assertIsNotNone(self.run_.result, "The scan did not report completion.")

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

def test_report_lists_every_input_user_once_and_no_entry_twice(self):
rows = harness.read_csv(self.run_.find_file("teams_report_"))
reported_users = [row[_ID_COLUMN] for row in rows if row[_TYPE_COLUMN].lower() == "user"]
self.assertEqual(harness.entry_problems(self.run_, reported_users, self.users), [])
entries = [row[_ID_COLUMN] for row in rows]
self.assertEqual(len(entries), len(set(entries)), "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), [])


class ChatDeepScanTest(_ChatScanTest, unittest.TestCase):
# Read every message, so the whole scan path runs.
OPTIONS = {"mode": "sampling", "sample_percentage": 100.0}


class ChatLastSixMonthsScanTest(_ChatScanTest, unittest.TestCase):
OPTIONS = {"mode": "heuristics"}


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