|
2 | 2 |
|
3 | 3 | import json
|
4 | 4 | import os
|
5 |
| -import socket |
6 | 5 | from collections.abc import Callable
|
7 | 6 | from functools import lru_cache, wraps
|
8 | 7 | from os import environ
|
@@ -51,13 +50,6 @@ def get_docker_tag() -> str:
|
51 | 50 | return f"gh-{branch_name}"
|
52 | 51 |
|
53 | 52 |
|
54 |
| -def get_local_ip() -> str: |
55 |
| - """Get the local machine's IP""" |
56 |
| - hostname = socket.gethostname() |
57 |
| - ip_addr = socket.gethostbyname(hostname) |
58 |
| - return ip_addr |
59 |
| - |
60 |
| - |
61 | 53 | class DockerTestCase(TestCase):
|
62 | 54 | """Mixin for dealing with containers"""
|
63 | 55 |
|
@@ -113,6 +105,9 @@ def run_container(self, **specs: dict[str, Any]) -> Container:
|
113 | 105 | specs["network"] = self.__network.name
|
114 | 106 | specs["labels"] = self.docker_labels
|
115 | 107 | specs["detach"] = True
|
| 108 | + specs["extra_hosts"] = { |
| 109 | + "host.docker.internal": "host-gateway", |
| 110 | + } |
116 | 111 | if hasattr(self, "live_server_url"):
|
117 | 112 | specs.setdefault("environment", {})
|
118 | 113 | specs["environment"]["AUTHENTIK_HOST"] = self.live_server_url
|
@@ -155,7 +150,6 @@ def tearDown(self):
|
155 | 150 | class SeleniumTestCase(DockerTestCase, StaticLiveServerTestCase):
|
156 | 151 | """StaticLiveServerTestCase which automatically creates a Webdriver instance"""
|
157 | 152 |
|
158 |
| - host = get_local_ip() |
159 | 153 | wait_timeout: int
|
160 | 154 | user: User
|
161 | 155 |
|
@@ -210,6 +204,15 @@ def wait_for_url(self, desired_url):
|
210 | 204 | f"URL {self.driver.current_url} doesn't match expected URL {desired_url}",
|
211 | 205 | )
|
212 | 206 |
|
| 207 | + def host_url(self, view, query: dict | None = None, **kwargs) -> str: |
| 208 | + """reverse `view` with `**kwargs` into full URL using live_server_url""" |
| 209 | + url = f"http://host.docker.internal:{self.server_thread.port}" + reverse( |
| 210 | + view, kwargs=kwargs |
| 211 | + ) |
| 212 | + if query: |
| 213 | + return url + "?" + urlencode(query) |
| 214 | + return url |
| 215 | + |
213 | 216 | def url(self, view, query: dict | None = None, **kwargs) -> str:
|
214 | 217 | """reverse `view` with `**kwargs` into full URL using live_server_url"""
|
215 | 218 | url = self.live_server_url + reverse(view, kwargs=kwargs)
|
|
0 commit comments