Add tests to check fetching sub/user/oauth
This commit is contained in:
parent
6cd53abd42
commit
0ca0eefaa4
@ -137,13 +137,13 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo
|
||||
let client: client::Client<_, hyper::Body> = CLIENT.clone();
|
||||
|
||||
let (token, vendor_id, device_id, user_agent, loid) = {
|
||||
let client = OAUTH_CLIENT.blocking_read();
|
||||
let client = tokio::task::block_in_place(move || OAUTH_CLIENT.blocking_read());
|
||||
(
|
||||
client.token.clone(),
|
||||
client.headers_map.get("Client-Vendor-Id").unwrap().clone(),
|
||||
client.headers_map.get("X-Reddit-Device-Id").unwrap().clone(),
|
||||
client.headers_map.get("User-Agent").unwrap().clone(),
|
||||
client.headers_map.get("x-reddit-loid").unwrap().clone(),
|
||||
client.headers_map.get("x-reddit-loid").cloned().unwrap_or_default(),
|
||||
)
|
||||
};
|
||||
// Build request to Reddit. When making a GET, request gzip compression.
|
||||
|
11
src/oauth.rs
11
src/oauth.rs
@ -208,3 +208,14 @@ impl Device {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_oauth_client() {
|
||||
initialize().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_oauth_client_refresh() {
|
||||
initialize().await;
|
||||
OAUTH_CLIENT.write().await.refresh().await.unwrap();
|
||||
}
|
||||
|
@ -434,3 +434,8 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
|
||||
nsfw: res["data"]["over18"].as_bool().unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
||||
async fn test_fetching_subreddit() {
|
||||
subreddit("rust", false).await.unwrap();
|
||||
}
|
||||
|
@ -129,3 +129,10 @@ async fn user(name: &str) -> Result<User, String> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
||||
async fn test_fetching_user() {
|
||||
let user = user("spez").await;
|
||||
assert!(user.is_ok());
|
||||
assert!(user.unwrap().karma > 100);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user