Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wsgi_json: take relations.json from sql #4405

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/wsgi_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ pub fn our_application_json(
== format!("{prefix}/lints/whole-country/invalid-addr-cities/update-result.json")
{
output = webframe::handle_invalid_addr_cities_update_json(ctx)?;
} else if request_uri == format!("{prefix}/api/relations.json") {
let conn = ctx.get_database_connection()?;
let mut stmt = conn.prepare("select json from stats_jsons where category = 'relations'")?;
let mut rows = stmt.query([])?;
output = match rows.next()? {
Some(row) => row.get(0)?,
None => String::from("[]"),
};
} else {
// Assume /additional-housenumbers/<relation>/view-result.json.
output = additional_housenumbers_view_result_json(relations, request_uri)?;
Expand Down
31 changes: 31 additions & 0 deletions src/wsgi_json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,34 @@ fn test_additional_housenumbers_view_result_json() {
let additional_housenumbers: util::NumberedStreets = serde_json::from_value(result).unwrap();
assert_eq!(additional_housenumbers.len(), 0);
}

/// Tests the /api part of our_application_json(), the relations + some case.
#[test]
fn test_our_application_json_api_relations_some() {
let mut test_wsgi = wsgi::tests::TestWsgi::new();
{
let conn = test_wsgi.get_ctx().get_database_connection().unwrap();
conn.execute_batch(
"insert into stats_jsons (category, json) values ('relations', '[1, 2]');",
)
.unwrap();
}

let result = test_wsgi.get_json_for_path("/api/relations.json");

let relations: Vec<u64> = serde_json::from_value(result).unwrap();
assert_eq!(relations.len(), 2);
assert_eq!(relations[0], 1);
assert_eq!(relations[1], 2);
}

/// Tests the /api part of our_application_json(), the relations + none case.
#[test]
fn test_our_application_json_api_relations_none() {
let mut test_wsgi = wsgi::tests::TestWsgi::new();

let result = test_wsgi.get_json_for_path("/api/relations.json");

let relations: Vec<u64> = serde_json::from_value(result).unwrap();
assert_eq!(relations.len(), 0);
}
Loading