-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Update to include fares v2 data manager refs and tests):
- Loading branch information
Showing
21 changed files
with
1,882 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/java/com/conveyal/datatools/manager/jobs/validation/FaresV2ValidationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.conveyal.datatools.manager.jobs.validation; | ||
|
||
import com.conveyal.datatools.DatatoolsTest; | ||
import com.conveyal.datatools.manager.auth.Auth0Connection; | ||
import com.conveyal.datatools.manager.models.FeedSource; | ||
import com.conveyal.datatools.manager.models.FeedVersion; | ||
import com.conveyal.datatools.manager.models.Project; | ||
import com.conveyal.datatools.manager.persistence.Persistence; | ||
import org.bson.Document; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import static com.conveyal.datatools.TestUtils.createFeedVersion; | ||
import static com.conveyal.datatools.TestUtils.zipFolderFiles; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class FaresV2ValidationTest { | ||
|
||
private static Project project; | ||
private static FeedVersion faresV2Version; | ||
|
||
@BeforeAll | ||
public static void setUp() throws IOException { | ||
// Start server if it isn't already running. | ||
DatatoolsTest.setUp(); | ||
Auth0Connection.setAuthDisabled(true); | ||
// Create a project, feed sources, and feed versions to merge. | ||
project = new Project(); | ||
project.name = String.format("Test %s", new Date()); | ||
Persistence.projects.create(project); | ||
|
||
FeedSource faresV2FeedSource = new FeedSource("fares-v2"); | ||
faresV2FeedSource.projectId = project.id; | ||
Persistence.feedSources.create(faresV2FeedSource); | ||
faresV2Version = createFeedVersion( | ||
faresV2FeedSource, | ||
zipFolderFiles("fake-agency-with-fares-v2") | ||
); | ||
Persistence.feedVersions.replace(faresV2Version.id, faresV2Version); | ||
} | ||
|
||
@AfterAll | ||
static void tearDown() { | ||
Auth0Connection.setAuthDisabled(Auth0Connection.getDefaultAuthDisabled()); | ||
project.delete(); | ||
} | ||
|
||
@Test | ||
void canValidateFareV2Files() { | ||
Document summary = (Document) faresV2Version.mobilityDataResult.get("summary"); | ||
List<String> files = summary.getList("files", String.class); | ||
assertTrue(files.contains("areas.txt")); | ||
assertTrue(files.contains("fare_leg_rules.txt")); | ||
assertTrue(files.contains("fare_media.txt")); | ||
assertTrue(files.contains("fare_products.txt")); | ||
assertTrue(files.contains("fare_transfer_rules.txt")); | ||
assertTrue(files.contains("networks.txt")); | ||
assertTrue(files.contains("route_networks.txt")); | ||
assertTrue(files.contains("stop_areas.txt")); | ||
assertTrue(files.contains("timeframes.txt")); | ||
} | ||
|
||
/** | ||
* This is not an exhaustive test, more of a sanity check that MobilityData can detect errors in fares v2 data. | ||
* https://gtfs-validator.mobilitydata.org/rules.html | ||
*/ | ||
@ParameterizedTest | ||
@MethodSource("createValidationErrorChecks") | ||
void canDetectValidationErrors(Set<String> codes, String expectedCode) { | ||
assertTrue(codes.contains(expectedCode)); | ||
} | ||
|
||
private static Stream<Arguments> createValidationErrorChecks() { | ||
ArrayList<Document> notices = (ArrayList<Document>) faresV2Version.mobilityDataResult.get("notices"); | ||
Set<String> codes = new HashSet<>(); | ||
for (Document notice : notices) { | ||
codes.add(notice.getString("code")); | ||
} | ||
return Stream.of( | ||
Arguments.of(codes, "fare_transfer_rule_duration_limit_type_without_duration_limit"), | ||
Arguments.of(codes, "fare_transfer_rule_duration_limit_without_type"), | ||
Arguments.of(codes, "fare_transfer_rule_missing_transfer_count"), | ||
Arguments.of(codes, "fare_transfer_rule_with_forbidden_transfer_count") | ||
); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-fares-v2/agency.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
agency_id,agency_name,agency_url,agency_lang,agency_phone,agency_email,agency_timezone,agency_fare_url,agency_branding_url | ||
1,Fake Transit,http://www.fake-agency.com,,,,America/Los_Angeles,, |
40 changes: 40 additions & 0 deletions
40
src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-fares-v2/areas.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
area_id,area_name | ||
area_bl,Blue Line | ||
area_bl_airport,Blue Line - Airport Station | ||
area_cf_zone_buzzards,CapeFLYER - Wareham/Buzzards Bay/Bourne | ||
area_cf_zone_hyannis,CapeFLYER - Hyannis | ||
area_commuter_rail_porter_zone_1a,Commuter Rail Zone 1A | ||
area_commuter_rail_sumner_tunnel_zone_1a,Commuter Rail Zone 1A | ||
area_commuter_rail_zone_1,Commuter Rail Zone 1 | ||
area_commuter_rail_zone_10,Commuter Rail Zone 10 | ||
area_commuter_rail_zone_1a,Commuter Rail Zone 1A | ||
area_commuter_rail_zone_2,Commuter Rail Zone 2 | ||
area_commuter_rail_zone_3,Commuter Rail Zone 3 | ||
area_commuter_rail_zone_4,Commuter Rail Zone 4 | ||
area_commuter_rail_zone_5,Commuter Rail Zone 5 | ||
area_commuter_rail_zone_6,Commuter Rail Zone 6 | ||
area_commuter_rail_zone_7,Commuter Rail Zone 7 | ||
area_commuter_rail_zone_8,Commuter Rail Zone 8 | ||
area_commuter_rail_zone_9,Commuter Rail Zone 9 | ||
area_fairmount_line_zone_1a,Commuter Rail Zone 1A - Fairmount Line | ||
area_gl_govt_ctr,Green Line - Government Center | ||
area_green_b_west_of_kenmore,Green Line B - West of Kenmore | ||
area_green_c_west_of_kenmore,Green Line C - West of Kenmore | ||
area_green_e_west_of_symphony,Green Line E - West of Symphony | ||
area_m_ashmont_mattapan,Mattapan Trolley - Ashmont and Mattapan | ||
area_ol_state,Orange Line - State | ||
area_red_south_station,Red Line - South Station | ||
area_route_354_downtown,Route 354 - Downtown | ||
area_route_354_outside_downtown,Route 354 - Outside Downtown | ||
area_route_426_downtown,Route 426 - Downtown | ||
area_route_426_outside_downtown,Route 426 - Outside Downtown | ||
area_route_450_downtown,Route 450 - Downtown | ||
area_route_450_outside_downtown,Route 450 - Outside Downtown | ||
area_sl3_north_of_airport,Silver Line - North of Airport Station | ||
area_sl_airport,Silver Line - Airport Station | ||
area_sl_courthouse,Silver Line - Courthouse | ||
area_sl_logan_terminal,Silver Line - Airport Terminals | ||
area_sl_silver_line_way,Silver Line - Silver Line Way | ||
area_sl_south_station,Silver Line - South Station | ||
area_sl_world_trade_center,Silver Line - World Trade Center | ||
area_ss_commuter_rail_zone_1a,Commuter Rail Zone 1A - South Station |
2 changes: 2 additions & 0 deletions
2
src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-fares-v2/calendar.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date | ||
04100312-8fe1-46a5-a9f2-556f39478f57,1,1,1,1,1,1,1,20170915,20170917 |
3 changes: 3 additions & 0 deletions
3
src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-fares-v2/calendar_dates.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
service_id,date,exception_type | ||
04100312-8fe1-46a5-a9f2-556f39478f57,20170916,2 | ||
calendar-date-service,20170917,1 |
Oops, something went wrong.