Skip to content

Commit 2728411

Browse files
chore: update SDK to v0.5.0
1 parent e730c4f commit 2728411

File tree

100 files changed

+25435
-9968
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+25435
-9968
lines changed

conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
project = "X API SDK"
2222
copyright = "2024, X Developer Platform"
2323
author = "X Developer Platform"
24-
release = "0.4.6"
25-
version = "0.4.6"
24+
release = "0.5.0"
25+
version = "0.5.0"
2626

2727
# -- General configuration ----------------------------------------------------
2828

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ build-backend = "hatchling.build"
1414

1515
[project]
1616
name = "xdk"
17-
version = "0.4.6"
17+
version = "0.5.0"
1818
description = "Python SDK for the X API"
1919
authors = [
2020
{name = "X Developer Platform", email = "[email protected]"},

scripts/process-for-mintlify.py

Lines changed: 1504 additions & 279 deletions
Large diffs are not rendered by default.

tests/account_activity/test_contracts.py

Lines changed: 148 additions & 133 deletions
Large diffs are not rendered by default.

tests/account_activity/test_generic.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ class TestAccountActivityGeneric:
2424

2525
def setup_class(self):
2626
"""Set up test fixtures."""
27-
self.client = Client(base_url="https://api.example.com")
27+
# Provide all authentication types for comprehensive test coverage
28+
# Tests mock the session, so actual HTTP requests won't be made
29+
from xdk.oauth1_auth import OAuth1
30+
oauth1 = OAuth1(
31+
api_key="test_api_key",
32+
api_secret="test_api_secret",
33+
callback="http://localhost:8080/callback",
34+
access_token="test_access_token",
35+
access_token_secret="test_access_token_secret",
36+
)
37+
self.client = Client(
38+
base_url="https://api.example.com",
39+
bearer_token="test_bearer_token",
40+
access_token="test_access_token",
41+
auth=oauth1,
42+
)
2843
self.account_activity_client = getattr(self.client, "account_activity")
2944

3045

tests/account_activity/test_structure.py

Lines changed: 93 additions & 78 deletions
Large diffs are not rendered by default.

tests/activity/test_contracts.py

Lines changed: 98 additions & 83 deletions
Large diffs are not rendered by default.

tests/activity/test_generic.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ class TestActivityGeneric:
2424

2525
def setup_class(self):
2626
"""Set up test fixtures."""
27-
self.client = Client(base_url="https://api.example.com")
27+
# Provide all authentication types for comprehensive test coverage
28+
# Tests mock the session, so actual HTTP requests won't be made
29+
from xdk.oauth1_auth import OAuth1
30+
oauth1 = OAuth1(
31+
api_key="test_api_key",
32+
api_secret="test_api_secret",
33+
callback="http://localhost:8080/callback",
34+
access_token="test_access_token",
35+
access_token_secret="test_access_token_secret",
36+
)
37+
self.client = Client(
38+
base_url="https://api.example.com",
39+
bearer_token="test_bearer_token",
40+
access_token="test_access_token",
41+
auth=oauth1,
42+
)
2843
self.activity_client = getattr(self.client, "activity")
2944

3045

tests/activity/test_structure.py

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ class TestActivityStructure:
2424

2525
def setup_class(self):
2626
"""Set up test fixtures."""
27-
self.client = Client(base_url="https://api.example.com")
27+
# Provide all authentication types for comprehensive test coverage
28+
# Tests mock the session, so actual HTTP requests won't be made
29+
from xdk.oauth1_auth import OAuth1
30+
oauth1 = OAuth1(
31+
api_key="test_api_key",
32+
api_secret="test_api_secret",
33+
callback="http://localhost:8080/callback",
34+
access_token="test_access_token",
35+
access_token_secret="test_access_token_secret",
36+
)
37+
self.client = Client(
38+
base_url="https://api.example.com",
39+
bearer_token="test_bearer_token",
40+
access_token="test_access_token",
41+
auth=oauth1,
42+
)
2843
self.activity_client = getattr(self.client, "activity")
2944

3045

@@ -118,51 +133,6 @@ def test_create_subscription_return_annotation(self):
118133
), f"Method create_subscription should have return type annotation"
119134

120135

121-
def test_stream_exists(self):
122-
"""Test that stream method exists with correct signature."""
123-
# Check method exists
124-
method = getattr(ActivityClient, "stream", None)
125-
assert method is not None, f"Method stream does not exist on ActivityClient"
126-
# Check method is callable
127-
assert callable(method), f"stream is not callable"
128-
# Check method signature
129-
sig = inspect.signature(method)
130-
params = list(sig.parameters.keys())
131-
# Should have 'self' as first parameter
132-
assert len(params) >= 1, f"stream should have at least 'self' parameter"
133-
assert (
134-
params[0] == "self"
135-
), f"First parameter should be 'self', got '{params[0]}'"
136-
# Check required parameters exist (excluding 'self')
137-
required_params = []
138-
for required_param in required_params:
139-
assert (
140-
required_param in params
141-
), f"Required parameter '{required_param}' missing from stream"
142-
# Check optional parameters have defaults (excluding 'self')
143-
optional_params = [
144-
"backfill_minutes",
145-
"start_time",
146-
"end_time",
147-
]
148-
for optional_param in optional_params:
149-
if optional_param in params:
150-
param_obj = sig.parameters[optional_param]
151-
assert (
152-
param_obj.default is not inspect.Parameter.empty
153-
), f"Optional parameter '{optional_param}' should have a default value"
154-
155-
156-
def test_stream_return_annotation(self):
157-
"""Test that stream has proper return type annotation."""
158-
method = getattr(ActivityClient, "stream")
159-
sig = inspect.signature(method)
160-
# Check return annotation exists
161-
assert (
162-
sig.return_annotation is not inspect.Signature.empty
163-
), f"Method stream should have return type annotation"
164-
165-
166136
def test_update_subscription_exists(self):
167137
"""Test that update_subscription method exists with correct signature."""
168138
# Check method exists
@@ -257,14 +227,59 @@ def test_delete_subscription_return_annotation(self):
257227
), f"Method delete_subscription should have return type annotation"
258228

259229

230+
def test_stream_exists(self):
231+
"""Test that stream method exists with correct signature."""
232+
# Check method exists
233+
method = getattr(ActivityClient, "stream", None)
234+
assert method is not None, f"Method stream does not exist on ActivityClient"
235+
# Check method is callable
236+
assert callable(method), f"stream is not callable"
237+
# Check method signature
238+
sig = inspect.signature(method)
239+
params = list(sig.parameters.keys())
240+
# Should have 'self' as first parameter
241+
assert len(params) >= 1, f"stream should have at least 'self' parameter"
242+
assert (
243+
params[0] == "self"
244+
), f"First parameter should be 'self', got '{params[0]}'"
245+
# Check required parameters exist (excluding 'self')
246+
required_params = []
247+
for required_param in required_params:
248+
assert (
249+
required_param in params
250+
), f"Required parameter '{required_param}' missing from stream"
251+
# Check optional parameters have defaults (excluding 'self')
252+
optional_params = [
253+
"backfill_minutes",
254+
"start_time",
255+
"end_time",
256+
]
257+
for optional_param in optional_params:
258+
if optional_param in params:
259+
param_obj = sig.parameters[optional_param]
260+
assert (
261+
param_obj.default is not inspect.Parameter.empty
262+
), f"Optional parameter '{optional_param}' should have a default value"
263+
264+
265+
def test_stream_return_annotation(self):
266+
"""Test that stream has proper return type annotation."""
267+
method = getattr(ActivityClient, "stream")
268+
sig = inspect.signature(method)
269+
# Check return annotation exists
270+
assert (
271+
sig.return_annotation is not inspect.Signature.empty
272+
), f"Method stream should have return type annotation"
273+
274+
260275
def test_all_expected_methods_exist(self):
261276
"""Test that all expected methods exist on the client."""
262277
expected_methods = [
263278
"get_subscriptions",
264279
"create_subscription",
265-
"stream",
266280
"update_subscription",
267281
"delete_subscription",
282+
"stream",
268283
]
269284
for expected_method in expected_methods:
270285
assert hasattr(

tests/communities/test_contracts.py

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,27 @@ class TestCommunitiesContracts:
2424

2525
def setup_class(self):
2626
"""Set up test fixtures."""
27-
self.client = Client(base_url="https://api.example.com")
27+
# Provide all authentication types for comprehensive test coverage
28+
# Tests mock the session, so actual HTTP requests won't be made
29+
from xdk.oauth1_auth import OAuth1
30+
oauth1 = OAuth1(
31+
api_key="test_api_key",
32+
api_secret="test_api_secret",
33+
callback="http://localhost:8080/callback",
34+
access_token="test_access_token",
35+
access_token_secret="test_access_token_secret",
36+
)
37+
self.client = Client(
38+
base_url="https://api.example.com",
39+
bearer_token="test_bearer_token",
40+
access_token="test_access_token",
41+
auth=oauth1,
42+
)
2843
self.communities_client = getattr(self.client, "communities")
2944

3045

31-
def test_search_request_structure(self):
32-
"""Test search request structure."""
46+
def test_get_by_id_request_structure(self):
47+
"""Test get_by_id request structure."""
3348
# Mock the session to capture request details
3449
with patch.object(self.client, "session") as mock_session:
3550
mock_response = Mock()
@@ -42,11 +57,11 @@ def test_search_request_structure(self):
4257
# Prepare test parameters
4358
kwargs = {}
4459
# Add required parameters
45-
kwargs["query"] = "test_query"
60+
kwargs["id"] = "test_value"
4661
# Add request body if required
4762
# Call the method
4863
try:
49-
method = getattr(self.communities_client, "search")
64+
method = getattr(self.communities_client, "get_by_id")
5065
# Check if this might be a streaming operation by inspecting return type
5166
import types
5267
import inspect
@@ -109,7 +124,7 @@ def test_search_request_structure(self):
109124
called_url = (
110125
call_args[0][0] if call_args[0] else call_args[1].get("url", "")
111126
)
112-
expected_path = "/2/communities/search"
127+
expected_path = "/2/communities/{id}"
113128
assert expected_path.replace("{", "").replace(
114129
"}", ""
115130
) in called_url or any(
@@ -125,12 +140,12 @@ def test_search_request_structure(self):
125140
# For regular operations, verify we got a result
126141
assert result is not None, "Method should return a result"
127142
except Exception as e:
128-
pytest.fail(f"Contract test failed for search: {e}")
143+
pytest.fail(f"Contract test failed for get_by_id: {e}")
129144

130145

131-
def test_search_required_parameters(self):
132-
"""Test that search handles parameters correctly."""
133-
method = getattr(self.communities_client, "search")
146+
def test_get_by_id_required_parameters(self):
147+
"""Test that get_by_id handles parameters correctly."""
148+
method = getattr(self.communities_client, "get_by_id")
134149
# Test with missing required parameters - mock the request to avoid network calls
135150
with patch.object(self.client, "session") as mock_session:
136151
# Mock a 400 response (typical for missing required parameters)
@@ -150,8 +165,8 @@ def test_search_required_parameters(self):
150165
next(result)
151166

152167

153-
def test_search_response_structure(self):
154-
"""Test search response structure validation."""
168+
def test_get_by_id_response_structure(self):
169+
"""Test get_by_id response structure validation."""
155170
with patch.object(self.client, "session") as mock_session:
156171
# Create mock response with expected structure
157172
mock_response_data = {
@@ -164,10 +179,10 @@ def test_search_response_structure(self):
164179
mock_session.get.return_value = mock_response
165180
# Prepare minimal valid parameters
166181
kwargs = {}
167-
kwargs["query"] = "test_value"
182+
kwargs["id"] = "test"
168183
# Add request body if required
169184
# Call method and verify response structure
170-
method = getattr(self.communities_client, "search")
185+
method = getattr(self.communities_client, "get_by_id")
171186
result = method(**kwargs)
172187
# Verify response object has expected attributes
173188
# Optional field - just check it doesn't cause errors if accessed
@@ -179,8 +194,8 @@ def test_search_response_structure(self):
179194
)
180195

181196

182-
def test_get_by_id_request_structure(self):
183-
"""Test get_by_id request structure."""
197+
def test_search_request_structure(self):
198+
"""Test search request structure."""
184199
# Mock the session to capture request details
185200
with patch.object(self.client, "session") as mock_session:
186201
mock_response = Mock()
@@ -193,11 +208,11 @@ def test_get_by_id_request_structure(self):
193208
# Prepare test parameters
194209
kwargs = {}
195210
# Add required parameters
196-
kwargs["id"] = "test_value"
211+
kwargs["query"] = "test_query"
197212
# Add request body if required
198213
# Call the method
199214
try:
200-
method = getattr(self.communities_client, "get_by_id")
215+
method = getattr(self.communities_client, "search")
201216
# Check if this might be a streaming operation by inspecting return type
202217
import types
203218
import inspect
@@ -260,7 +275,7 @@ def test_get_by_id_request_structure(self):
260275
called_url = (
261276
call_args[0][0] if call_args[0] else call_args[1].get("url", "")
262277
)
263-
expected_path = "/2/communities/{id}"
278+
expected_path = "/2/communities/search"
264279
assert expected_path.replace("{", "").replace(
265280
"}", ""
266281
) in called_url or any(
@@ -276,12 +291,12 @@ def test_get_by_id_request_structure(self):
276291
# For regular operations, verify we got a result
277292
assert result is not None, "Method should return a result"
278293
except Exception as e:
279-
pytest.fail(f"Contract test failed for get_by_id: {e}")
294+
pytest.fail(f"Contract test failed for search: {e}")
280295

281296

282-
def test_get_by_id_required_parameters(self):
283-
"""Test that get_by_id handles parameters correctly."""
284-
method = getattr(self.communities_client, "get_by_id")
297+
def test_search_required_parameters(self):
298+
"""Test that search handles parameters correctly."""
299+
method = getattr(self.communities_client, "search")
285300
# Test with missing required parameters - mock the request to avoid network calls
286301
with patch.object(self.client, "session") as mock_session:
287302
# Mock a 400 response (typical for missing required parameters)
@@ -301,8 +316,8 @@ def test_get_by_id_required_parameters(self):
301316
next(result)
302317

303318

304-
def test_get_by_id_response_structure(self):
305-
"""Test get_by_id response structure validation."""
319+
def test_search_response_structure(self):
320+
"""Test search response structure validation."""
306321
with patch.object(self.client, "session") as mock_session:
307322
# Create mock response with expected structure
308323
mock_response_data = {
@@ -315,10 +330,10 @@ def test_get_by_id_response_structure(self):
315330
mock_session.get.return_value = mock_response
316331
# Prepare minimal valid parameters
317332
kwargs = {}
318-
kwargs["id"] = "test"
333+
kwargs["query"] = "test_value"
319334
# Add request body if required
320335
# Call method and verify response structure
321-
method = getattr(self.communities_client, "get_by_id")
336+
method = getattr(self.communities_client, "search")
322337
result = method(**kwargs)
323338
# Verify response object has expected attributes
324339
# Optional field - just check it doesn't cause errors if accessed

0 commit comments

Comments
 (0)