Skip to content

Commit

Permalink
fix and test: create all notes for trips with more than one note
Browse files Browse the repository at this point in the history
  • Loading branch information
jclgoodwin committed May 7, 2024
1 parent 5146d38 commit cea9438
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bustimes/management/commands/import_transxchange.py
Expand Up @@ -748,7 +748,11 @@ def handle_journeys(
if cell.notes:
for note_code, note_text in cell.notes:
note = self.get_note(note_code, note_text)
if not trip_notes or trip_notes[-1].trip is not trip:
if not (
trip_notes
and trip_notes[-1].trip is trip
and trip_notes[-1].note is note
):
trip_notes.append(Trip.notes.through(trip=trip, note=note))
stop_time_notes.append(
StopTime.notes.through(stoptime=stop_time, note=note)
Expand All @@ -773,8 +777,7 @@ def handle_journeys(

for note_code, note_text in journey.notes.items():
note = self.get_note(note_code, note_text)
if not trip_notes or trip_notes[-1].trip is not trip:
trip_notes.append(Trip.notes.through(trip=trip, note=note))
trip_notes.append(Trip.notes.through(trip=trip, note=note))

if journey.frequency_interval:
if len(journeys) > i + 1:
Expand Down
12 changes: 12 additions & 0 deletions bustimes/management/tests/test_import_transxchange.py
Expand Up @@ -29,6 +29,7 @@
Calendar,
CalendarDate,
Garage,
Note,
Route,
RouteLink,
Trip,
Expand Down Expand Up @@ -1004,6 +1005,17 @@ def test_services_nw(self):
# self.assertNotContains(res, 'Timetable changes from <a href="?date=2017-09-03">Sunday 3 September 2017</a>')
self.assertEqual(18, len(res.context_data["timetable"].groupings[0].trips))

# notes
self.assertContains(
res,
"<td>Night Service, runs Saturday night/Sunday morning ONLY;special fares may</td>",
html=True,
)
self.assertContains(
res, "<p>Low floor bus - access for pushchairs and wheelchairs</p>"
)
self.assertEqual(Note.objects.filter(trip__start="02:30:00").count(), 4)

self.assertContains(
res,
"Piccadilly Gardens, Manchester City Centre or Ashton Under Lyne - Glossop",
Expand Down

0 comments on commit cea9438

Please sign in to comment.