Skip to content

Commit

Permalink
new tests, new logo
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbuffalo committed Aug 22, 2023
1 parent 2017347 commit a477fc3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@ it's on the remote, this should prompt an error.

- wrap git, do something like `scf clone` that pulls in Git repo.
- recursive pulling.
- check no external file; add tests


Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod lib {
pub mod macros;
pub mod remote;
pub mod utils;
pub mod test_utilities;
}

pub mod logging_setup;
10 changes: 7 additions & 3 deletions src/lib/api/figshare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ use crate::lib::data::{DataFile, MergedFile};
use crate::lib::remote::{AuthKeys, RemoteFile, DownloadInfo,RequestData};
use crate::lib::project::LocalMetadata;

const BASE_URL: &str = "https://api.figshare.com/v2/";
pub const FIGSHARE_BASE_URL: &str = "https://api.figshare.com/v2/";

// for testing:
const TEST_TOKEN: &str = "test-token";

// for serde deserialize default
fn figshare_api_url() -> String {
BASE_URL.to_string()
FIGSHARE_BASE_URL.to_string()
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -262,7 +262,7 @@ impl FigShareAPI {
auth_keys
};
let token = auth_keys.get("figshare".to_string())?;
let base_url = base_url.unwrap_or(BASE_URL.to_string());
let base_url = base_url.unwrap_or(FIGSHARE_BASE_URL.to_string());
Ok(FigShareAPI {
base_url,
article_id: None,
Expand All @@ -275,6 +275,10 @@ impl FigShareAPI {
self.token = token;
}

pub fn get_base_url(&self) -> String {
self.base_url.clone()
}

async fn issue_request<T: serde::Serialize>(&self, method: Method, endpoint: &str,
data: Option<RequestData<T>>) -> Result<Response> {
let mut headers = HeaderMap::new();
Expand Down
30 changes: 27 additions & 3 deletions src/lib/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ pub struct DataCollection {
/// interacting with the data manifest (including remotes).
impl DataCollection {
pub fn new() -> Self {

Self {
files: HashMap::new(),
remotes: HashMap::new(),
Expand Down Expand Up @@ -575,6 +574,9 @@ impl DataCollection {
}
}

// Register the remote
//
// This can overwrite existing entries.
pub fn register_remote(&mut self, dir: &String, remote: Remote) -> Result<()> {
self.validate_remote_directory(dir)?;
self.remotes.insert(dir.to_string(), remote);
Expand Down Expand Up @@ -1011,7 +1013,11 @@ impl DataCollection {

#[cfg(test)]
mod tests {
use super::DataFile;
use crate::lib::api::figshare::{FIGSHARE_BASE_URL,FigShareAPI, self};
use crate::lib::remote::Remote;
use crate::lib::test_utilities::check_error;

use super::{DataFile, DataCollection, DataCollectionMetadata};
use std::path::Path;
use std::io::Write;
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -1125,6 +1131,24 @@ mod tests {
}


// ==== Data Collection Tests
#[test]
fn test_register_remote_figshare() {
let mut dc = DataCollection::new();

let dir = "data/supplement".to_string();
let result = FigShareAPI::new("Test remote", None);
assert!(result.is_ok(), "FigShareAPI::new() resulted in error!");
let figshare = result.unwrap();
assert!(figshare.get_base_url() == FIGSHARE_BASE_URL, "FigShareAPI.base_url is not correct!");
dc.register_remote(&dir, Remote::FigShareAPI(figshare)).unwrap();

// check that it's been inserted
assert!(dc.remotes.contains_key(&dir), "Remote not registered!");

// Let's check that validate_remote_directory() is working
let figshare = FigShareAPI::new("Another test remote", None).unwrap();
let result = dc.register_remote(&dir, Remote::FigShareAPI(figshare));
check_error(result, "already tracked");
}

}

0 comments on commit a477fc3

Please sign in to comment.