|
2 | 2 |
|
3 | 3 | from unittest import TestCase
|
4 | 4 | from configparser import ConfigParser
|
| 5 | +from ms_graph.client import MicrosoftGraphClient |
5 | 6 |
|
| 7 | +from ms_graph.mail import Mail |
| 8 | +from ms_graph.notes import Notes |
| 9 | +from ms_graph.users import Users |
| 10 | +from ms_graph.search import Search |
| 11 | +from ms_graph.drives import Drives |
| 12 | +from ms_graph.groups import Groups |
| 13 | +from ms_graph.session import GraphSession |
| 14 | +from ms_graph.drive_items import DriveItems |
| 15 | +from ms_graph.personal_contacts import PersonalContacts |
6 | 16 |
|
7 |
| -class MySession(TestCase): |
8 | 17 |
|
9 |
| - """Will perform a unit test for the <PLACEHOLDER> session.""" |
| 18 | +class MicrosoftGraphSessionTest(TestCase): |
| 19 | + |
| 20 | + """Will perform a unit test for the `MicrosoftGraphClient` session.""" |
10 | 21 |
|
11 | 22 | def setUp(self) -> None:
|
12 |
| - """Set up the <PLACEHOLDER> Client.""" |
| 23 | + """Set up the `MicrosoftGraphClient` Client.""" |
| 24 | + |
| 25 | + scopes = [ |
| 26 | + 'Calendars.ReadWrite', |
| 27 | + 'Files.ReadWrite.All', |
| 28 | + 'User.ReadWrite.All', |
| 29 | + 'Notes.ReadWrite.All', |
| 30 | + 'Directory.ReadWrite.All', |
| 31 | + 'User.Read.All', |
| 32 | + 'Directory.Read.All', |
| 33 | + 'Directory.ReadWrite.All' |
| 34 | + ] |
13 | 35 |
|
14 | 36 | # Initialize the Parser.
|
15 | 37 | config = ConfigParser()
|
16 | 38 |
|
17 | 39 | # Read the file.
|
18 |
| - config.read('configs/config.ini') |
| 40 | + config.read('config/config.ini') |
19 | 41 |
|
20 | 42 | # Get the specified credentials.
|
21 |
| - config.get('main', '') |
| 43 | + client_id = config.get('graph_api', 'client_id') |
| 44 | + client_secret = config.get('graph_api', 'client_secret') |
| 45 | + redirect_uri = config.get('graph_api', 'redirect_uri') |
| 46 | + |
| 47 | + # Initialize the Client. |
| 48 | + graph_client = MicrosoftGraphClient( |
| 49 | + client_id=client_id, |
| 50 | + client_secret=client_secret, |
| 51 | + redirect_uri=redirect_uri, |
| 52 | + scope=scopes, |
| 53 | + credentials='config/ms_graph_state.jsonc' |
| 54 | + ) |
| 55 | + |
| 56 | + self.client = graph_client |
22 | 57 |
|
23 | 58 | def test_creates_instance_of_session(self):
|
24 |
| - """Create an instance and make sure it's a <PLACEHOLDER>.""" |
25 |
| - pass |
| 59 | + """Create an instance and make sure it's a `MicrosoftGraphClient`.""" |
| 60 | + |
| 61 | + self.assertIsInstance(self.client, MicrosoftGraphClient) |
| 62 | + |
| 63 | + def test_creates_instance_of_mail(self): |
| 64 | + """Create an instance and make sure it's a `MicrosoftGraphClient.Mail`.""" |
| 65 | + |
| 66 | + self.assertIsInstance(self.client.mail(), Mail) |
| 67 | + |
| 68 | + def test_creates_instance_of_drive_items(self): |
| 69 | + """Create an instance and make sure it's a `MicrosoftGraphClient.DriveItems`.""" |
| 70 | + |
| 71 | + self.assertIsInstance(self.client.drive_item(), DriveItems) |
| 72 | + |
| 73 | + def test_creates_instance_of_drives(self): |
| 74 | + """Create an instance and make sure it's a `MicrosoftGraphClient.Drives`.""" |
| 75 | + |
| 76 | + self.assertIsInstance(self.client.drives(), Drives) |
| 77 | + |
| 78 | + def test_creates_instance_of_users(self): |
| 79 | + """Create an instance and make sure it's a `MicrosoftGraphClient.Users`.""" |
| 80 | + |
| 81 | + self.assertIsInstance(self.client.users(), Users) |
| 82 | + |
| 83 | + def test_creates_instance_of_groups(self): |
| 84 | + """Create an instance and make sure it's a `MicrosoftGraphClient.Groups`.""" |
| 85 | + |
| 86 | + self.assertIsInstance(self.client.groups(), Groups) |
| 87 | + |
| 88 | + def test_creates_instance_of_notes(self): |
| 89 | + """Create an instance and make sure it's a `MicrosoftGraphClient.Notes`.""" |
| 90 | + |
| 91 | + self.assertIsInstance(self.client.notes(), Notes) |
| 92 | + |
| 93 | + def test_creates_instance_of_search(self): |
| 94 | + """Create an instance and make sure it's a `MicrosoftGraphClient.Search`.""" |
| 95 | + |
| 96 | + self.assertIsInstance(self.client.search(), Search) |
| 97 | + |
| 98 | + def test_creates_instance_of_personal_contacts(self): |
| 99 | + """Create an instance and make sure it's a `MicrosoftGraphClient.PersonalContacts`.""" |
| 100 | + |
| 101 | + self.assertIsInstance( |
| 102 | + self.client.personal_contacts(), PersonalContacts) |
26 | 103 |
|
27 | 104 | def tearDown(self) -> None:
|
28 |
| - """Teardown the <PLACEHOLDER> Client.""" |
29 |
| - pass |
| 105 | + """Teardown the `MicrosoftGraphClient` Client.""" |
| 106 | + |
| 107 | + del self.client |
30 | 108 |
|
31 | 109 |
|
32 | 110 | if __name__ == '__main__':
|
|
0 commit comments