wikibase 0.7.6

A library to access Wikibase
Documentation
extern crate wikibase;

use wikibase::query;
use wiremock::matchers::query_param;
use wiremock::{Mock, MockServer, ResponseTemplate};

async fn start_mock() -> MockServer {
    let server = MockServer::start().await;
    let siteinfo = serde_json::json!({
        "batchcomplete": "",
        "query": {
            "general": {"sitename": "Wikidata", "dbname": "wikidatawiki"},
            "namespaces": {
                "0": {"id": 0, "case": "first-letter", "content": "", "*": ""}
            },
            "namespacealiases": [],
            "libraries": [],
            "extensions": [],
            "statistics": {}
        }
    });
    Mock::given(query_param("meta", "siteinfo"))
        .respond_with(ResponseTemplate::new(200).set_body_json(siteinfo))
        .mount(&server)
        .await;
    server
}

/// Test if the URL is changed from the default to another instance.
///
/// Setting the API URL should change the request URL returned by a query.
#[tokio::test]
async fn test_api_url() {
    let server1 = start_mock().await;
    let server2 = start_mock().await;
    let url1 = server1.uri();
    let url2 = server2.uri();

    let mut configuration = wikibase::Configuration::new_with_url("Testing/0.1", &url1)
        .await
        .unwrap();
    let entity_query = query::EntityQuery::new(vec!["Q43453".to_string()], "uk");
    assert_eq!(
        format!(
            "{}?action=wbgetentities&ids=Q43453&languages=uk&uselang=uk&format=json",
            url1
        ),
        entity_query.url(&configuration)
    );

    configuration.set_api_url(&url2).await;
    assert_eq!(
        format!(
            "{}?action=wbgetentities&ids=Q43453&languages=uk&uselang=uk&format=json",
            url2
        ),
        entity_query.url(&configuration)
    );
}

/// Test if user-agent is constructed correctly.
///
/// User-agent has to consist of the user user-agent prefix, and the
/// Wikibase user-agent.
#[tokio::test]
async fn test_user_agent() {
    let server = start_mock().await;
    let start = "Testing/0.1";
    let expected = format!("{} Wikibase-RS/{}", &start, env!("CARGO_PKG_VERSION"));
    let configuration = wikibase::Configuration::new_with_url(start, &server.uri())
        .await
        .unwrap();
    assert_eq!(expected, configuration.user_agent());
}