|
1 | 1 | import time |
| 2 | +from datetime import datetime, timezone |
2 | 3 | import unittest |
3 | 4 |
|
4 | 5 | from slack_sdk.oauth.installation_store import Installation, FileInstallationStore, Bot |
@@ -36,6 +37,22 @@ def test_bot_custom_fields(self): |
36 | 37 | self.assertEqual(bot.to_dict().get("service_user_id"), "XYZ123") |
37 | 38 | self.assertEqual(bot.to_dict_for_copying().get("custom_values").get("service_user_id"), "XYZ123") |
38 | 39 |
|
| 40 | + def test_bot_datetime_manipulation(self): |
| 41 | + expected_timestamp = datetime.now(tz=timezone.utc) |
| 42 | + bot = Bot( |
| 43 | + bot_token="xoxb-", |
| 44 | + bot_id="B111", |
| 45 | + bot_user_id="U111", |
| 46 | + bot_token_expires_at=expected_timestamp, |
| 47 | + installed_at=expected_timestamp, |
| 48 | + ) |
| 49 | + bot_dict = bot.to_dict() |
| 50 | + self.assertIsNotNone(bot_dict) |
| 51 | + self.assertEqual( |
| 52 | + bot_dict.get("bot_token_expires_at").isoformat(), expected_timestamp.strftime("%Y-%m-%dT%H:%M:%S+00:00") |
| 53 | + ) |
| 54 | + self.assertEqual(bot_dict.get("installed_at"), expected_timestamp) |
| 55 | + |
39 | 56 | def test_installation(self): |
40 | 57 | installation = Installation( |
41 | 58 | app_id="A111", |
@@ -84,3 +101,29 @@ def test_installation_custom_fields(self): |
84 | 101 | self.assertEqual(bot.to_dict().get("app_id"), "A111") |
85 | 102 | self.assertEqual(bot.to_dict().get("service_user_id"), "XYZ123") |
86 | 103 | self.assertEqual(bot.to_dict_for_copying().get("custom_values").get("app_id"), "A222") |
| 104 | + |
| 105 | + def test_installation_datetime_manipulation(self): |
| 106 | + expected_timestamp = datetime.now(tz=timezone.utc) |
| 107 | + installation = Installation( |
| 108 | + app_id="A111", |
| 109 | + enterprise_id="E111", |
| 110 | + team_id="T111", |
| 111 | + user_id="U111", |
| 112 | + bot_id="B111", |
| 113 | + bot_token="xoxb-111", |
| 114 | + bot_scopes=["chat:write"], |
| 115 | + bot_user_id="U222", |
| 116 | + bot_token_expires_at=expected_timestamp, |
| 117 | + user_token_expires_at=expected_timestamp, |
| 118 | + installed_at=expected_timestamp, |
| 119 | + ) |
| 120 | + installation_dict = installation.to_dict() |
| 121 | + self.assertIsNotNone(installation_dict) |
| 122 | + self.assertEqual( |
| 123 | + installation_dict.get("bot_token_expires_at").isoformat(), expected_timestamp.strftime("%Y-%m-%dT%H:%M:%S+00:00") |
| 124 | + ) |
| 125 | + self.assertEqual( |
| 126 | + installation_dict.get("user_token_expires_at").isoformat(), |
| 127 | + expected_timestamp.strftime("%Y-%m-%dT%H:%M:%S+00:00"), |
| 128 | + ) |
| 129 | + self.assertEqual(installation_dict.get("installed_at"), expected_timestamp) |
0 commit comments