Skip to content

Commit aa93def

Browse files
philimon-resetvsangereanMOZ
authored andcommitted
region divide added
1 parent 5be8bdd commit aa93def

File tree

10 files changed

+35
-17
lines changed

10 files changed

+35
-17
lines changed

l10n_CM/Unified/conftest.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ def is_port_in_use() -> bool:
2525
return s.connect_ex((LOCALHOST, PORT)) == 0
2626

2727

28-
def get_html_files(live_site):
29-
address_path_to_site = parent_dir + f"/sites/{live_site}/{live_site}_ad.html"
30-
cc_path_to_site = parent_dir + f"/sites/{live_site}/{live_site}_cc.html"
28+
def get_html_files(live_site, region):
29+
address_path_to_site = (
30+
parent_dir + f"/sites/{live_site}/{region}/{live_site}_ad.html"
31+
)
32+
cc_path_to_site = parent_dir + f"/sites/{live_site}/{region}/{live_site}_cc.html"
3133
if os.path.exists(address_path_to_site) and os.path.exists(cc_path_to_site):
3234
address_html_file, cc_html_file = "", ""
3335
with open(address_path_to_site, "r", encoding="utf-8") as fp:
3436
address_html_file = fp.read()
3537
with open(cc_path_to_site, "r", encoding="utf-8") as fp:
3638
cc_html_file = fp.read()
3739
return address_html_file, cc_html_file
38-
return ""
40+
return "", ""
3941

4042

4143
@pytest.fixture()
@@ -45,7 +47,7 @@ def region():
4547

4648
@pytest.fixture()
4749
def live_site():
48-
return os.environ.get("CM_SITE", "demo")
50+
return os.environ.get("CM_SITE", "amazon")
4951

5052

5153
@pytest.fixture()
@@ -68,7 +70,11 @@ def prefs_list(add_to_prefs_list: List[tuple[str, str | bool]], region: str):
6870

6971
@pytest.fixture()
7072
def ad_site_data(live_site, region):
71-
ad_live_site = f"{live_site}/{live_site}_ad"
73+
ad_live_site = (
74+
f"{live_site}/{region}/{live_site}_ad"
75+
if live_site != "demo"
76+
else f"{live_site}/{live_site}_ad"
77+
)
7278
path_to_site = parent_dir + "/constants/"
7379
with open(path_to_site + ad_live_site + ".json", "r") as fp:
7480
live_site_data = load(fp)
@@ -84,8 +90,12 @@ def ad_site_data(live_site, region):
8490

8591

8692
@pytest.fixture()
87-
def cc_site_data(live_site):
88-
cc_live_site = f"{live_site}/{live_site}_cc"
93+
def cc_site_data(live_site, region):
94+
cc_live_site = (
95+
f"{live_site}/{region}/{live_site}_cc"
96+
if live_site != "demo"
97+
else f"{live_site}/{live_site}_cc"
98+
)
8999
path_to_site = parent_dir + "/constants/"
90100
with open(path_to_site + cc_live_site + ".json", "r") as fp:
91101
live_site_data = load(fp)
@@ -105,14 +115,14 @@ def httpserver_listen_address():
105115

106116

107117
@pytest.fixture()
108-
def serve_live_site(is_live_site, live_site, request):
118+
def serve_live_site(is_live_site, live_site, region, request):
109119
"""Serve the live site only if needed."""
110120
if not is_live_site or is_port_in_use():
111121
return
112122
# only serve content if url is already not served.
113123
try:
124+
ad_html_file, cc_html_file = get_html_files(live_site, region)
114125
http_server = request.getfixturevalue("httpserver")
115-
ad_html_file, cc_html_file = get_html_files(live_site)
116126
http_server.expect_request(f"/{live_site}_ad.html").respond_with_data(
117127
ad_html_file, content_type="text/html"
118128
)

l10n_CM/run_l10n.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@
2424

2525
class MyHttpRequestHandler(SimpleHTTPRequestHandler):
2626
live_site = None
27+
region = None
2728

2829
def translate_path(self, path):
2930
"""switch the default directory where the html files are served from."""
30-
base_dir = os.path.join(current_dir, "sites", self.live_site)
31+
base_dir = os.path.join(current_dir, "sites", self.live_site, self.region)
3132
return os.path.join(base_dir, path.lstrip("/"))
3233

3334
def log_message(self, format, *args):
3435
"""Remove logs from the server."""
3536
pass
3637

3738

38-
def start_server(live_site):
39+
def start_server(live_site, current_region):
3940
# set live site attribute
4041
MyHttpRequestHandler.live_site = live_site
42+
MyHttpRequestHandler.region = current_region
4143
# start web server on a separate thread to avoid blocking calls.
4244
http = HTTPServer((LOCALHOST, PORT), MyHttpRequestHandler)
4345

@@ -47,9 +49,15 @@ def start_server(live_site):
4749

4850

4951
@contextmanager
50-
def running_server(live_site):
52+
def running_server(live_site, test_region):
5153
"""Context manager to run a server and clean it up automatically."""
52-
httpd, server_thread = start_server(live_site)
54+
html_path = os.path.join(current_dir, "sites", live_site, test_region)
55+
if not os.path.exists(html_path):
56+
raise FileNotFoundError(
57+
f"Expected HTML directory not found at path: {html_path}"
58+
)
59+
60+
httpd, server_thread = start_server(live_site, test_region)
5361
try:
5462
yield # control goes to the caller, server runs in the background
5563
finally:
@@ -166,8 +174,8 @@ def run_unified(regions, unified_flags):
166174
for unified_region in regions:
167175
run_tests(unified_region, live_site, unified_flags, unified_tests)
168176
else:
169-
with running_server(live_site):
170-
for unified_region in regions:
177+
for unified_region in regions:
178+
with running_server(live_site, unified_region):
171179
run_tests(unified_region, live_site, unified_flags, unified_tests)
172180

173181

@@ -195,5 +203,5 @@ def run_unified(regions, unified_flags):
195203
if site == "demo":
196204
run_tests(region, site, flags, tests)
197205
else:
198-
with running_server(site):
206+
with running_server(site, region):
199207
run_tests(region, site, flags, tests)

0 commit comments

Comments
 (0)