Skip to content

Commit

Permalink
BNLCJobToGeoData : utilise nouvelle BNLC (#3674)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Dec 20, 2023
1 parent 765e30f commit 7d9bb49
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
10 changes: 9 additions & 1 deletion apps/transport/lib/jobs/geo_data/bnlc_to_geo_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defmodule Transport.Jobs.BNLCToGeoData do

@impl Oban.Worker
def perform(%{}) do
[%DB.Resource{} = resource] = relevant_dataset() |> DB.Dataset.official_resources()
[%DB.Resource{} = resource] =
relevant_dataset()
|> Map.fetch!(:resources)
|> Enum.filter(fn %DB.Resource{datagouv_id: datagouv_id} -> datagouv_id == bnlc_datagouv_id() end)

Transport.Jobs.BaseGeoData.import_replace_data(resource, &prepare_data_for_insert/2)
:ok
Expand Down Expand Up @@ -40,4 +43,9 @@ defmodule Transport.Jobs.BNLCToGeoData do

Transport.Jobs.BaseGeoData.prepare_csv_data_for_import(body, prepare_data_fn)
end

defp bnlc_datagouv_id do
%{resource_id: resource_id} = Map.fetch!(Application.fetch_env!(:transport, :consolidation), :bnlc)
resource_id
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ defmodule Transport.Test.Transport.Jobs.ConsolidateBNLCJobTest do
tmp_path = @tmp_path

expected_url =
"https://demo.data.gouv.fr/api/1/datasets/5d6eaffc8b4c417cdc452ac3/resources/4fd78dee-e122-4c0d-8bf6-ff55d79f3af1/upload/"
"https://demo.data.gouv.fr/api/1/datasets/bnlc_fake_dataset_id/resources/bnlc_fake_resource_id/upload/"

Transport.HTTPoison.Mock
|> expect(:request, fn :post,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ defmodule Transport.Test.Transport.Jobs.ConsolidateLEZsJobTest do
assert String.ends_with?(path, "aires.geojson")

assert url ==
"https://demo.data.gouv.fr/api/1/datasets/624ff4b1bbb449a550264040/resources/3ddd29ee-00dd-40af-bc98-3367adbd0289/upload/"
"https://demo.data.gouv.fr/api/1/datasets/zfe_fake_dataset_id/resources/zfe_aires_fake_resource_id/upload/"

assert headers == [{"content-type", "multipart/form-data"}, {"X-API-KEY", "fake-datagouv-api-key"}]
{:ok, %HTTPoison.Response{body: "", status_code: 200}}
Expand All @@ -257,7 +257,7 @@ defmodule Transport.Test.Transport.Jobs.ConsolidateLEZsJobTest do
assert String.ends_with?(path, "voies.geojson")

assert url ==
"https://demo.data.gouv.fr/api/1/datasets/624ff4b1bbb449a550264040/resources/98c6bcdb-1205-4481-8859-f885290763f2/upload/"
"https://demo.data.gouv.fr/api/1/datasets/zfe_fake_dataset_id/resources/zfe_voies_fake_resource_id/upload/"

assert headers == [{"content-type", "multipart/form-data"}, {"X-API-KEY", "fake-datagouv-api-key"}]
{:ok, %HTTPoison.Response{body: "", status_code: 200}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Transport.Jobs.BNLCToGeoDataTest do

setup :verify_on_exit!

@bnlc_datagouv_id "bnlc_fake_resource_id"
@bnlc_content ~s("id_lieu","Xlong","Ylat","nbre_pl"\n"2A004-C-001","8.783403","41.9523692","0"\n"01024-C-001","5.158352778","46.28957222","5")

test "import a BNLC to the DB" do
Expand Down Expand Up @@ -54,7 +55,7 @@ defmodule Transport.Jobs.BNLCToGeoDataTest do

# insert bnlc resources
insert(:resource, %{dataset_id: dataset_id, is_community_resource: true})
%{id: resource_id} = insert(:resource, %{dataset_id: dataset_id})
%{id: resource_id} = insert(:resource, %{dataset_id: dataset_id, datagouv_id: @bnlc_datagouv_id})
# insert bnlc resource history
%{id: id_0} =
insert(:resource_history, %{
Expand Down
15 changes: 14 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ config :transport,
datagouvfr_apikey: "fake-datagouv-api-key",
# NOTE: some tests still rely on ExVCR cassettes at the moment. We configure the
# expected host here, until we move to a behaviour-based testing instead.
gtfs_validator_url: "https://validation.transport.data.gouv.fr"
gtfs_validator_url: "https://validation.transport.data.gouv.fr",
consolidation: %{
zfe: %{
dataset_id: "zfe_fake_dataset_id",
resource_ids: %{
"voies" => "zfe_voies_fake_resource_id",
"aires" => "zfe_aires_fake_resource_id"
}
},
bnlc: %{
dataset_id: "bnlc_fake_dataset_id",
resource_id: "bnlc_fake_resource_id"
}
}

secret_key_base = "SOME-LONG-SECRET-KEY-BASE-FOR-TESTING-SOME-LONG-SECRET-KEY-BASE-FOR-TESTING"

Expand Down

0 comments on commit 7d9bb49

Please sign in to comment.