feat(scouts): add gmail label-list + disconnect routes
This commit is contained in:
@@ -104,3 +104,46 @@ async def test_delete_cloud_scout():
|
||||
assert resp.status_code == 200
|
||||
listing = (await client.get("/api/v1/scouts/cloud", headers=_auth_headers())).json()
|
||||
assert all(r["id"] != sid for r in listing)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gmail_labels_route_returns_labels():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
created = (await client.post(
|
||||
"/api/v1/scouts/cloud",
|
||||
json={"name": "L", "provider": "gmail"},
|
||||
headers=_auth_headers(),
|
||||
)).json()
|
||||
sid = created["id"]
|
||||
|
||||
with patch("app.api.routes.scouts.get_connector") as mock_get:
|
||||
mock_get.return_value.list_labels = AsyncMock(return_value=[{"id": "INBOX", "name": "INBOX"}])
|
||||
resp = await client.get(f"/api/v1/scouts/cloud/{sid}/gmail-labels", headers=_auth_headers())
|
||||
assert resp.status_code == 200
|
||||
assert resp.json() == [{"id": "INBOX", "name": "INBOX"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gmail_disconnect_clears_token():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
created = (await client.post(
|
||||
"/api/v1/scouts/cloud",
|
||||
json={"name": "D", "provider": "gmail"},
|
||||
headers=_auth_headers(),
|
||||
)).json()
|
||||
sid = created["id"]
|
||||
# mark it connected directly in the DB
|
||||
async with _TestSessionLocal() as session:
|
||||
row = await session.get(CloudScoutConfig, sid)
|
||||
row.oauth_token_encrypted = "blob"
|
||||
row.gmail_address = "a@b.com"
|
||||
await session.commit()
|
||||
|
||||
with patch("app.api.routes.scouts.get_connector") as mock_get:
|
||||
mock_get.return_value.stop_watch = AsyncMock()
|
||||
resp = await client.post(f"/api/v1/scouts/cloud/{sid}/gmail-disconnect", headers=_auth_headers())
|
||||
assert resp.status_code == 200
|
||||
body = resp.json()
|
||||
assert body["oauth_connected"] is False
|
||||
assert body["gmail_address"] is None
|
||||
assert body["enabled"] is False
|
||||
|
||||
Reference in New Issue
Block a user