Skip to content

Commit

Permalink
Merge pull request #153 from lawinslow/master
Browse files Browse the repository at this point in the history
Added tests for functions requiring authentication
  • Loading branch information
Luke Winslow committed Dec 30, 2015
2 parents e96fa0b + 45b134d commit af8dfda
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.DS_Store
.Renviron
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before_install:

install:
- ./pkg-build.sh install_deps
- ./pkg-build.sh install_github jimhester/covr

script:
- ./pkg-build.sh run_tests
Expand All @@ -28,3 +29,7 @@ env:
- RVERSION=oldrel
- RVERSION=release
- RVERSION=devel

after_success:
- ./pkg-build.sh run_script -e 'library(covr);codecov()'

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ScienceBase R Tools
===
[![Build Status](https://travis-ci.org/USGS-R/sbtools.svg?branch=master)](https://travis-ci.org/USGS-R/sbtools)
[![Build Status](https://travis-ci.org/USGS-R/sbtools.svg?branch=master)](https://travis-ci.org/USGS-R/sbtools) [![codecov.io](https://codecov.io/github/USGS-R/sbtools/coverage.svg?branch=master)](https://codecov.io/github/USGS-R/sbtools?branch=master)

Tools for interfacing R with ScienceBase data services.

Expand Down
2 changes: 1 addition & 1 deletion man/is_logged_in.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sb_ping.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/session_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/session_logout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions tests/testthat/test-auth.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@



context("test sb functionality requiring authentication")

test_that("authenticate_sb login results in valid session", {

if(is.na(Sys.getenv("sb_user", unset=NA))){
skip("Authenticated tests skipped due to lack of login info")
}


expect_silent(authenticate_sb(Sys.getenv("sb_user", unset=""), Sys.getenv("sb_pass", unset="")))
expect_true(session_validate())

expect_equal(nchar(user_id()), 24)

})

test_that("item creation, identifiers, and file upload works", {

if(is.na(Sys.getenv("sb_user", unset=NA))){
skip("Authenticated tests skipped due to lack of login info")
}

authenticate_sb(Sys.getenv("sb_user", unset=""), Sys.getenv("sb_pass", unset=""))

#create an item
item = item_create(title="automated testing item")
expect_is(item, 'sbitem')

#add item identifier
rand_key = as.character(floor(runif(1, 0, 10^12)))
expect_equal(item_update_identifier(item, 'test_scheme', 'test_type', rand_key)$status, 200)

#upload file
expect_is(item_append_files(item, system.file("examples/data.csv", package="sbtools")), 'sbitem')

#download file
dir_name = tempdir()
dl_files = item_file_download(item, dest_dir=dir_name)

expect_equal(file.info(dl_files)$size, file.info(system.file("examples/data.csv", package="sbtools"))$size)

#check item identifier (checking issue #74)
ident = item_get(item)$identifier

expect_equal(ident[[1]]$type, "test_type")
expect_equal(ident[[1]]$scheme, "test_scheme")
expect_equal(ident[[1]]$key, rand_key)

#remove the test item when done
item_rm(item)

expect_error(item_get(item), 'Item not found*.')

expect_silent(session_logout())
})




2 changes: 1 addition & 1 deletion tests/testthat/test-eg.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ context("authentication")

test_that("session validation works appropriately", {
expect_false(session_validate(5))
expect_null(current_session())
#expect_null(current_session())
session <- httr::handle("http://google.com")
attributes(session) <- c(attributes(session), list(birthdate=Sys.time()))
expect_true(session_validate(session))
Expand Down

0 comments on commit af8dfda

Please sign in to comment.