Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 3609f93

Browse files
committed
filling up tests
1 parent bc6556d commit 3609f93

13 files changed

+85
-20
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"python.venvFolders": ["/home/seve/w/seam/seamapi-python/.venv"]
2+
// "python.venvFolders": ["/home/seve/w/seam/seamapi-python/.venv"]
33
}

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ seam.locks.lock_door(some_lock)
3131

3232
This project uses [poetry](https://github.com/python-poetry/poetry)
3333

34+
- To setup the project and install dependencies run `poetry install`
3435
- To run tests, run `poetry run pytest`
3536
- To build the project for publishing, run `poetry build`
3637
- To publish the project run `poetry build`
@@ -39,3 +40,10 @@ Our tests use a seam sandbox environment given by the environment
3940
variables `SEAM_SANDBOX_API_KEY`. If you want to run the tests, you should
4041
first create a sandbox workspace [on your dashboard](https://dashboard.getseam.com)
4142
then create a sandbox workspace.
43+
44+
> NOTE: For installation on m1 mac, you may need to export the following lines
45+
> prior to `poetry install`...
46+
>
47+
> `export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"`
48+
>
49+
> `export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib -L${HOME}/.pyenv/versions/3.8.10/lib"`

seamapi/connect_webviews.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def list(self) -> List[ConnectWebview]:
3434
]
3535

3636
def get(self, connect_webview_id: str) -> ConnectWebview:
37-
res = requests.post(
37+
res = requests.get(
3838
f"{self.seam.api_url}/connect_webviews/get",
3939
headers={"Authorization": f"Bearer {self.seam.api_key}"},
4040
params={"connect_webview_id": connect_webview_id},

seamapi/devices.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def list(
3535
devices = res.json()["devices"]
3636
return [Device.from_dict(d) for d in devices]
3737

38-
def get(self, device: Union[DeviceId, Device]) -> Device:
38+
def get(
39+
self,
40+
device: Optional[Union[DeviceId, Device]] = None,
41+
name: Optional[str] = None,
42+
) -> Device:
3943
device_id = to_device_id(device)
4044
res = requests.get(
4145
f"{self.seam.api_url}/devices/get",

seamapi/locks.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ def list(
4343
json_locks = res.json()["devices"]
4444
return [Device.from_dict(d) for d in json_locks]
4545

46-
def get(self, device: Union[DeviceId, Device]) -> Device:
47-
device_id = to_device_id(device)
46+
def get(
47+
self,
48+
device: Optional[Union[DeviceId, Device]] = None,
49+
name: Optional[str] = None,
50+
) -> Device:
51+
params = {}
52+
if device:
53+
params["device_id"] = to_device_id(device)
54+
if name:
55+
params["name"] = name
4856
res = requests.post(
4957
f"{self.seam.api_url}/locks/get",
5058
headers={"Authorization": f"Bearer {self.seam.api_key}"},
51-
params={"device_id": device_id},
59+
params=params,
5260
)
5361
if not res.ok:
5462
raise Exception(res.text)

seamapi/types.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ def list(self) -> List[Device]:
151151
raise NotImplementedError
152152

153153
@abc.abstractmethod
154-
def get(self, device: Union[DeviceId, Device]) -> Device:
154+
def get(
155+
self,
156+
device: Optional[Union[DeviceId, Device]] = None,
157+
name: Optional[str] = None,
158+
) -> Device:
155159
raise NotImplementedError
156160

157161

tests/conftest.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dotenv import load_dotenv
66
from typing import Any
77
from dataclasses import dataclass
8+
import sys
89
from testcontainers.postgres import PostgresContainer
910
from testcontainers.core.container import DockerContainer
1011
from testcontainers.core.waiting_utils import wait_for_logs
@@ -21,7 +22,7 @@ class SeamBackend:
2122
sandbox_api_key: str
2223

2324

24-
@pytest.fixture
25+
@pytest.fixture(scope="session")
2526
def seam_backend():
2627
with PostgresContainer("postgres:13", dbname="postgres") as pg:
2728
db_host = "host.docker.internal" if sys.platform == "darwin" else "172.17.0.1"
@@ -34,18 +35,18 @@ def seam_backend():
3435
).with_env("DATABASE_NAME", "seam_api").with_env("NODE_ENV", "test").with_env(
3536
"POSTGRES_HOST", db_host
3637
).with_env(
37-
"SERVER_BASE_URL", "http://localhost:3021"
38+
"SERVER_BASE_URL", "http://localhost:3000"
3839
).with_env(
3940
"SEAMTEAM_ADMIN_PASSWORD", "1234"
4041
).with_bind_ports(
41-
3000, 4020
42+
3000, 3000
4243
).with_command(
4344
"start:for-integration-testing"
4445
) as sc_container:
4546
wait_for_logs(sc_container, r"started server", timeout=20)
46-
requests.get("http://localhost:4020/health")
47+
requests.get("http://localhost:3000/health")
4748
yield SeamBackend(
48-
url="http://localhost:4020",
49+
url="http://localhost:3000",
4950
sandbox_api_key="seam_sandykey_0000000000000000000sand",
5051
)
5152

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from seamapi import Seam
2+
3+
4+
def test_connect_webviews(seam: Seam):
5+
webview = seam.connect_webviews.create(accepted_providers=["schlage"])
6+
7+
assert webview.url is not None

tests/devices/test_devices.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from seamapi import Seam
2+
from tests.fixtures.login_via_schlage import login_via_schlage
3+
4+
5+
def test_devices(seam: Seam):
6+
login_via_schlage(seam)
7+
8+
devices = seam.devices.list()
9+
10+
some_device = seam.devices.get(name="FRONT DOOR")
11+
print(some_device)
12+
13+
print(devices)
14+
15+
pass

tests/fixtures/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .login_via_schlage import login_via_schlage

tests/fixtures/login_via_schlage.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from seamapi import Seam
2+
import time
3+
import requests
4+
5+
6+
def login_via_schlage(seam: Seam):
7+
webview = seam.connect_webviews.create(accepted_providers=["schlage"])
8+
print(seam.workspaces.get())
9+
print(webview)
10+
11+
# This is an internal endpoint that will be removed, don't use it, see how
12+
# it says "internal" there? It's not going to stick around.
13+
schlage_login_res = requests.post(
14+
f"{seam.api_url}/internal/schlage/login",
15+
json={
16+
"email": "[email protected]",
17+
"password": "1234",
18+
"connect_webview_id": webview.connect_webview_id,
19+
},
20+
).json()
21+
22+
# We've completed a webview login, which will load devices into this
23+
# workspace
24+
pass

tests/test_init_seam.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
from seamapi import Seam
22

33

4-
# def test_init_seam():
5-
# seam = Seam()
6-
# assert seam.api_key
7-
# assert seam.api_url
8-
9-
104
def test_init_seam_with_fixture(seam: Seam):
115
assert seam.api_key
126
assert seam.api_url
13-
assert "https" in seam.api_url and "localhost" in seam.api_url
7+
assert "http" in seam.api_url and "localhost" in seam.api_url

tests/workspaces/test_workspaces_get.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
def test_workspaces_get(seam: Seam):
55
ws = seam.workspaces.get()
6-
assert ws.name == "PythonLibrarySandbox"
76
assert ws.is_sandbox == True

0 commit comments

Comments
 (0)