From e693c25abc8538abfda75c82939539e4a237a93e Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sun, 3 Jun 2018 09:37:17 -0700 Subject: [PATCH] matrix tests: Add test for sample config generation. --- zulip/integrations/matrix/test_matrix.py | 40 +++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/zulip/integrations/matrix/test_matrix.py b/zulip/integrations/matrix/test_matrix.py index 3e56813..c768fdd 100644 --- a/zulip/integrations/matrix/test_matrix.py +++ b/zulip/integrations/matrix/test_matrix.py @@ -2,12 +2,40 @@ from unittest import TestCase from subprocess import Popen, PIPE import os +import shutil + +from contextlib import contextmanager +from tempfile import mkdtemp + script_file = "matrix_bridge.py" script_dir = os.path.dirname(__file__) script = os.path.join(script_dir, script_file) -from typing import List +from typing import List, Iterator +sample_config_path = "matrix_test.conf" + +sample_config_text = """[matrix] +host = https://matrix.org +username = username +password = password +room_id = #zulip:matrix.org + +[zulip] +email = glitch-bot@chat.zulip.org +api_key = aPiKeY +site = https://chat.zulip.org +stream = test here +topic = matrix + +""" + +@contextmanager +def new_temp_dir(): + # type: () -> Iterator[str] + path = mkdtemp() + yield path + shutil.rmtree(path) class MatrixBridgeTests(TestCase): def output_from_script(self, options): @@ -38,3 +66,13 @@ class MatrixBridgeTests(TestCase): self.assertTrue(len(output_lines) > blank_lines[0]) # Minimal description should be in the first line of the 2nd "paragraph" self.assertIn(description, output_lines[blank_lines[0] + 1]) + + def test_write_sample_config(self): + # type: () -> None + with new_temp_dir() as tempdir: + path = os.path.join(tempdir, sample_config_path) + output_lines = self.output_from_script(["--write-sample-config", path]) + self.assertEqual(output_lines, ["Wrote sample configuration to '{}'".format(path)]) + + with open(path) as sample_file: + self.assertEqual(sample_file.read(), sample_config_text)