Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Test expansion #67

Merged
merged 4 commits into from
Jan 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R/fs_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#' @import httr
#' @export
#' @examples \dontrun{
#' fs_search("Fish", category="Ecology")
#' fs_search("Fish", category = "Ecology")
#' }
fs_search <-
function(query, author=NA, title=NA, description=NA, tag=NA, category=NA, from_date=NA, to_date=NA, mine=FALSE, public_only=FALSE, private_only=FALSE, drafts_only=FALSE, session = fs_get_auth(), base = "http://api.figshare.com/v1") {
function(query, author = NA, title = NA, description = NA, tag = NA, category = NA, from_date = NA, to_date = NA, mine = FALSE, public_only = FALSE, private_only = FALSE, drafts_only = FALSE, session = fs_get_auth(), base = "http://api.figshare.com/v1") {

# resolve name conflict?
the_title <- title
Expand Down Expand Up @@ -81,12 +81,12 @@ fs_search <-
method_ <- paste(method, "&page=", i, sep="")
request = paste(base, method_, sep="/")
out <- GET(request, session)
parsed <- parsed_content(out)
parsed <- content(out, as = "parsed")
parsed$items
})
out <- unlist(all, recursive = FALSE)
}
class(out) = "fs_object"
class(out) <- "fs_object"
out
}

Expand Down
201 changes: 201 additions & 0 deletions inst/tests/figshare_tests.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@

context("Authentication, creating authors, and content")

test_that("We are able to create objects on figshare", {
# Make sure we cannot authenticate with bad credentials
expect_error(fs_auth(cKey = "a",
cSecret = "b",
token = "c",
token_secret = "d"))
# fs_auth
# Note: These keys are for the rOpenSciDemo account. All content gets wiped nightly.
# Please do not use these in production. Create new keys from your own account
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")

# fs_create
new_object <- fs_create("My Title", "A description of the object", "dataset")
expect_is(new_object, "numeric")
fs_delete(new_object)
# fs_create_author
expect_error(fs_create_author()) # Can't create an empty author
})

# ------------------------------------------------------------------

context("Data Retrieval")

test_that("Downloads work correctly", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")

# Downloading a csv file
url <- fs_download(90818)
data <- read.csv(url)
expect_that(data, is_a("data.frame"))

#downloading an Excel file
excel_url <- fs_download(894949)
excel_data <- gdata::read.xls(excel_url)
expect_that(excel_data, is_a("data.frame"))
})




# ----------------------------------------------------------------
context("Metadata to/from existing objects")



# fs_add_tags
# fs_update
test_that("We are able to add metadata to existing objects", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")
data <- head(iris)
new_fs_obj <- fs_create("Dummy data", "Fisher's iris", "dataset")
# fs_add_authors
expect_that(fs_add_authors(new_fs_obj, list("Scott Chamberlain", "Karthik Ram")), shows_message("found ids for all authors"))
# fs_add_categories
# difficult to write detailed tests for functions that return invisible output.
# only testing for bad calls.
expect_error(fs_add_categories(new_fs_obj, ""))
# fs_add_links
# For now there is no test for add_links. See discussion at issue #63
expect_error(fs_add_tags(new_fs_obj))
# fs_update, again can't really test this.
# fs_update(new_fs_obj, title = "This is now the new title")
})

test_that("articles are tagged as 'Published using rfigshare'", {


write.csv(mtcars, "mtcars.csv")
id <- fs_new_article(title="A Test of rfigshare",
description="This is a test",
type="dataset",
authors=c("Karthik Ram", "Scott Chamberlain"),
tags=c("ecology", "openscience"),
categories="Ecology",
links="http://ropensci.org",
files="mtcars.csv",
visibility="private")

details <- fs_details(id, mine = TRUE)

expect_match("Published using rfigshare", sapply(details$tags, `[[`, "name")[[1]])

fs_delete(id)
unlink("mtcars.csv")
})

test_that("We can browse our own files", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")
expect_is(fs_browse(mine = TRUE), "list")
})

# ----------------------------------------------------------------
context("Searching figshare")
# fs_author_search
# fs_search
# fs_browse
# fs_category_list
test_that("We are able to perform search correctly", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")
# fs_search
# skipping this for now because the search function is broken
# expect_is(fs_author_search("Karthik Ram"), "list")


})


# ----------------------------------------------------------------
context("Manipulating objects on figshare")
# fs_make_public
# fs_make_private
# fs_delete (delete second)
test_that("We are able to change visibility of objects", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")
data <- head(iris)
new_fs_obj <- fs_create("Dummy data", "Fisher's iris", "dataset")
write.csv(data, file = "iris_data.csv")
fs_upload(new_fs_obj, "iris_data.csv")
expect_that(fs_make_private(new_fs_obj), prints_text("error"))
fs_add_categories(new_fs_obj, "Ecology")
expect_that(fs_make_private(new_fs_obj), prints_text("success"))
fs_delete(new_fs_obj)
unlink("iris_data.csv")
})

test_that("We can make articles public", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")
data <- head(iris)
new_fs_obj <- fs_create("Dummy data", "Fisher's iris", "dataset")
write.csv(data, file = "iris_data.csv")
fs_upload(new_fs_obj, "iris_data.csv")
expect_that(fs_make_public(new_fs_obj), prints_text("error"))
fs_add_categories(new_fs_obj, "Ecology")
expect_that(fs_make_public(new_fs_obj), prints_text("success"))
fs_delete(new_fs_obj)
unlink("iris_data.csv")

})
# ----------------------------------------------------------------
context("We can obtain summaries")
# plot_to_filename
# summary_fs_details
test_that("We can make articles public", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")
my_article <- fs_details("138")
summary_fs_details(my_article)
expect_that(summary_fs_details(my_article), prints_text("Article ID"))


})


# ----------------------------------------------------------------
context("Testing miscellaneous functions")
test_that("We can save plots to disk while uploading", {
fs_auth(cKey = "kCV1UF2V1Bjw01TybvzDCg",
cSecret = "dGLFrnXeBjXi6qdsO6vwAg",
token = "QsqBaOrTBI0wuotW7cTDwAgFvSV1bmNouEoqYdWoYbZAQsqBaOrTXI0wuotW7cTDwA",
token_secret = "2gz16wL1Tszh4TY2z6opcQ")
library(ggplot2)
p <- qplot(mpg, wt, data = mtcars)
plot_to_filename(p, "myfilename", ".")
expect_true(file.exists("myfilename.png"))
unlink("myfilename.png")

})


# miscellaneous functions
# fs_embed
# fs_ids
# Can't test because it's broken
# also missing tests for fs_embed

14 changes: 0 additions & 14 deletions inst/tests/test_auth.R

This file was deleted.

23 changes: 0 additions & 23 deletions inst/tests/test_rfigshare_tag.R

This file was deleted.