sendmock-testcontainers 0.1.0b1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sendmock_testcontainers-0.1.0b1/PKG-INFO +11 -0
- sendmock_testcontainers-0.1.0b1/pyproject.toml +25 -0
- sendmock_testcontainers-0.1.0b1/sendmock_testcontainers/__init__.py +37 -0
- sendmock_testcontainers-0.1.0b1/sendmock_testcontainers.egg-info/PKG-INFO +11 -0
- sendmock_testcontainers-0.1.0b1/sendmock_testcontainers.egg-info/SOURCES.txt +8 -0
- sendmock_testcontainers-0.1.0b1/sendmock_testcontainers.egg-info/dependency_links.txt +1 -0
- sendmock_testcontainers-0.1.0b1/sendmock_testcontainers.egg-info/requires.txt +4 -0
- sendmock_testcontainers-0.1.0b1/sendmock_testcontainers.egg-info/top_level.txt +1 -0
- sendmock_testcontainers-0.1.0b1/setup.cfg +4 -0
- sendmock_testcontainers-0.1.0b1/tests/test_sendmock_container.py +32 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sendmock-testcontainers
|
|
3
|
+
Version: 0.1.0b1
|
|
4
|
+
Summary: Starts SendMock in Docker from a test and gives its SMTP, HTTP and provider addresses.
|
|
5
|
+
License-Expression: MIT OR Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://shibbirweb.github.io/sendmock/
|
|
7
|
+
Project-URL: Source, https://github.com/shibbirweb/sendmock/tree/develop/testcontainers/python
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: testcontainers==4.15.0
|
|
10
|
+
Provides-Extra: test
|
|
11
|
+
Requires-Dist: pytest==8.4.2; extra == "test"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sendmock-testcontainers"
|
|
3
|
+
version = "0.1.0-beta.1"
|
|
4
|
+
description = "Starts SendMock in Docker from a test and gives its SMTP, HTTP and provider addresses."
|
|
5
|
+
license = "MIT OR Apache-2.0"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"testcontainers==4.15.0",
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
[project.urls]
|
|
12
|
+
Homepage = "https://shibbirweb.github.io/sendmock/"
|
|
13
|
+
Source = "https://github.com/shibbirweb/sendmock/tree/develop/testcontainers/python"
|
|
14
|
+
|
|
15
|
+
[project.optional-dependencies]
|
|
16
|
+
test = [
|
|
17
|
+
"pytest==8.4.2",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["setuptools>=77"]
|
|
22
|
+
build-backend = "setuptools.build_meta"
|
|
23
|
+
|
|
24
|
+
[tool.setuptools]
|
|
25
|
+
packages = ["sendmock_testcontainers"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""SendMock in Docker for a test: SMTP, the HTTP API and UI, and the provider port that
|
|
2
|
+
answers provider SDKs at their real paths."""
|
|
3
|
+
|
|
4
|
+
from testcontainers.core.container import DockerContainer
|
|
5
|
+
from testcontainers.core.wait_strategies import HttpWaitStrategy
|
|
6
|
+
|
|
7
|
+
DEFAULT_IMAGE = "ghcr.io/shibbirweb/sendmock:0.1.0-beta.1"
|
|
8
|
+
SMTP_PORT = 1025
|
|
9
|
+
HTTP_PORT = 8025
|
|
10
|
+
PROVIDER_PORT = 8026
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SendMockContainer(DockerContainer):
|
|
14
|
+
def __init__(self, image: str = DEFAULT_IMAGE, **container_options) -> None:
|
|
15
|
+
super().__init__(image, **container_options)
|
|
16
|
+
self.with_exposed_ports(SMTP_PORT, HTTP_PORT, PROVIDER_PORT)
|
|
17
|
+
self.with_env("SENDMOCK_PROVIDER_ADDR", f"0.0.0.0:{PROVIDER_PORT}")
|
|
18
|
+
self.waiting_for(HttpWaitStrategy(HTTP_PORT, "/api/v1/health"))
|
|
19
|
+
|
|
20
|
+
def get_smtp_host(self) -> str:
|
|
21
|
+
"""The host the SMTP port is reached on."""
|
|
22
|
+
return self.get_container_host_ip()
|
|
23
|
+
|
|
24
|
+
def get_smtp_port(self) -> int:
|
|
25
|
+
"""The SMTP port on the host, for the app's mail settings."""
|
|
26
|
+
return int(self.get_exposed_port(SMTP_PORT))
|
|
27
|
+
|
|
28
|
+
def get_http_url(self) -> str:
|
|
29
|
+
"""The HTTP API and UI, e.g. `http://localhost:32768`."""
|
|
30
|
+
return f"http://{self.get_container_host_ip()}:{self.get_exposed_port(HTTP_PORT)}"
|
|
31
|
+
|
|
32
|
+
def get_provider_url(self) -> str:
|
|
33
|
+
"""The provider port, the base URL to give a provider SDK instead of the provider's own."""
|
|
34
|
+
return f"http://{self.get_container_host_ip()}:{self.get_exposed_port(PROVIDER_PORT)}"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
__all__ = ["DEFAULT_IMAGE", "SendMockContainer"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sendmock-testcontainers
|
|
3
|
+
Version: 0.1.0b1
|
|
4
|
+
Summary: Starts SendMock in Docker from a test and gives its SMTP, HTTP and provider addresses.
|
|
5
|
+
License-Expression: MIT OR Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://shibbirweb.github.io/sendmock/
|
|
7
|
+
Project-URL: Source, https://github.com/shibbirweb/sendmock/tree/develop/testcontainers/python
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: testcontainers==4.15.0
|
|
10
|
+
Provides-Extra: test
|
|
11
|
+
Requires-Dist: pytest==8.4.2; extra == "test"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
sendmock_testcontainers/__init__.py
|
|
3
|
+
sendmock_testcontainers.egg-info/PKG-INFO
|
|
4
|
+
sendmock_testcontainers.egg-info/SOURCES.txt
|
|
5
|
+
sendmock_testcontainers.egg-info/dependency_links.txt
|
|
6
|
+
sendmock_testcontainers.egg-info/requires.txt
|
|
7
|
+
sendmock_testcontainers.egg-info/top_level.txt
|
|
8
|
+
tests/test_sendmock_container.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sendmock_testcontainers
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import socket
|
|
3
|
+
import urllib.parse
|
|
4
|
+
import urllib.request
|
|
5
|
+
|
|
6
|
+
from sendmock_testcontainers import DEFAULT_IMAGE, SendMockContainer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def read_smtp_greeting(smtp_host, smtp_port):
|
|
10
|
+
with socket.create_connection((smtp_host, smtp_port), timeout=10) as smtp_socket:
|
|
11
|
+
return smtp_socket.recv(512).decode("ascii")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# DS-06.1
|
|
15
|
+
def test_starts_the_image_and_gives_the_smtp_http_and_provider_addresses():
|
|
16
|
+
with SendMockContainer(os.environ.get("SENDMOCK_IMAGE", DEFAULT_IMAGE)) as sendmock:
|
|
17
|
+
with urllib.request.urlopen(f"{sendmock.get_http_url()}/api/v1/health") as health_response:
|
|
18
|
+
health_status = health_response.status
|
|
19
|
+
twilio_form = urllib.parse.urlencode(
|
|
20
|
+
{"From": "+15005550006", "To": "+14155550104", "Body": "From Python"}
|
|
21
|
+
).encode()
|
|
22
|
+
twilio_request = urllib.request.Request(
|
|
23
|
+
f"{sendmock.get_provider_url()}/2010-04-01/Accounts/AC00000000000000000000000000000005/Messages.json",
|
|
24
|
+
data=twilio_form,
|
|
25
|
+
)
|
|
26
|
+
with urllib.request.urlopen(twilio_request) as twilio_response:
|
|
27
|
+
twilio_status = twilio_response.status
|
|
28
|
+
smtp_greeting = read_smtp_greeting(sendmock.get_smtp_host(), sendmock.get_smtp_port())
|
|
29
|
+
|
|
30
|
+
assert health_status == 200
|
|
31
|
+
assert twilio_status == 201
|
|
32
|
+
assert smtp_greeting.startswith("220 ")
|