Skip to content

Commit 65aa6af

Browse files
committed
trying to fix tests and minor renamings
1 parent 8ae4e47 commit 65aa6af

File tree

8 files changed

+98
-117
lines changed

8 files changed

+98
-117
lines changed

tests/test_feeds_global.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

tests/test_feed_landing_pages.py renamed to tests/test_feeds_global_landing_pages.py

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
from django.test import TestCase
1515
from django.urls import reverse
1616

17+
import json
18+
from xml.etree import ElementTree as ET
19+
1720
from works.models import Work, GlobalRegion
1821

1922

23+
NSPS = {"atom": "http://www.w3.org/2005/Atom"}
24+
25+
2026
# Expected work counts per region based on test_data_global_feeds fixture
2127
# These values are hardcoded from the actual fixture data to ensure tests
2228
# verify the exact expected behavior
@@ -41,25 +47,91 @@
4147
}
4248

4349

44-
class FeedLandingPageTests(TestCase):
50+
class GlobalFeedsAndLandingPageTests(TestCase):
4551
fixtures = ["test_data_global_feeds"]
4652

4753
@classmethod
4854
def setUpTestData(cls):
55+
call_command("flush", "--no-input")
4956
call_command("load_global_regions")
5057
call_command("loaddata", "test_data_global_feeds")
5158

52-
def _slugify(self, name):
59+
def slugify(self, name):
5360
"""Convert region name to slug."""
5461
return name.lower().replace(" ", "-")
5562

63+
def test_global_region_load(self):
64+
regions = GlobalRegion.objects.all()
65+
self.assertEqual(len(regions), 15)
66+
67+
def test_georss_feed_per_region(self):
68+
for region in GlobalRegion.objects.all():
69+
slug = self.slugify(region.name)
70+
# Use new API v1 endpoint based on region type
71+
if region.region_type == 'continent':
72+
url = reverse("optimap:api-continent-georss", kwargs={"continent_slug": slug})
73+
else: # ocean
74+
url = reverse("optimap:api-ocean-georss", kwargs={"ocean_slug": slug})
75+
76+
resp = self.client.get(url)
77+
self.assertEqual(resp.status_code, 200,
78+
f"{region.name} GeoRSS feed failed")
79+
80+
root = ET.fromstring(resp.content)
81+
titles = [item.find("title").text
82+
for item in root.findall(".//item")]
83+
84+
expected_titles = list(
85+
Work.objects
86+
.filter(
87+
status="p",
88+
geometry__isnull=False,
89+
geometry__intersects=region.geom
90+
)
91+
.order_by("-creationDate")
92+
.values_list("title", flat=True)
93+
)
94+
95+
self.assertCountEqual(
96+
titles, expected_titles,
97+
f"GeoRSS feed for {region.name} returned {titles!r}, expected {expected_titles!r}"
98+
)
99+
100+
def test_geoatom_feed_australia(self):
101+
# Use new API v1 Atom endpoint
102+
url = reverse("optimap:api-continent-atom", kwargs={"continent_slug": "australia"})
103+
response = self.client.get(url)
104+
self.assertEqual(response.status_code, 200)
105+
106+
root = ET.fromstring(response.content)
107+
titles = [entry.find("atom:title", namespaces=NSPS).text
108+
for entry in root.findall(".//atom:entry", namespaces=NSPS)]
109+
110+
self.assertEqual(len(titles), 6, "Atom feed for Australia should return 6 entries")
111+
self.assertEqual(titles[0], "Migration Route: Asia to Australia", "Atom feed for Australia returned unexpected title")
112+
113+
def test_georss_feed_south_atlantic(self):
114+
# Use new API v1 GeoRSS endpoint
115+
url = reverse("optimap:api-ocean-georss", kwargs={"ocean_slug": "south-atlantic-ocean"})
116+
response = self.client.get(url)
117+
self.assertEqual(response.status_code, 200)
118+
119+
root = ET.fromstring(response.content)
120+
titles = [item.find("title").text
121+
for item in root.findall(".//item", namespaces=NSPS)]
122+
123+
self.assertEqual(len(titles), 10, "GeoRSS feed for South Atlantic Ocean should return 10 entries")
124+
self.assertEqual(titles[0], "Marine Biology and Oceanography of the Southern Ocean", "GeoRSS feed for South Atlantic Ocean returned unexpected first title")
125+
self.assertEqual(titles[9], "Global Climate Network", "GeoRSS feed for South Atlantic Ocean returned unexpected last title")
126+
127+
56128
def test_all_continent_pages_display_correct_work_counts(self):
57129
"""Test that all continent feed pages display the correct number of works."""
58130
continents = GlobalRegion.objects.filter(region_type=GlobalRegion.CONTINENT)
59131

60132
for region in continents:
61133
with self.subTest(continent=region.name):
62-
slug = self._slugify(region.name)
134+
slug = self.slugify(region.name)
63135
expected_count = EXPECTED_COUNTS.get(slug, 0)
64136

65137
url = reverse('optimap:feed-continent-page', kwargs={'continent_slug': slug})
@@ -81,19 +153,19 @@ def test_all_continent_pages_display_correct_work_counts(self):
81153

82154
# Verify the count is shown in the HTML
83155
if expected_count > 0:
84-
self.assertContains(response, f'Showing {expected_count} publication',
156+
self.assertContains(response, f'{expected_count} research works',
85157
msg_prefix=f"Work count not displayed for {region.name}")
86158

87159
# Verify at least the first work title appears
88160
self.assertContains(response, actual_works[0].title,
89161
msg_prefix=f"First work title not found for {region.name}")
90162

91163
# Should NOT show empty message
92-
self.assertNotContains(response, 'No publications found',
164+
self.assertNotContains(response, 'No works found',
93165
msg_prefix=f"{region.name} should not show empty message")
94166
else:
95167
# Should show empty message
96-
self.assertContains(response, 'No publications found',
168+
self.assertContains(response, 'No works found',
97169
msg_prefix=f"{region.name} should show empty message")
98170

99171
def test_all_ocean_pages_display_correct_work_counts(self):
@@ -102,7 +174,7 @@ def test_all_ocean_pages_display_correct_work_counts(self):
102174

103175
for region in oceans:
104176
with self.subTest(ocean=region.name):
105-
slug = self._slugify(region.name)
177+
slug = self.slugify(region.name)
106178
expected_count = EXPECTED_COUNTS.get(slug, 0)
107179

108180
url = reverse('optimap:feed-ocean-page', kwargs={'ocean_slug': slug})
@@ -124,25 +196,25 @@ def test_all_ocean_pages_display_correct_work_counts(self):
124196

125197
# Verify the count is shown in the HTML
126198
if expected_count > 0:
127-
self.assertContains(response, f'Showing {expected_count} publication',
199+
self.assertContains(response, f'{expected_count} research works',
128200
msg_prefix=f"Work count not displayed for {region.name}")
129201

130202
# Verify at least the first work title appears
131203
self.assertContains(response, actual_works[0].title,
132204
msg_prefix=f"First work title not found for {region.name}")
133205

134206
# Should NOT show empty message
135-
self.assertNotContains(response, 'No publications found',
207+
self.assertNotContains(response, 'No works found',
136208
msg_prefix=f"{region.name} should not show empty message")
137209
else:
138210
# Should show empty message
139-
self.assertContains(response, 'No publications found',
211+
self.assertContains(response, 'No works found',
140212
msg_prefix=f"{region.name} should show empty message")
141213

142214
def test_continent_page_shows_region_metadata(self):
143215
"""Test that continent pages show correct region metadata."""
144216
region = GlobalRegion.objects.filter(region_type=GlobalRegion.CONTINENT).first()
145-
slug = self._slugify(region.name)
217+
slug = self.slugify(region.name)
146218
url = reverse('optimap:feed-continent-page', kwargs={'continent_slug': slug})
147219
response = self.client.get(url)
148220

@@ -162,7 +234,7 @@ def test_continent_page_shows_region_metadata(self):
162234
def test_ocean_page_shows_region_metadata(self):
163235
"""Test that ocean pages show correct region metadata."""
164236
region = GlobalRegion.objects.filter(region_type=GlobalRegion.OCEAN).first()
165-
slug = self._slugify(region.name)
237+
slug = self.slugify(region.name)
166238
url = reverse('optimap:feed-ocean-page', kwargs={'ocean_slug': slug})
167239
response = self.client.get(url)
168240

@@ -182,7 +254,7 @@ def test_ocean_page_shows_region_metadata(self):
182254
def test_feed_page_cache_refresh(self):
183255
"""Test that ?now parameter forces cache refresh."""
184256
region = GlobalRegion.objects.filter(region_type=GlobalRegion.CONTINENT).first()
185-
slug = self._slugify(region.name)
257+
slug = self.slugify(region.name)
186258
url = reverse('optimap:feed-continent-page', kwargs={'continent_slug': slug})
187259

188260
# First request (no cache)

tests/test_regular_harvesting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_harvest_regular_metadata_sends_email(self, mock_parser, mock_get):
4141
fake_response.content = b"<OAI-PMH><ListRecords></ListRecords></OAI-PMH>"
4242
mock_get.return_value = fake_response
4343

44-
def fake_parser_func(content, event, max_records=None):
44+
def fake_parser_func(content, event, max_records=None, warning_collector=None):
4545
Work.objects.create(
4646
title="Test Publication 1",
4747
doi="10.1000/1",

works/management/commands/load_global_regions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Command(BaseCommand):
2828
help = "Load 7 continents (Esri Hub) and 5 oceans (MarineRegions IHO) into GlobalRegion"
2929

3030
def handle(self, *args, **options):
31+
self.stdout.write(f"Looading global regions…")
32+
3133
continents_path = os.path.join(COMMAND_DIR, CONTINENTS_FILE)
3234

3335
if os.path.exists(continents_path):

works/static/js/map-search.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class MapSearchManager {
202202
if (this.isSearchActive) {
203203
console.log('Clearing active search...');
204204
this.showAllPublications();
205-
this.announce('Search cleared. Showing all publications.');
205+
this.announce('Search cleared. Showing all works.');
206206
}
207207
console.groupEnd();
208208
return;
@@ -439,7 +439,7 @@ class MapSearchManager {
439439
showAllPublications() {
440440
if (!this.map) return;
441441

442-
console.log('🗺️ Showing all publications...');
442+
console.log('🗺️ Showing all works...');
443443

444444
// Remove filtered layer if it exists
445445
if (this.filteredLayer) {
@@ -466,7 +466,7 @@ class MapSearchManager {
466466
const bounds = this.publicationsGroup.getBounds();
467467
if (bounds.isValid()) {
468468
this.map.fitBounds(bounds);
469-
console.log('🗺️ Map fitted to all publications');
469+
console.log('🗺️ Map fitted to all works');
470470
}
471471
}
472472

@@ -487,7 +487,7 @@ class MapSearchManager {
487487
}
488488

489489
this.showAllPublications();
490-
this.announce('Search cleared. Showing all publications.');
490+
this.announce('Search cleared. Showing all works.');
491491
}
492492

493493
/**
@@ -517,7 +517,7 @@ class MapSearchManager {
517517
*/
518518
updatePublications(publications) {
519519
this.allPublications = publications || [];
520-
console.log(`Map search updated with ${this.allPublications.length} publications`);
520+
console.log(`Map search updated with ${this.allPublications.length} works`);
521521

522522
// If search is active, re-run search
523523
if (this.isSearchActive && this.searchInput && this.searchInput.value.trim().length >= this.minSearchLength) {

works/templates/works.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h1>All Works</h1>
88

99
{% if is_admin %}
1010
<p class="alert alert-info">
11-
<strong>Admin view:</strong> You can see all publications regardless of status. Status labels are shown next to each entry.
11+
<strong>Admin view:</strong> You can see all works regardless of status. Status labels are shown next to each entry.
1212
</p>
1313
{% endif %}
1414

@@ -137,7 +137,7 @@ <h5 class="work-title mb-2">
137137
</div>
138138
</div>
139139
{% empty %}
140-
<p class="alert alert-warning">No publications found.</p>
140+
<p class="alert alert-warning">No works found.</p>
141141
{% endfor %}
142142
</div>
143143

works/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def main(request):
132132

133133
def contribute(request):
134134
"""
135-
Page showing harvested publications that need spatial or temporal extent contributions.
136-
Displays publications with Harvested status that are missing geometry or temporal extent.
135+
Page showing harvested works that need spatial or temporal extent contributions.
136+
Displays works with harvested status that are missing geometry or temporal extent.
137137
"""
138138
from django.contrib.gis.geos import GeometryCollection
139139
from django.db.models import Q

works/views/work_views.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626

2727
def contribute(request):
2828
"""
29-
Page showing harvested publications that need spatial or temporal extent contributions.
30-
Displays publications with Harvested status that are missing geometry or temporal extent.
31-
29+
Page showing harvested works that need spatial or temporal extent contributions.
3230
Supports pagination with user-selectable page size.
3331
"""
3432
from django.contrib.gis.geos import GeometryCollection

0 commit comments

Comments
 (0)