Skip to content

Commit 805e00f

Browse files
committed
feat: addn suport to sms tools and testing
1 parent a7531a1 commit 805e00f

File tree

13 files changed

+187
-22
lines changed

13 files changed

+187
-22
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ patch_templates:
2020
rm -rf $$VENV
2121

2222
tests:
23-
uv run pytest -rs -m e2e
23+
uv run pytest -rs -v -s -m e2e
2424

2525
clean-tests:
2626
@source .venv/bin/activate && \

appwrite_lab/_orchestrator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _deploy_compose_service(
145145
146146
Args:
147147
project: The name of the project to deploy the service to.
148-
template_path: The path to the template to use for the service.
148+
template_paths: The path to the template to use for the service.
149149
env_vars: The environment variables to set.
150150
env_file: The path to the environment file to use for the service.
151151
extra_args: Extra arguments to pass to the compose command.
@@ -157,7 +157,6 @@ def _deploy_compose_service(
157157
for path in template_paths:
158158
file_overlays.extend(["-f", str(path)])
159159

160-
new_env = {**os.environ, **env_vars}
161160
cmd = [
162161
*self.compose,
163162
*file_overlays,
@@ -168,7 +167,7 @@ def _deploy_compose_service(
168167
"up",
169168
"-d",
170169
]
171-
return self._run_cmd_safely(cmd, envs=new_env)
170+
return self._run_cmd_safely(cmd, envs=env_vars)
172171

173172
def deploy_appwrite_lab(
174173
self,
@@ -267,6 +266,8 @@ def deploy_appwrite_lab(
267266
version=version,
268267
url=url,
269268
**_kwargs,
269+
sms_shim_url="https://localhost:4443",
270+
mailpit_url="http://localhost:8025",
270271
)
271272

272273
lab.generate_missing_config()

appwrite_lab/_state.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
from pathlib import Path
43

54
from .utils import get_state_path
65

appwrite_lab/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Lab(_BaseClass):
5151
default_factory=lambda: {"default": Project(None, None, None)}
5252
)
5353
_file: str = field(default="")
54+
sms_shim_url: str = field(default="")
55+
mailpit_url: str = field(default="")
5456

5557
def generate_missing_config(self):
5658
"""Generate missing data config with random values."""

appwrite_lab/templates/environment/dotenv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ _APP_SMTP_PORT=1025
5555
_APP_SMTP_SECURE=
5656
_APP_SMTP_USERNAME=
5757
_APP_SMTP_PASSWORD=
58-
_APP_SMS_PROVIDER=
59-
_APP_SMS_FROM=
58+
_APP_SMS_PROVIDER=sms://twilio:shim@twilio
59+
_APP_SMS_FROM=+15555555555
6060
_APP_STORAGE_LIMIT=30000000
6161
_APP_STORAGE_PREVIEW_LIMIT=20000000
6262
_APP_STORAGE_ANTIVIRUS=disabled

appwrite_lab/templates/extras/twilio-shim/docker_compose.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ x-sms-env: &sms_env
33
_APP_SMS_FROM: ${_APP_SMS_FROM:-+15555555555}
44

55
networks:
6-
appwrite_net:
7-
external: true
6+
appwrite:
87
name: appwrite
98

109
volumes:
@@ -29,7 +28,7 @@ services:
2928
- fake_twilio_certs:/certs
3029
ports: ["4443:443"] # dev-only host access
3130
networks:
32-
appwrite_net:
31+
appwrite:
3332
aliases: [api.twilio.com]
3433
restart: unless-stopped
3534
healthcheck:
@@ -47,7 +46,7 @@ services:
4746
volumes:
4847
- fake_twilio_certs:/usr/local/share/ca-certificates:ro
4948
- php_extra_conf:/opt/php-extra-conf.d:ro
50-
networks: [appwrite_net]
49+
networks: [appwrite]
5150

5251
appwrite-worker-messaging:
5352
depends_on:
@@ -59,4 +58,4 @@ services:
5958
volumes:
6059
- fake_twilio_certs:/usr/local/share/ca-certificates:ro
6160
- php_extra_conf:/opt/php-extra-conf.d:ro
62-
networks: [appwrite_net]
61+
networks: [appwrite]

appwrite_lab/tools/sms.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from appwrite_lab.models import Lab
2+
from httpx import AsyncClient
3+
4+
5+
class SMS:
6+
def __init__(self, lab: Lab):
7+
self.url = lab.sms_shim_url
8+
9+
async def get_messages(self):
10+
async with AsyncClient(verify=False) as client:
11+
response = await client.get(f"{self.url}/inbox")
12+
return response.json().get("messages")
13+
14+
async def clear_messages(self):
15+
async with AsyncClient(verify=False) as client:
16+
response = await client.post(f"{self.url}/clear")
17+
return response.json().get("ok")

pyproject.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ version = "0.1.2"
88
description = "Zero-click Appwrite test environments."
99
readme = "README.md"
1010
requires-python = ">=3.11"
11-
dependencies = ["playwright", "typer>=0.16.0", "python-dotenv>=1.1.0", "pytest>=8.4.1"]
11+
dependencies = [
12+
"playwright",
13+
"typer>=0.16.0",
14+
"python-dotenv>=1.1.0",
15+
"pytest>=8.4.1",
16+
"httpx>=0.28.1",
17+
"pytest-asyncio>=1.1.0",
18+
]
1219
license = "MIT"
1320

1421
[tool.setuptools]
@@ -23,6 +30,5 @@ appwrite-lab = "appwrite_lab.cli.entry:app"
2330
awlab = "appwrite_lab.cli.entry:app"
2431

2532
[tool.pytest.ini_options]
26-
markers = [
27-
"e2e: mark test as e2e",
28-
]
33+
markers = ["e2e: mark test as e2e"]
34+
asyncio_mode = "auto"

tests/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22
from pathlib import Path
33
from appwrite_lab.models import Lab
44
from appwrite_lab.test_suite import lab_svc, appwrite_file, lab_config, lab
5+
from appwrite_lab.tools.sms import SMS
56

67

78
@pytest.fixture(scope="session")
89
def appwrite_file_path():
910
return Path(__file__).parent / "data" / "appwrite.json"
10-
11+
12+
13+
@pytest.fixture(scope="session")
14+
def sms(lab: Lab):
15+
return SMS(lab)
16+
17+
18+
@pytest.fixture(autouse=True)
19+
async def clear_sms(sms: SMS):
20+
yield
21+
await sms.clear_messages()

tests/test_labs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
from appwrite_lab.labs import Labs
33
from appwrite_lab.automations.models import Expiration
44
import pytest
5-
5+
import uuid
66

77
@pytest.mark.e2e
88
def test_labs_new(lab: Lab):
99
assert lab.name == "test-lab"
1010
assert lab.version == "1.7.4"
11-
assert lab.url.endswith("8080")
11+
assert lab.url.endswith("80")
1212
assert lab.projects.get("default") is not None
1313

1414

1515
@pytest.mark.e2e
1616
def test_labs_create_api_key(lab: Lab, lab_svc: Labs):
1717
default = lab.projects.get("default")
18+
if default.api_key:
19+
pytest.skip("API key already exists")
1820
res = lab_svc.create_api_key(
1921
project_name=default.project_name,
2022
key_name="default-api-key",
@@ -37,8 +39,9 @@ def test_labs_synced_project(lab: Lab, lab_svc: Labs):
3739

3840
@pytest.mark.e2e
3941
def test_labs_create_project(lab: Lab, lab_svc: Labs):
40-
project_name = "test-project"
41-
project_id = "test-project-id"
42+
nonce = str(uuid.uuid4())[:8]
43+
project_name = f"test-project-{nonce}"
44+
project_id = f"test-project-id-{nonce}"
4245
res = lab_svc.create_project(
4346
project_name=project_name,
4447
project_id=project_id,

0 commit comments

Comments
 (0)