Skip to content

Commit 0b145d9

Browse files
committed
update base url option
1 parent 36a554b commit 0b145d9

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

planet/cli/subscriptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def subscriptions(ctx, base_url):
8787
"pending",
8888
"completed",
8989
"suspended",
90-
"failed"
90+
"failed",
91+
"invalid",
9192
]),
9293
multiple=True,
9394
help="Select subscriptions in one or more states. Default is all.")

planet/sync/client.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,27 @@ class Planet:
3737
Parameters:
3838
session: Optional Session. The Session can be provided allowing for customization, and
3939
will default to standard behavior when not provided.
40+
data_base_url: Optional base URL for Data API. Defaults to production.
41+
orders_base_url: Optional base URL for Orders API. Defaults to production.
42+
subscriptions_base_url: Optional base URL for Subscriptions API. Defaults to production.
43+
features_base_url: Optional base URL for Features API. Defaults to production.
4044
4145
"""
4246

43-
def __init__(self, session: Optional[Session] = None) -> None:
47+
def __init__(self,
48+
session: Optional[Session] = None,
49+
data_base_url: Optional[str] = None,
50+
orders_base_url: Optional[str] = None,
51+
subscriptions_base_url: Optional[str] = None,
52+
features_base_url: Optional[str] = None) -> None:
4453
self._session = session or Session()
4554
self._session._client.headers.update({
4655
"X-Planet-App": SYNC_CLIENT_X_PLANET_APP,
4756
"User-Agent": f"planet-client-python/{__version__}/sync",
4857
})
4958

50-
self.data = DataAPI(self._session)
51-
self.orders = OrdersAPI(self._session)
52-
self.subscriptions = SubscriptionsAPI(self._session)
53-
self.features = FeaturesAPI(self._session)
59+
self.data = DataAPI(self._session, data_base_url)
60+
self.orders = OrdersAPI(self._session, orders_base_url)
61+
self.subscriptions = SubscriptionsAPI(self._session,
62+
subscriptions_base_url)
63+
self.features = FeaturesAPI(self._session, features_base_url)

test_base_url_functionality.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
"""Simple test to verify base URL functionality works correctly."""
3+
4+
import sys
5+
import os
6+
sys.path.insert(0, os.path.abspath('.'))
7+
8+
from planet.sync import Planet
9+
10+
def test_planet_base_url_configuration():
11+
"""Test that Planet client accepts and uses custom base URLs."""
12+
13+
# Test with custom base URLs
14+
custom_data_url = "https://custom-data.planet.com"
15+
custom_orders_url = "https://custom-orders.planet.com"
16+
custom_subscriptions_url = "https://custom-subscriptions.planet.com"
17+
custom_features_url = "https://custom-features.planet.com"
18+
19+
# Create Planet client with custom base URLs
20+
pl = Planet(
21+
data_base_url=custom_data_url,
22+
orders_base_url=custom_orders_url,
23+
subscriptions_base_url=custom_subscriptions_url,
24+
features_base_url=custom_features_url
25+
)
26+
27+
# Verify the base URLs are correctly set
28+
assert pl.data._client._base_url == custom_data_url
29+
assert pl.orders._client._base_url == custom_orders_url
30+
assert pl.subscriptions._client._base_url == custom_subscriptions_url
31+
assert pl.features._client._base_url == custom_features_url
32+
33+
print("✓ All custom base URLs are correctly set")
34+
35+
def test_planet_default_base_urls():
36+
"""Test that Planet client uses default base URLs when none provided."""
37+
38+
# Create Planet client with defaults
39+
pl = Planet()
40+
41+
# Verify default base URLs are used
42+
assert "https://api.planet.com/data/v1" in pl.data._client._base_url
43+
assert "https://api.planet.com/compute/ops" in pl.orders._client._base_url
44+
assert "https://api.planet.com/subscriptions/v1" in pl.subscriptions._client._base_url
45+
assert "https://api.planet.com/features/v1/ogc/my" in pl.features._client._base_url
46+
47+
print("✓ All default base URLs are correctly set")
48+
49+
if __name__ == "__main__":
50+
test_planet_base_url_configuration()
51+
test_planet_default_base_urls()
52+
print("All tests passed! 🎉")

0 commit comments

Comments
 (0)