Skip to content

Commit 951f8d0

Browse files
committed
try to fix UI tests
1 parent 31b44f6 commit 951f8d0

15 files changed

+313
-54
lines changed

tests-ui/test_accountdeletion.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
User = get_user_model()
1414

15-
class AccountDeletionUITest(unittest.TestCase):
15+
class AccountDeletionUITest(unittest.StaticLiveServerTestCase):
1616
def setUp(self):
1717
"""Set up the test user and start browser"""
1818
self.email = "[email protected]"
@@ -36,10 +36,10 @@ def test_delete_account(self):
3636
write(self.email, into='email')
3737
click(S('button[type="submit"]'))
3838

39-
go_to(f"http://localhost:8000/login/{self.token}")
39+
go_to(ff"{self.live_server_url}/login/{self.token}")
4040
sleep(3)
4141

42-
go_to("http://localhost:8000/usersettings/")
42+
go_to(f"{self.live_server_url}/usersettings/")
4343
sleep(2)
4444

4545
click("Delete account")
@@ -48,7 +48,7 @@ def test_delete_account(self):
4848
click("Delete")
4949
sleep(3)
5050

51-
go_to(f"http://localhost:8000/confirm-delete/{self.delete_token}")
51+
go_to(ff"{self.live_server_url}/confirm-delete/{self.delete_token}")
5252
sleep(3)
5353

5454
click("Permanently Delete Account")

tests-ui/test_admin_block_user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
User = get_user_model()
1616

17-
class AdminBlockUserTests(TestCase):
17+
class AdminBlockUserTests(StaticLiveServerTestCase):
1818
def setUp(self):
1919
"""Set up a superuser, test user, and start the browser before each test."""
2020
self.superuser, _ = User.objects.get_or_create(
@@ -35,7 +35,7 @@ def setUp(self):
3535

3636
#self.kill_existing_firefox_processes()
3737
try:
38-
self.browser = start_chrome("http://localhost:8000/admin/", headless=True)
38+
self.browser = start_chrome(f"{self.live_server_url}/admin/", headless=True)
3939
except Exception as e:
4040
print(f"Error starting browser: {e}")
4141
self.browser = None
@@ -65,7 +65,7 @@ def block_user_by_action(self, action_name):
6565
write("admin123", into="Password")
6666
click("Log in")
6767

68-
go_to("http://localhost:8000/admin/auth/user/")
68+
go_to(f"{self.live_server_url}/admin/auth/user/")
6969

7070
if not User.objects.filter(email="[email protected]").exists():
7171
self.test_user = User.objects.create_user(

tests-ui/test_admin_content.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from django.test import TestCase
10+
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
1011
from django.contrib.auth import get_user_model
1112
from helium import (
1213
start_chrome,
@@ -22,13 +23,16 @@
2223
User = get_user_model()
2324

2425

25-
def get_work_from_api():
26+
def get_work_from_api(base_url):
2627
"""
2728
Helper function to get a work (id, doi) from the API instead of database.
2829
Returns the first published work found, preferring works with DOI.
2930
Returns identifier field that can be used in URLs (either DOI or ID).
31+
32+
Args:
33+
base_url: The base URL of the test server (e.g., self.live_server_url)
3034
"""
31-
response = requests.get('http://localhost:8000/api/v1/works/', timeout=5)
35+
response = requests.get(f'{base_url}/api/v1/works/', timeout=5)
3236
if response.status_code == 200:
3337
data = response.json()
3438
if data.get('results') and len(data['results']) > 0:
@@ -141,11 +145,20 @@ def test_admin_panel_accessible_to_staff(self):
141145
self.assertContains(response, 'Site administration')
142146

143147

144-
class AdminButtonsBrowserTests(TestCase):
145-
"""Browser-based tests for admin button visibility."""
148+
class AdminButtonsBrowserTests(StaticLiveServerTestCase):
149+
"""Browser-based tests for admin button visibility.
150+
151+
Uses StaticLiveServerTestCase to automatically start a live test server
152+
that serves both the application and static files.
153+
"""
146154

147155
fixtures = ['test_data_optimap.json']
148156

157+
@classmethod
158+
def setUpClass(cls):
159+
"""Set up class-level resources including live server."""
160+
super().setUpClass()
161+
149162
def setUp(self):
150163
"""Set up test users for each test."""
151164
# Create admin user
@@ -159,13 +172,13 @@ def test_work_landing_page_anonymous_no_admin_buttons(self):
159172
"""Test that work landing page doesn't show admin buttons to anonymous users."""
160173

161174
# Get work from API instead of database
162-
work_data = get_work_from_api()
175+
work_data = get_work_from_api(self.live_server_url)
163176
if not work_data or not work_data.get('identifier'):
164177
self.skipTest('No works available via API')
165178

166179
try:
167180
# Use the unified identifier (DOI or ID)
168-
start_chrome(f'localhost:8000/work/{work_data["identifier"]}/', headless=True)
181+
start_chrome(f'{self.live_server_url}/work/{work_data["identifier"]}/', headless=True)
169182
driver = get_driver()
170183

171184
# Wait for page to load
@@ -181,7 +194,7 @@ def test_work_landing_page_anonymous_no_admin_buttons(self):
181194
def test_contribute_page_anonymous_no_publish_buttons(self):
182195
"""Test that contribute page doesn't show publish buttons to anonymous users."""
183196
try:
184-
start_chrome('localhost:8000/contribute/', headless=True)
197+
start_chrome(f'{self.live_server_url}/contribute/', headless=True)
185198
driver = get_driver()
186199

187200
# Wait for page to load

tests-ui/test_contribution_workflow.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
from django.test import TestCase
16+
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
1617
from django.contrib.auth import get_user_model
1718
from helium import (
1819
start_chrome,
@@ -34,7 +35,7 @@
3435
User = get_user_model()
3536

3637

37-
class ContributionWorkflowE2ETest(TestCase):
38+
class ContributionWorkflowE2ETest(StaticLiveServerTestCase):
3839
"""End-to-end test for complete contribution and publication workflow."""
3940

4041
@classmethod
@@ -82,12 +83,12 @@ def test_complete_contribution_workflow(self):
8283
"""
8384
try:
8485
# Start browser
85-
start_chrome('localhost:8000/', headless=True)
86+
start_chrome(f'{self.live_server_url}/', headless=True)
8687
driver = get_driver()
8788

8889
# Step 1: Login as admin
8990
# Navigate to home page and open menu
90-
go_to('localhost:8000/')
91+
go_to(f'{self.live_server_url}/')
9192
time.sleep(1)
9293

9394
# Find and click the menu dropdown
@@ -108,7 +109,7 @@ def test_complete_contribution_workflow(self):
108109

109110
# Start browser again with authenticated session
110111
# Set up session cookie
111-
start_chrome('localhost:8000/', headless=True)
112+
start_chrome(f'{self.live_server_url}/', headless=True)
112113
driver = get_driver()
113114

114115
# Add session cookie to browser
@@ -122,7 +123,7 @@ def test_complete_contribution_workflow(self):
122123
})
123124

124125
# Step 2: Navigate to contribute page
125-
go_to('localhost:8000/contribute/')
126+
go_to(f'{self.live_server_url}/contribute/')
126127
time.sleep(2)
127128

128129
# Verify we're on the contribute page
@@ -177,7 +178,7 @@ def test_complete_contribution_workflow(self):
177178
self.test_work.save()
178179

179180
# Step 6: Navigate to work landing page
180-
work_url = f'localhost:8000/work/{self.test_work.id}/'
181+
work_url = ff'{self.live_server_url}/work/{self.test_work.id}/'
181182
go_to(work_url)
182183
time.sleep(2)
183184

@@ -209,7 +210,7 @@ def test_complete_contribution_workflow(self):
209210
self.skipTest('Publish button not found - may need to adjust test')
210211

211212
# Step 8: Verify work appears on main map
212-
go_to('localhost:8000/')
213+
go_to(f'{self.live_server_url}/')
213214
time.sleep(2)
214215

215216
# Check if map has loaded

tests-ui/test_emailchange.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
User = get_user_model()
1414

15-
class EmailChangeUITest(unittest.TestCase):
15+
class EmailChangeUITest(unittest.StaticLiveServerTestCase):
1616
def setUp(self):
1717
"""Set up the test user and start browser"""
1818
self.old_email = "[email protected]"
@@ -44,10 +44,10 @@ def test_email_change_process(self):
4444

4545
sleep(1)
4646

47-
go_to(f"http://localhost:8000/login/{self.token}")
47+
go_to(ff"{self.live_server_url}/login/{self.token}")
4848
sleep(3)
4949

50-
go_to("http://localhost:8000/usersettings/")
50+
go_to(f"{self.live_server_url}/usersettings/")
5151
sleep(2)
5252

5353
click("Change Email")
@@ -61,7 +61,7 @@ def test_email_change_process(self):
6161

6262
if stored_data and "token" in stored_data:
6363
correct_token = stored_data["token"]
64-
confirmation_url = f"http://localhost:8000/confirm-email/{correct_token}/{self.new_email}"
64+
confirmation_url = ff"{self.live_server_url}/confirm-email/{correct_token}/{self.new_email}"
6565
go_to(confirmation_url)
6666
sleep(5)
6767
else:

0 commit comments

Comments
 (0)