From c235a154042fe715e609a0d60a22bfa6913fbc14 Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 15:52:31 -0600 Subject: [PATCH 1/8] added tests that require authentication --- .gitignore | 1 + tests/testthat/test-auth.R | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/testthat/test-auth.R diff --git a/.gitignore b/.gitignore index 728e389..ee52dd3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .Rhistory .RData .DS_Store +.Renviron \ No newline at end of file diff --git a/tests/testthat/test-auth.R b/tests/testthat/test-auth.R new file mode 100644 index 0000000..3b5f2bb --- /dev/null +++ b/tests/testthat/test-auth.R @@ -0,0 +1,54 @@ + + + +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") + } + + #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_is(item_update_identifier(item, 'test_scheme', 'test_type', rand_key), 'sbitem') + + #upload file + expect_is(item_append_files(item, 'examples/data.csv'), '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('examples/data.csv')$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) + +}) + + + + From 8f871d67bed71b5118ebfd5600c10437bc7d17cb Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 16:10:45 -0600 Subject: [PATCH 2/8] roxy update --- man/is_logged_in.Rd | 2 +- man/sb_ping.Rd | 2 +- man/session_info.Rd | 2 +- man/session_logout.Rd | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/man/is_logged_in.Rd b/man/is_logged_in.Rd index f683bd2..02bbd6f 100644 --- a/man/is_logged_in.Rd +++ b/man/is_logged_in.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/is_logged_in.R \name{is_logged_in} \alias{is_logged_in} diff --git a/man/sb_ping.Rd b/man/sb_ping.Rd index 6ac918d..8caa667 100644 --- a/man/sb_ping.Rd +++ b/man/sb_ping.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/sb_ping.R \name{sb_ping} \alias{sb_ping} diff --git a/man/session_info.Rd b/man/session_info.Rd index 0ac2e8e..0d69a08 100644 --- a/man/session_info.Rd +++ b/man/session_info.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/session_info.R \name{session_info} \alias{session_info} diff --git a/man/session_logout.Rd b/man/session_logout.Rd index 2725a35..0a85a3d 100644 --- a/man/session_logout.Rd +++ b/man/session_logout.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/session_logout.R \name{session_logout} \alias{session_logout} From 85a21b71aef3600d68d1794304382f7499f58525 Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 16:11:04 -0600 Subject: [PATCH 3/8] had wrong test for actual function return --- tests/testthat/test-auth.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-auth.R b/tests/testthat/test-auth.R index 3b5f2bb..e857344 100644 --- a/tests/testthat/test-auth.R +++ b/tests/testthat/test-auth.R @@ -23,22 +23,24 @@ test_that("item creation, identifiers, and file upload works", { 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_is(item_update_identifier(item, 'test_scheme', 'test_type', rand_key), 'sbitem') + expect_equal(item_update_identifier(item, 'test_scheme', 'test_type', rand_key)$status, 200) #upload file - expect_is(item_append_files(item, 'examples/data.csv'), 'sbitem') + expect_is(item_append_files(item, 'inst/examples/data.csv'), '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('examples/data.csv')$size) + expect_equal(file.info(dl_files)$size, file.info('inst/examples/data.csv')$size) #check item identifier (checking issue #74) ident = item_get(item)$identifier @@ -47,6 +49,12 @@ test_that("item creation, identifiers, and file upload works", { 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()) }) From b8d4303e6d4ba83034b387898766776266549a3e Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 16:17:21 -0600 Subject: [PATCH 4/8] fixed file path issue in tests --- tests/testthat/test-auth.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-auth.R b/tests/testthat/test-auth.R index e857344..fedea23 100644 --- a/tests/testthat/test-auth.R +++ b/tests/testthat/test-auth.R @@ -34,13 +34,13 @@ test_that("item creation, identifiers, and file upload works", { expect_equal(item_update_identifier(item, 'test_scheme', 'test_type', rand_key)$status, 200) #upload file - expect_is(item_append_files(item, 'inst/examples/data.csv'), 'sbitem') + 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('inst/examples/data.csv')$size) + 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 From 143f8204ebaf65b16fd5d3918dce30ee88e6dd8d Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 16:17:36 -0600 Subject: [PATCH 5/8] because auth is used earlier, null can't be assumed --- tests/testthat/test-eg.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-eg.R b/tests/testthat/test-eg.R index f6dca28..a498e46 100644 --- a/tests/testthat/test-eg.R +++ b/tests/testthat/test-eg.R @@ -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)) From b800f529abc8befb6550df3c0fc3fc27b6ae1e7a Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 16:45:21 -0600 Subject: [PATCH 6/8] add codecovr.io code and badge --- .travis.yml | 5 +++++ README.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8381c85..de6e082 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -28,3 +29,7 @@ env: - RVERSION=oldrel - RVERSION=release - RVERSION=devel + +after_success: + - Rscript -e 'library(covr);codecov()' + \ No newline at end of file diff --git a/README.md b/README.md index 8f21498..59e3166 100644 --- a/README.md +++ b/README.md @@ -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. From 2482767f48088a8a90d9cae40966a829adfa1b24 Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 17:02:49 -0600 Subject: [PATCH 7/8] using different way to run R code --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index de6e082..51b123a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,5 +31,5 @@ env: - RVERSION=devel after_success: - - Rscript -e 'library(covr);codecov()' + - ./pkg-build.sh RunScript -e 'library(covr);codecov()' \ No newline at end of file From 45b134d572daa56f1d56f3921ed2188eb5c2156e Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Wed, 30 Dec 2015 17:05:28 -0600 Subject: [PATCH 8/8] fixed wrote format --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 51b123a..bc2c795 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,5 +31,5 @@ env: - RVERSION=devel after_success: - - ./pkg-build.sh RunScript -e 'library(covr);codecov()' + - ./pkg-build.sh run_script -e 'library(covr);codecov()' \ No newline at end of file