def test_should_handle_team_name_with_invalid_characters(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T92345678") exporter = SlackChannelExporter("TOKEN_DUMMY") channels = ["C12345678"] # when response = exporter.run(channels, outputdir) # then self.assertTrue(response["ok"])
def test_all_message_variants(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") exporter = SlackChannelExporter("TOKEN_DUMMY") channels = ["G1234567X"] # when response = exporter.run(channels, outputdir) # then self.assertTrue(response["ok"])
def test_should_handle_nested_code_formatting(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") exporter = SlackChannelExporter(slack_token="TOKEN_DUMMY") channel = "C92345678" # when response = exporter.run([channel], outputdir) # then self.assertTrue(response["ok"])
def test_basic(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") exporter = SlackChannelExporter("TOKEN_DUMMY") channel = "C12345678" # when response = exporter.run([channel], outputdir) # then self.assertTrue(response["ok"]) res_channel = response["channels"][channel] self.assertTrue(res_channel["ok"]) filename_pdf = Path(res_channel["filename_pdf"]) self.assertTrue(filename_pdf.is_file()) self.assertEqual(filename_pdf.name, "test_berlin.pdf")
def test_run_with_args_2(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") exporter = SlackChannelExporter("TOKEN_DUMMY") channel = "C72345678" # when response = exporter.run([channel], outputdir, write_raw_data=True) # then self.assertTrue(response["ok"]) self.assertTrue((outputdir / "test_bots.json").is_file()) self.assertTrue((outputdir / "test_channels.json").is_file()) self.assertTrue((outputdir / "test_london.pdf").is_file()) self.assertTrue((outputdir / "test_london_messages.json").is_file()) self.assertTrue((outputdir / "test_usergroups.json").is_file()) self.assertTrue((outputdir / "test_users.json").is_file())
def test_run_with_args_1(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") exporter = SlackChannelExporter("TOKEN_DUMMY") channel = "C72345678" # when response = exporter.run([channel], outputdir, None, None, "landscape", "a3", 42) # then self.assertTrue(response["ok"]) res_channel = response["channels"][channel] self.assertTrue(res_channel["ok"]) self.assertEqual(res_channel["message_count"], 5) self.assertEqual(res_channel["thread_count"], 0) self.assertEqual(res_channel["dest_path"], str(outputdir)) self.assertEqual(res_channel["page_format"], "a3") self.assertEqual(res_channel["page_orientation"], "landscape") self.assertEqual(res_channel["max_messages"], 42)
def test_run_with_defaults(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") exporter = SlackChannelExporter("TOKEN_DUMMY") channels = ["C12345678", "C72345678"] # when response = exporter.run(channels) # then self.assertTrue(response["ok"]) for channel_id in channels: self.assertIn(channel_id, response["channels"]) res_channel = response["channels"][channel_id] channel_name = exporter._slack_service.channel_names()[channel_id] self.assertEqual( res_channel["filename_pdf"], str( currentdir.parent / (exporter._slack_service.team + "_" + channel_name + ".pdf") ), ) self.assertTrue(Path(res_channel["filename_pdf"]).is_file()) # assert export details are correct self.assertTrue(res_channel["ok"]) self.assertEqual(res_channel["dest_path"], str(currentdir.parent)) self.assertEqual(res_channel["page_format"], "a4") self.assertEqual(res_channel["page_orientation"], "portrait") self.assertEqual( res_channel["max_messages"], settings.MAX_MESSAGES_PER_CHANNEL, ) self.assertEqual(res_channel["timezone"], pytz.UTC) self.assertEqual(res_channel["locale"], babel.Locale("en", "US")) # assert infos in PDF file are correct pdf_file = open(res_channel["filename_pdf"], "rb") pdf_reader = PyPDF2.PdfFileReader(pdf_file) doc_info = pdf_reader.getDocumentInfo() self.assertEqual(doc_info.author, "Erik Kalkoken") self.assertEqual(doc_info.creator, f"Channel Export v{__version__}") self.assertEqual( doc_info.title, (exporter._slack_service.team + " / " + channel_name), )
def test_should_use_given_timezone(self, mock_slack): # given mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") exporter = SlackChannelExporter( slack_token="TOKEN_DUMMY", my_tz=pytz.timezone("Asia/Bangkok"), my_locale=babel.Locale.parse("es-MX", sep="-"), ) channel = "C12345678" # when response = exporter.run([channel], outputdir) # then self.assertTrue(response["ok"]) res_channel = response["channels"][channel] self.assertTrue(res_channel["ok"]) self.assertEqual( res_channel["timezone"], pytz.timezone("Asia/Bangkok"), ) self.assertEqual(res_channel["locale"], babel.Locale.parse("es-MX", sep="-"))
def setUpClass(cls): super().setUpClass() with patch("slackchannel2pdf.slack_service.slack") as mock_slack: mock_slack.WebClient.return_value = SlackClientStub(team="T12345678") cls.exporter = SlackChannelExporter("TOKEN_DUMMY")