Page MenuHomeDevCentral

D3244.id8335.diff
No OneTemporary

D3244.id8335.diff

diff --git a/opendatasoft-explore-api/Cargo.toml b/opendatasoft-explore-api/Cargo.toml
--- a/opendatasoft-explore-api/Cargo.toml
+++ b/opendatasoft-explore-api/Cargo.toml
@@ -25,7 +25,7 @@
[dev-dependencies]
# Mockito upgrade to 1.x is blocked by T1876
-mockito = "~0.32.5"
+mockito = "~1.1.0"
lazy_static = "~1.4.0"
[dependencies.tokio]
diff --git a/opendatasoft-explore-api/tests/requests_test.rs b/opendatasoft-explore-api/tests/requests_test.rs
--- a/opendatasoft-explore-api/tests/requests_test.rs
+++ b/opendatasoft-explore-api/tests/requests_test.rs
@@ -3,7 +3,7 @@
use std::collections::HashMap;
use lazy_static::lazy_static;
-use mockito::{mock, Mock};
+use mockito::{Server, ServerGuard};
use serde_json::json;
use opendatasoft_explore_api::requests::ExploreApiEndPoint;
@@ -16,49 +16,77 @@
static TEST_RECORD_ID: &'static str = "eb04cba18e872814448a7fda829f3f1918cfae0b";
lazy_static! {
- static ref MOCK_URL: String = mockito::server_url();
-
static ref MOCK_FILES: HashMap<&'static str, &'static str> = {
let mut m = HashMap::new();
- m.insert("/catalog/datasets", include_str!("requests/catalog_datasets.json"));
- m.insert("/catalog/facets", include_str!("requests/catalog_facets.json"));
- m.insert("/catalog/exports/rdf", include_str!("requests/catalog_exports.rdf"));
- m.insert("/catalog/datasets/controle_techn/records", include_str!("requests/catalog_datasets_records.json"));
- m.insert("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits", include_str!("requests/catalog_dataset_fantoir.json"));
- m.insert("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/attachments", include_str!("requests/catalog_dataset_fantoir_attachments.json"));
- m.insert("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/facets", include_str!("requests/catalog_dataset_fantoir_facets.json"));
- m.insert("/catalog/datasets/controle_techn/records/eb04cba18e872814448a7fda829f3f1918cfae0b", include_str!("requests/catalog_dataset_record.json"));
+ m.insert(
+ "/catalog/datasets",
+ include_str!("requests/catalog_datasets.json"),
+ );
+ m.insert(
+ "/catalog/facets",
+ include_str!("requests/catalog_facets.json"),
+ );
+ m.insert(
+ "/catalog/exports/rdf",
+ include_str!("requests/catalog_exports.rdf"),
+ );
+ m.insert(
+ "/catalog/datasets/controle_techn/records",
+ include_str!("requests/catalog_datasets_records.json"),
+ );
+ m.insert(
+ "/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits",
+ include_str!("requests/catalog_dataset_fantoir.json"),
+ );
+ m.insert(
+ "/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/attachments",
+ include_str!("requests/catalog_dataset_fantoir_attachments.json"),
+ );
+ m.insert(
+ "/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/facets",
+ include_str!("requests/catalog_dataset_fantoir_facets.json"),
+ );
+ m.insert(
+ "/catalog/datasets/controle_techn/records/eb04cba18e872814448a7fda829f3f1918cfae0b",
+ include_str!("requests/catalog_dataset_record.json"),
+ );
m
};
}
-pub fn prepare_mock (url: &str) -> Mock {
- mock("GET", url)
- .with_status(200)
+pub async fn prepare_mock(url: &str) -> ServerGuard {
+ let mut s = Server::new_async().await;
+ s.mock("GET", url)
.with_body(MOCK_FILES[url])
- .create()
+ .create_async()
+ .await;
+ s
}
#[tokio::test]
-async fn test_get_datasets () {
- let _mock = prepare_mock("/catalog/datasets");
+async fn test_get_datasets() {
+ let server = prepare_mock("/catalog/datasets").await;
- let endpoint = ExploreApiEndPoint::new(&MOCK_URL);
+ let endpoint = ExploreApiEndPoint::new(&server.url());
let catalog = endpoint.get_datasets().await;
assert_eq!(426, catalog.total_count);
- assert_eq!(Link {
- href: "https://data.economie.gouv.fr/api/v2/catalog/datasets/mef-catalogue-temporaire".to_string(),
- rel: "self".to_string(),
- }, catalog.datasets[0].links[0]);
+ assert_eq!(
+ Link {
+ href: "https://data.economie.gouv.fr/api/v2/catalog/datasets/mef-catalogue-temporaire"
+ .to_string(),
+ rel: "self".to_string(),
+ },
+ catalog.datasets[0].links[0]
+ );
assert_eq!(3, catalog.datasets.len());
}
#[tokio::test]
-async fn test_export_datasets_catalog () {
- let _mock = prepare_mock("/catalog/exports/rdf");
+async fn test_export_datasets_catalog() {
+ let server = prepare_mock("/catalog/exports/rdf").await;
- let mut response = ExploreApiEndPoint::new(&MOCK_URL)
+ let mut response = ExploreApiEndPoint::new(&server.url())
.export_datasets_catalog("rdf")
.await;
@@ -75,32 +103,32 @@
}
#[tokio::test]
-async fn test_get_facets () {
- let _mock = prepare_mock("/catalog/facets");
+async fn test_get_facets() {
+ let server = prepare_mock("/catalog/facets").await;
- let endpoint = ExploreApiEndPoint::new(&MOCK_URL);
+ let endpoint = ExploreApiEndPoint::new(&server.url());
let facets = endpoint.get_facets().await;
assert!(facets.links[0].href.starts_with(TEST_URL));
let expected_facets_categories = vec![
- "features".to_string(), "modified".to_string(),
- "publisher".to_string(), "keyword".to_string(),
+ "features".to_string(),
+ "modified".to_string(),
+ "publisher".to_string(),
+ "keyword".to_string(),
"theme".to_string(),
];
- let actual_facets_categories: Vec<_> = facets.facets
- .into_iter()
- .map(|facet| facet.name)
- .collect();
+ let actual_facets_categories: Vec<_> =
+ facets.facets.into_iter().map(|facet| facet.name).collect();
assert_eq!(expected_facets_categories, actual_facets_categories);
}
#[tokio::test]
-async fn test_get_dataset_records () {
- let _mock = prepare_mock("/catalog/datasets/controle_techn/records");
+async fn test_get_dataset_records() {
+ let server = prepare_mock("/catalog/datasets/controle_techn/records").await;
- let results = ExploreApiEndPoint::new(&MOCK_URL)
+ let results = ExploreApiEndPoint::new(&server.url())
.get_dataset_records(TEST_DATASET_WITH_RECORDS_ID)
.await;
@@ -110,7 +138,10 @@
ResultsRecord::Aggregation(_) => unreachable!(),
ResultsRecord::Record(record) => record.clone(),
};
- assert_eq!("b839362b229db63bc9b344e980ae6273be7f80fd", record.record.id.as_str());
+ assert_eq!(
+ "b839362b229db63bc9b344e980ae6273be7f80fd",
+ record.record.id.as_str()
+ );
assert_eq!(
Some(&json!("Voiture Particulière")),
record.record.fields.get("cat_vehicule_libelle")
@@ -122,10 +153,10 @@
}
#[tokio::test]
-async fn test_get_dataset_information () {
- let _mock = prepare_mock("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits");
+async fn test_get_dataset_information() {
+ let server = prepare_mock("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits").await;
- let dataset = ExploreApiEndPoint::new(&MOCK_URL)
+ let dataset = ExploreApiEndPoint::new(&server.url())
.get_dataset_information(TEST_DATASET_ID)
.await;
@@ -133,21 +164,26 @@
}
#[tokio::test]
-async fn test_get_dataset_attachments () {
- let _mock = prepare_mock("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/attachments");
+async fn test_get_dataset_attachments() {
+ let server =
+ prepare_mock("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/attachments").await;
- let attachments = ExploreApiEndPoint::new(&MOCK_URL)
+ let attachments = ExploreApiEndPoint::new(&server.url())
.get_dataset_attachments(TEST_DATASET_ID)
.await;
- assert!(attachments.attachments[0].metas.url.starts_with("odsfile://"));
+ assert!(attachments.attachments[0]
+ .metas
+ .url
+ .starts_with("odsfile://"));
}
#[tokio::test]
-async fn test_get_dataset_facets () {
- let _mock = prepare_mock("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/facets");
+async fn test_get_dataset_facets() {
+ let server =
+ prepare_mock("/catalog/datasets/fichier-fantoir-des-voies-et-lieux-dits/facets").await;
- let facets = ExploreApiEndPoint::new(&MOCK_URL)
+ let facets = ExploreApiEndPoint::new(&server.url())
.get_dataset_facets(TEST_DATASET_ID)
.await;
@@ -155,10 +191,13 @@
}
#[tokio::test]
-async fn test_get_dataset_record () {
- let _mock = prepare_mock("/catalog/datasets/controle_techn/records/eb04cba18e872814448a7fda829f3f1918cfae0b");
+async fn test_get_dataset_record() {
+ let server = prepare_mock(
+ "/catalog/datasets/controle_techn/records/eb04cba18e872814448a7fda829f3f1918cfae0b",
+ )
+ .await;
- let record = ExploreApiEndPoint::new(&MOCK_URL)
+ let record = ExploreApiEndPoint::new(&server.url())
.get_dataset_record(TEST_DATASET_WITH_RECORDS_ID, TEST_RECORD_ID)
.await;

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 14:34 (21 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2262668
Default Alt Text
D3244.id8335.diff (9 KB)

Event Timeline