Skip to content

Commit a4bcc12

Browse files
Extend testing (#107)
* Test headers * ci: Format code * Update test/headers_test.py * ci: Format code * Fix headers test * Fix header definition * Fix lint * Rename client_test.py * Test waiting for action attempt feature * ci: Format code * Remove Seam class Routes inheritence * Use Seam().client in headers test * Remove duplicate code * Don't adjust client to accommodate the test, test should replicate the behaviour of the lib --------- Co-authored-by: Seam Bot <devops@getseam.com>
1 parent e7b2dbf commit a4bcc12

5 files changed

Lines changed: 90 additions & 6 deletions

File tree

seam/seam_multi_workspace.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ def __init__(
6060
auth_headers=auth_headers,
6161
)
6262

63-
self.client = SeamHttpClient(
64-
base_url=endpoint,
65-
auth_headers=auth_headers,
66-
)
67-
6863
defaults = {"wait_for_action_attempt": wait_for_action_attempt}
6964

7065
self._workspaces = Workspaces(client=self.client, defaults=defaults)

test/api_key_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_seam_client_constructor_interprets_single_string_argument_as_api_key(se
3030
assert seam is not None
3131

3232
with pytest.raises(SeamInvalidTokenError, match=r"api_key"):
33-
Seam(api_key="some-invalid-key-format")
33+
Seam("some-invalid-key-format")
3434

3535

3636
def test_seam_client_checks_api_key_format():

test/headers_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import niquests
2+
import uuid
3+
from unittest.mock import patch, Mock
4+
from seam import Seam
5+
from importlib.metadata import version
6+
from seam.constants import LTS_VERSION
7+
8+
9+
def test_seam_http_client_request(server):
10+
endpoint, seed = server
11+
seam = Seam.from_api_key(seed["seam_apikey1_token"], endpoint=endpoint)
12+
device_id = str(uuid.uuid4())
13+
14+
mock_response = Mock()
15+
mock_response.status_code = 200
16+
mock_response.headers = {"content-type": "application/json"}
17+
mock_response_data = {"device": {"device_id": device_id}}
18+
mock_response.json.return_value = mock_response_data
19+
20+
with patch.object(
21+
niquests.Session, "request", return_value=mock_response
22+
) as mock_request:
23+
response = seam.client.post("/devices/get", json={"device_id": device_id})
24+
25+
mock_request.assert_called_once()
26+
args, _ = mock_request.call_args
27+
28+
assert args[0] == "POST"
29+
assert args[1] == f"{endpoint}/devices/get"
30+
31+
passed_headers = mock_request.call_args.kwargs["headers"] or {}
32+
request_headers = {
33+
**seam.client.headers,
34+
**passed_headers,
35+
}
36+
37+
assert request_headers["seam-sdk-name"] == "seamapi/python"
38+
assert request_headers["seam-sdk-version"] == version("seam")
39+
assert request_headers["seam-lts-version"] == LTS_VERSION
40+
41+
assert response == mock_response_data
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pytest
2+
from seam import Seam
3+
4+
5+
def test_wait_for_action_attempt_directly_on_returned_action_attempt(server):
6+
endpoint, seed = server
7+
seam = Seam.from_api_key(
8+
seed["seam_apikey1_token"], endpoint=endpoint, wait_for_action_attempt=False
9+
)
10+
11+
action_attempt = seam.locks.unlock_door(
12+
device_id=seed["august_device_1"], wait_for_action_attempt=True
13+
)
14+
15+
assert action_attempt.status == "success"
16+
17+
18+
def test_wait_for_action_attempt_by_default(server):
19+
endpoint, seed = server
20+
seam = Seam.from_api_key(seed["seam_apikey1_token"], endpoint=endpoint)
21+
22+
action_attempt = seam.locks.unlock_door(device_id=seed["august_device_1"])
23+
24+
assert action_attempt.status == "success"
25+
26+
27+
def test_wait_for_action_attempt_can_set_class_default(server):
28+
endpoint, seed = server
29+
seam = Seam.from_api_key(
30+
seed["seam_apikey1_token"], endpoint=endpoint, wait_for_action_attempt=False
31+
)
32+
33+
action_attempt = seam.locks.unlock_door(device_id=seed["august_device_1"])
34+
35+
assert action_attempt.status == "pending"
36+
37+
38+
def test_wait_for_action_attempt_can_set_class_default_with_object(server):
39+
endpoint, seed = server
40+
seam = Seam.from_api_key(
41+
seed["seam_apikey1_token"],
42+
endpoint=endpoint,
43+
wait_for_action_attempt={"timeout": 5000},
44+
)
45+
46+
action_attempt = seam.locks.unlock_door(device_id=seed["august_device_1"])
47+
48+
assert action_attempt.status == "success"

0 commit comments

Comments
 (0)