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

Commit 6422b90

Browse files
authored
fix: Merge pull request #21 from seamapi/access-code-status
2 parents aa84d9f + bad73e1 commit 6422b90

File tree

16 files changed

+132
-52
lines changed

16 files changed

+132
-52
lines changed

.github/workflows/test.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Generated by seam-plop
2+
name: Python Test
3+
on:
4+
push:
5+
workflow_dispatch:
6+
inputs:
7+
sdkSha:
8+
description: "SHA of the seamapi-python commit to run against"
9+
type: string
10+
required: false
11+
connectSha:
12+
description: "SHA of the seam-connect commit to run against"
13+
type: string
14+
required: false
15+
prRepo:
16+
description: "Repository of PR context (needed when leaving comments)"
17+
type: string
18+
required: false
19+
prNumber:
20+
description: "PR number (needed when leaving comments)"
21+
type: string
22+
23+
jobs:
24+
test:
25+
runs-on: ubuntu-latest
26+
env:
27+
CONTAINER_REGISTRY: "registry.digitalocean.com"
28+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v2
32+
with:
33+
ref: ${{ github.event.inputs.sdkSha }}
34+
- name: Login to DO container registry
35+
uses: docker/login-action@v1
36+
with:
37+
registry: ${{ env.CONTAINER_REGISTRY }}
38+
username: ${{ secrets.DIGITAL_OCEAN_TOKEN }}
39+
password: ${{ secrets.DIGITAL_OCEAN_TOKEN }}
40+
- name: Pre-pull Seam Connect image
41+
run: docker pull ${{ env.CONTAINER_REGISTRY }}/seam/seam-connect:${{ github.event.inputs.connectSha || 'latest' }}
42+
- uses: actions/setup-python@v2
43+
with:
44+
python-version: 3.8
45+
- name: Install Poetry
46+
uses: snok/install-poetry@v1
47+
- if: ${{ github.event.inputs.prNumber }}
48+
uses: marocchino/sticky-pull-request-comment@v2
49+
with:
50+
number: ${{ github.event.inputs.prNumber }}
51+
repo: ${{ github.event.inputs.prRepo }}
52+
GITHUB_TOKEN: ${{ secrets.BOT_GH_TOKEN }}
53+
message: |
54+
⌛️ [running Python SDK tests](${{ env.RUN_URL }})...
55+
- run: poetry install
56+
- run: poetry run pytest -s
57+
- name: Comment on failure
58+
if: ${{ github.event.inputs.prNumber && failure() }}
59+
uses: marocchino/sticky-pull-request-comment@v2
60+
with:
61+
number: ${{ github.event.inputs.prNumber }}
62+
repo: ${{ github.event.inputs.prRepo }}
63+
GITHUB_TOKEN: ${{ secrets.BOT_GH_TOKEN }}
64+
message: |
65+
⛔️ [Python SDK tests failed](${{ env.RUN_URL }}).
66+
67+
- name: Comment on success
68+
if: ${{ github.event.inputs.prNumber && success() }}
69+
uses: marocchino/sticky-pull-request-comment@v2
70+
with:
71+
number: ${{ github.event.inputs.prNumber }}
72+
repo: ${{ github.event.inputs.prRepo }}
73+
GITHUB_TOKEN: ${{ secrets.BOT_GH_TOKEN }}
74+
message: |
75+
✅ [Python SDK tests passed](${{ env.RUN_URL }}).

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ seam.locks.lock_door(some_lock)
3232
This project uses [poetry](https://github.com/python-poetry/poetry)
3333

3434
- To setup the project and install dependencies run `poetry install`
35-
- To run tests, run `poetry run pytest`
35+
- To run tests, run `poetry run pytest -s`
3636
- To build the project for publishing, run `poetry build`
3737

3838
Commits to `main` following [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) will automatically be published to PyPI.

seamapi/access_codes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ def update(
231231
success_res: Any = action_attempt.result
232232
return AccessCode.from_dict(success_res["access_code"])
233233

234-
235234
def delete(
236235
self,
237236
access_code: Union[AccessCodeId, AccessCode],

seamapi/connect_webviews.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def list(self) -> List[ConnectWebview]:
5959
A list of connect webviews
6060
"""
6161

62-
res = requests.post(
62+
res = requests.get(
6363
f"{self.seam.api_url}/connect_webviews/list",
6464
headers={"Authorization": f"Bearer {self.seam.api_key}"},
6565
)

seamapi/connected_accounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def list(self) -> List[ConnectedAccount]:
5555
A list of connected accounts.
5656
"""
5757

58-
res = requests.post(
58+
res = requests.get(
5959
f"{self.seam.api_url}/connected_accounts/list",
6060
headers={"Authorization": f"Bearer {self.seam.api_key}"},
6161
)

seamapi/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class AccessCode:
8888
starts_at: Optional[str] = None
8989
ends_at: Optional[str] = None
9090
name: Optional[str] = ""
91+
status: Optional[str] = None
9192

9293

9394
class AbstractActionAttempts(abc.ABC):
@@ -149,6 +150,7 @@ def update(
149150
code: Optional[str] = None,
150151
starts_at: Optional[str] = None,
151152
ends_at: Optional[str] = None,
153+
status: Optional[str] = None,
152154
) -> AccessCode:
153155
raise NotImplementedError
154156

seamapi/workspaces.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def list(
6767
Workspace
6868
"""
6969

70-
workspace_id = to_workspace_id(workspace)
70+
workspace_id = None if workspace is None else to_workspace_id(workspace)
7171
res = requests.get(
7272
f"{self.seam.api_url}/workspaces/list",
7373
params={"workspace_id": workspace_id},
@@ -102,8 +102,7 @@ def get(
102102
------
103103
Workspace
104104
"""
105-
106-
workspace_id = to_workspace_id(workspace)
105+
workspace_id = None if workspace is None else to_workspace_id(workspace)
107106
res = requests.get(
108107
f"{self.seam.api_url}/workspaces/get",
109108
params={"workspace_id": workspace_id},

tests/access_codes/test_access_codes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from seamapi import Seam
2-
from tests.fixtures.login_via_schlage import login_via_schlage
2+
from tests.fixtures.run_august_factory import run_august_factory
33

44

55
def test_access_codes(seam: Seam):
6-
login_via_schlage(seam)
6+
run_august_factory(seam)
77

88
some_device = seam.devices.list()[0]
99

10-
created_access_code = seam.access_codes.create(some_device.device_id, "Test code", "4444")
10+
created_access_code = seam.access_codes.create(
11+
some_device.device_id, "Test code", "4444"
12+
)
1113
assert created_access_code.name == "Test code"
14+
assert created_access_code.status == "setting"
1215

1316
access_codes = seam.access_codes.list(some_device.device_id)
1417
assert len(access_codes) == 1

tests/action_attempts/test_action_attempts.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from seamapi import Seam
2-
from tests.fixtures.login_via_schlage import login_via_schlage
2+
from tests.fixtures.run_august_factory import run_august_factory
33

44

55
def test_action_attempts(seam: Seam):
6-
login_via_schlage(seam)
6+
run_august_factory(seam)
77

88
some_device = seam.devices.list()[0]
9-
created_access_code = seam.access_codes.create(some_device.device_id, "Test code", "4444")
9+
created_access_code = seam.access_codes.create(
10+
some_device.device_id, "Test code", "4444"
11+
)
1012
delete_action_attempt = seam.access_codes.delete(created_access_code)
1113

1214
action_attempt = seam.action_attempts.get(delete_action_attempt)

tests/conftest.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@ class SeamBackend:
2222
sandbox_api_key: str
2323

2424

25-
@pytest.fixture(scope="session")
25+
# TODO this should use scope="session", but there's some issue, this would
26+
# dramatically reduce test time to switch
27+
@pytest.fixture(scope="function")
2628
def seam_backend():
2729
with PostgresContainer("postgres:13", dbname="postgres") as pg:
2830
db_host = "host.docker.internal" if sys.platform == "darwin" else "172.17.0.1"
29-
db_url = f"postgresql://test:test@{db_host}:{pg.get_exposed_port(pg.port_to_expose)}/seam_api"
30-
with DockerContainer("seam-connect").with_env(
31+
db_url = f"postgresql://test:test@{db_host}:{pg.get_exposed_port(pg.port_to_expose)}/postgres"
32+
with DockerContainer("registry.digitalocean.com/seam/seam-connect").with_env(
3133
"DATABASE_URL",
3234
# TODO on mac us docker.host.internal instead of 172.17.0.1 when someone
3335
# with a mac needs to run tests
3436
db_url,
35-
).with_env("DATABASE_NAME", "seam_api").with_env("NODE_ENV", "test").with_env(
37+
).with_env("POSTGRES_DATABASE", "postgres").with_env(
38+
"NODE_ENV", "test"
39+
).with_env(
3640
"POSTGRES_HOST", db_host
3741
).with_env(
3842
"SERVER_BASE_URL", "http://localhost:3020"

0 commit comments

Comments
 (0)