# Testing Microsoft 365 connections

Microsoft 365 mocks - dot-separated method chains for SharePoint, Teams, OneDrive and the rest.

When your Zato service reads SharePoint lists, sends Teams messages, accesses OneDrive files, or works with any Microsoft 365 API, you need to test that logic without real Microsoft credentials. This page shows how to mock Microsoft 365 responses so your tests run fast and work without Azure AD setup.

**Note:** If you're new to unit testing with Zato, check the [tutorial](https://zato.io/docs/api-testing/tutorial.html) first.

## How it works {#how-it-works}

When your Zato service calls Microsoft 365 APIs, the code uses method chaining. For example, here is a service that gets SharePoint list items:

```python
from zato.server.service import Service

class GetItems(Service):
    name = 'sharepoint.items.get'

    def handle(self):
        conn = self.microsoft.cloud['ms365.Sharepoint']
        site = conn.sharepoint().get_site('sites/main')
        sp_list = site.get_list_by_name('Tasks')
        items = sp_list.get_items()
        self.response.payload = {'items': list(items)}
```

To mock this, you configure responses for each step in the chain using dot-separated paths:

```python
from zato_testing import ServiceTestCase

class TestGetItems(ServiceTestCase):

    def test_returns_items(self):

        self.set_response('ms365.Sharepoint.sharepoint.get_site', {'id': 'site-123'})
        self.set_response('ms365.Sharepoint.sharepoint.get_site.get_list_by_name', {'id': 'list-456'})
        self.set_response('ms365.Sharepoint.sharepoint.get_site.get_list_by_name.get_items', [
            {'Title': 'Item 1'},
            {'Title': 'Item 2'}
        ])

        service = self.invoke(GetItems)

        items = service.response.payload['items']
        self.assertEqual(len(items), 2)
```

The framework detects Microsoft 365 paths by the dot-separated method chain (at least 2 dots).

## Request matching {#request-matching}

For operations that send data, use request matching:

```python
self.set_response(
    'ms365.Sharepoint.sharepoint.get_site.get_list_by_name.create_list_item',
    response={'id': 'new-item-123'},
    request={'Title': 'New Item', 'Status': 'Active'}
)
```

## Missing responses {#missing-responses}

If a service calls a Microsoft 365 method without a configured response, the framework raises an exception:

```text
ValueError: No response configured for 'ms365.Sharepoint...get_items'.
Use set_response('ms365.Sharepoint...get_items', <response>) to configure it.
```

## Microsoft 365 resources {#microsoft-365-resources}

Each Microsoft 365 resource has its own documentation:

| Resource | Description |
| --- | --- |
| [SharePoint](https://zato.io/docs/api-testing/ms365/sharepoint.html) | Lists, items, columns, subsites |
| [Mailbox](https://zato.io/docs/api-testing/ms365/mailbox.html) | Messages, folders, sending email |
| [OneDrive](https://zato.io/docs/api-testing/ms365/onedrive.html) | Files, folders, sharing, versions |
| [Teams](https://zato.io/docs/api-testing/ms365/teams.html) | Teams, channels, chats, presence |
| [Calendar](https://zato.io/docs/api-testing/ms365/calendar.html) | Events, calendars, scheduling |
| [Directory](https://zato.io/docs/api-testing/ms365/directory.html) | Users, groups, organization |
| [Planner](https://zato.io/docs/api-testing/ms365/planner.html) | Plans, tasks, buckets |
| [Tasks](https://zato.io/docs/api-testing/ms365/tasks.html) | ToDo lists and tasks |

## Learn more {#learn-more}

- [API testing](https://zato.io/docs/api-testing/) - Tests in plain English, run against real or mocked connections
- [API testing tutorial](https://zato.io/docs/api-testing/tutorial.html) - A complete test suite, from the first scenario to the report
- [Testing REST connections](https://zato.io/docs/api-testing/rest.html) - Mock outgoing REST calls and assert on what your service sent
- [Testing SQL connections](https://zato.io/docs/api-testing/sql.html) - Mock database queries and the rows they return
- [Testing LDAP connections](https://zato.io/docs/api-testing/ldap.html) - Mock directory lookups and the entries they find
- [Testing service invocations](https://zato.io/docs/api-testing/services.html) - Services that call other services, with the callees mocked
- [Testing Jira connections](https://zato.io/docs/api-testing/jira.html) - Mock Jira API calls and the issues they return
- [Tests in CI/CD](https://zato.io/docs/api-testing/ci-cd.html) - Running the suite in a pipeline and reading its output
