|
| 1 | +import pytest |
| 2 | +from packaging import version |
| 3 | + |
| 4 | +from posit import connect |
| 5 | + |
| 6 | +from .. import CONNECT_VERSION |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.skipif( |
| 10 | + CONNECT_VERSION <= version.parse("2024.06.0"), |
| 11 | + reason="OAuth Integrations not supported.", |
| 12 | +) |
| 13 | +class TestIntegrations: |
| 14 | + @classmethod |
| 15 | + def setup_class(cls): |
| 16 | + cls.client = connect.Client() |
| 17 | + cls.integration = cls.client.oauth.integrations.create( |
| 18 | + name="example integration", |
| 19 | + description="integration description", |
| 20 | + template="custom", |
| 21 | + config={ |
| 22 | + "auth_mode": "Confidential", |
| 23 | + "authorization_uri": "https://example.com/__tenand_id__/oauth2/v2.0/authorize", |
| 24 | + "client_id": "client_id", |
| 25 | + "client_secret": "client_secret", |
| 26 | + "scopes": "a b c", |
| 27 | + "token_endpoint_auth_method": "client_secret_post", |
| 28 | + "token_uri": "https://example.com/__tenant_id__/oauth2/v2.0/token", |
| 29 | + }, |
| 30 | + ) |
| 31 | + |
| 32 | + cls.another_integration = cls.client.oauth.integrations.create( |
| 33 | + name="another example integration", |
| 34 | + description="another integration description", |
| 35 | + template="custom", |
| 36 | + config={ |
| 37 | + "auth_mode": "Confidential", |
| 38 | + "authorization_uri": "https://example.com/__tenand_id__/oauth2/v2.0/authorize", |
| 39 | + "client_id": "client_id", |
| 40 | + "client_secret": "client_secret", |
| 41 | + "scopes": "a b c", |
| 42 | + "token_endpoint_auth_method": "client_secret_post", |
| 43 | + "token_uri": "https://example.com/__tenant_id__/oauth2/v2.0/token", |
| 44 | + }, |
| 45 | + ) |
| 46 | + |
| 47 | + @classmethod |
| 48 | + def teardown_class(cls): |
| 49 | + cls.integration.delete() |
| 50 | + cls.another_integration.delete() |
| 51 | + assert len(cls.client.oauth.integrations.find()) == 0 |
| 52 | + |
| 53 | + def test_get(self): |
| 54 | + result = self.client.oauth.integrations.get(self.integration.guid) |
| 55 | + assert result == self.integration |
| 56 | + |
| 57 | + def test_find(self): |
| 58 | + results = self.client.oauth.integrations.find() |
| 59 | + assert len(results) == 2 |
| 60 | + assert results[0] == self.integration |
| 61 | + assert results[1] == self.another_integration |
| 62 | + |
| 63 | + def test_create_update_delete(self): |
| 64 | + # create a new integration |
| 65 | + |
| 66 | + integration = self.client.oauth.integrations.create( |
| 67 | + name="new integration", |
| 68 | + description="new integration description", |
| 69 | + template="custom", |
| 70 | + config={ |
| 71 | + "auth_mode": "Confidential", |
| 72 | + "authorization_uri": "https://example.com/__tenand_id__/oauth2/v2.0/authorize", |
| 73 | + "client_id": "client_id", |
| 74 | + "client_secret": "client_secret", |
| 75 | + "scopes": "a b c", |
| 76 | + "token_endpoint_auth_method": "client_secret_post", |
| 77 | + "token_uri": "https://example.com/__tenant_id__/oauth2/v2.0/token", |
| 78 | + }, |
| 79 | + ) |
| 80 | + |
| 81 | + created = self.client.oauth.integrations.get(integration.guid) |
| 82 | + assert created == integration |
| 83 | + |
| 84 | + all_integrations = self.client.oauth.integrations.find() |
| 85 | + assert len(all_integrations) == 3 |
| 86 | + |
| 87 | + # update the new integration |
| 88 | + |
| 89 | + created.update(name="updated integration name") |
| 90 | + updated = self.client.oauth.integrations.get(integration.guid) |
| 91 | + assert updated.name == "updated integration name" |
| 92 | + |
| 93 | + # delete the new integration |
| 94 | + |
| 95 | + created.delete() |
| 96 | + all_integrations_after_delete = self.client.oauth.integrations.find() |
| 97 | + assert len(all_integrations_after_delete) == 2 |
0 commit comments