|
1 | 1 | """BDD step definitions for Destination integration tests.""" |
2 | 2 |
|
3 | 3 | import concurrent.futures |
| 4 | +import os |
4 | 5 | from typing import List, Optional |
5 | 6 |
|
6 | 7 | import pytest |
|
17 | 18 | ConsumptionOptions, |
18 | 19 | PatchLabels, |
19 | 20 | ) |
| 21 | +from sap_cloud_sdk.destination._destination_http_client import DestinationHttpClient |
20 | 22 | from sap_cloud_sdk.destination.exceptions import ( |
21 | 23 | HttpError, |
22 | 24 | DestinationOperationError, |
@@ -57,6 +59,8 @@ def __init__(self): |
57 | 59 | self.updated_certificate_content: Optional[str] = None |
58 | 60 | self.tenant: Optional[str] = None |
59 | 61 | self.retrieved_labels: List[Label] = [] |
| 62 | + self.http_client: Optional[DestinationHttpClient] = None |
| 63 | + self.http_response = None |
60 | 64 |
|
61 | 65 |
|
62 | 66 | @pytest.fixture |
@@ -1572,3 +1576,38 @@ def certificate_should_have_label(context, key, value): |
1572 | 1576 | lbl.key == key and value in lbl.values |
1573 | 1577 | for lbl in context.retrieved_labels |
1574 | 1578 | ), f"Expected label key='{key}' value='{value}' in {context.retrieved_labels}" |
| 1579 | + |
| 1580 | + |
| 1581 | +# ==================== DESTINATION HTTP CLIENT STEPS ==================== |
| 1582 | + |
| 1583 | +@given("the destination has OAuth2 credentials from environment") |
| 1584 | +def destination_has_oauth2_credentials(context): |
| 1585 | + context.destination.properties.update({ |
| 1586 | + "clientId": os.environ["CLOUD_SDK_CFG_DESTINATION_DEFAULT_CLIENTID"], |
| 1587 | + "clientSecret": os.environ["CLOUD_SDK_CFG_DESTINATION_DEFAULT_CLIENTSECRET"], |
| 1588 | + "tokenServiceURL": os.environ["CLOUD_SDK_CFG_DESTINATION_DEFAULT_URL"] + "/oauth/token", |
| 1589 | + }) |
| 1590 | + |
| 1591 | + |
| 1592 | +@when("I fetch the destination using the v2 API") |
| 1593 | +def fetch_destination_v2(context, destination_client): |
| 1594 | + context.retrieved_destination = destination_client.get_destination(context.destination.name) |
| 1595 | + |
| 1596 | + |
| 1597 | +@when("I create a DestinationHttpClient from the destination") |
| 1598 | +def create_http_client(context): |
| 1599 | + context.http_client = DestinationHttpClient(context.retrieved_destination) |
| 1600 | + |
| 1601 | + |
| 1602 | +@when(parsers.parse('I send a GET request to "{path}"')) |
| 1603 | +def send_get_request(context, path): |
| 1604 | + context.http_response = context.http_client.request("GET", path) |
| 1605 | + |
| 1606 | + |
| 1607 | +@then("the response contains an Authorization header") |
| 1608 | +def assert_authorization_header_present(context): |
| 1609 | + echoed = context.http_response.json().get("headers", {}) |
| 1610 | + assert "Authorization" in echoed, ( |
| 1611 | + f"Expected Authorization header in response, got: {list(echoed.keys())}. " |
| 1612 | + "Check that BTP returned an auth token for the destination." |
| 1613 | + ) |
0 commit comments