Coverage for src/integry/tests/test_apps.py: 97%
52 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-26 01:26 +0500
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-26 01:26 +0500
1import unittest
2import os
3from integry import Integry
4from datetime import datetime
6APP_KEY = os.getenv("INTEGRY_APP_KEY")
7APP_SECRET = os.getenv("INTEGRY_APP_SECRET")
8USER_ID = os.getenv("INTEGRY_USER_ID")
10class TestIntegryFunctionAPI(unittest.IsolatedAsyncioTestCase):
11 """Test suite for the Integry Function API"""
13 async def asyncSetUp(self):
14 """Initialize Integry client asynchronously"""
15 self.integry = Integry(app_key=APP_KEY, app_secret=APP_SECRET)
16 self.user_id = USER_ID
18 async def test_list_apps(self):
19 """Test if listing apps returns a valid response"""
20 response = await self.integry.apps.list(user_id=self.user_id)
22 self.assertIsInstance(response, object, "Response should be an object")
23 self.assertTrue(
24 hasattr(response, "apps"), "Response should have an 'apps' attribute"
25 )
26 self.assertIsInstance(response.apps, list, "'apps' should be a list")
27 self.assertGreater(len(response.apps), 0, "'apps' list should not be empty")
29 for app in response.apps:
30 with self.subTest(app=app.name):
31 self.assertTrue(hasattr(app, "id"), "App should have an 'id'")
32 self.assertTrue(hasattr(app, "name"), "App should have a 'name'")
33 self.assertTrue(hasattr(app, "title"), "App should have a 'title'")
34 self.assertTrue(
35 hasattr(app, "icon_url"), "App should have an 'icon_url'"
36 )
37 self.assertTrue(
38 hasattr(app, "login_url"), "App should have a 'login_url'"
39 )
40 self.assertTrue(
41 hasattr(app, "connected_accounts"),
42 "App should have 'connected_accounts'",
43 )
45 for app in response.apps:
46 for account in app.connected_accounts:
47 with self.subTest(app=app.name, account=account.display_name):
48 self.assertTrue(
49 hasattr(account, "id"), "ConnectedAccount should have an 'id'"
50 )
51 self.assertTrue(
52 hasattr(account, "display_name"),
53 "ConnectedAccount should have a 'display_name'",
54 )
55 self.assertTrue(
56 hasattr(account, "modified_at"),
57 "ConnectedAccount should have 'modified_at'",
58 )
59 self.assertIsInstance(
60 account.modified_at,
61 datetime,
62 "'modified_at' should be a datetime object",
63 )
65 async def test_get_app(self):
66 """Test if getting the App returns the correct structure"""
68 response = await self.integry.apps.get("slack", user_id=self.user_id)
70 self.assertTrue(hasattr(response, "id"), "App should have an 'id'")
71 self.assertTrue(hasattr(response, "name"), "App should have a 'name'")
72 self.assertTrue(hasattr(response, "title"), "App should have a 'title'")
73 self.assertTrue(hasattr(response, "icon_url"), "App should have an 'icon_url'")
74 self.assertTrue(hasattr(response, "login_url"), "App should have a 'login_url'")
75 self.assertTrue(hasattr(response, "connected_accounts"), "App should have 'connected_accounts'")
77 self.assertIsInstance(response.connected_accounts, list, "'connected_accounts' should be a list")
78 for account in response.connected_accounts:
79 self.assertTrue(hasattr(account, "id"), "ConnectedAccount should have an 'id'")
80 self.assertTrue(hasattr(account, "display_name"), "ConnectedAccount should have a 'display_name'")
81 self.assertTrue(hasattr(account, "modified_at"), "ConnectedAccount should have 'modified_at'")
82 self.assertIsInstance(account.modified_at, datetime, "'modified_at' should be a datetime object")
84 async def test_is_connected(self):
85 """Test if the app is connected successfully"""
86 response = await self.integry.apps.is_connected(
87 app_name="slack",
88 user_id=self.user_id,
89 )
91 self.assertIsInstance(response, bool, "Response should be a boolean")
92 self.assertTrue(response, "App should be connected")
95if __name__ == "__main__": 95 ↛ 96line 95 didn't jump to line 96 because the condition on line 95 was never true
96 unittest.main()