-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streamlined setting environment variables into setup_ckanr, superseding set_test_env #37
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f27ea7e
Streamlined setting environment variables into setup_ckanr, supersedi…
c2f1aee
Replaced references to set_test_env with setup_ckanr.
4b2ee05
fixed a typo in test-resource_update.R
0e0a534
test-ckanr_settings.R - un-clobber test settings
7b93c22
consistent use of setup_ckanr; consistent use of check_ckan and other…
0a3e7b6
added a failsafe to ds_search test
8916a83
included usage of setup_ckanr in readme.md and readme.rmd
4e15271
fixed build error in vignette
6f78b9c
last formatting of zzz.R
35c8250
renamed setup_ckanr to ckanr_setup to align with ckanr_settings
d757201
restored spacing around equal signs
3d141f6
reflowed parameters, removed line breaks from parameters where possible
8647ae5
last clean-up of line breaks, keeping "args" params "url", "as", "...…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#' Get or set ckanr CKAN settings | ||
#' | ||
#' @export | ||
#' @return \code{ckanr_settings} prints your base url, API key (if used), and | ||
#' optional test server settings (URL, API key, a dataset ID and a resource ID). | ||
#' \code{setup_ckanr} sets your production and test settings, while | ||
#' \code{get_test_*} get each of those respective settings. | ||
#' \code{test_behaviour} indicates whether the CKANR test suite will skip | ||
#' ("SKIP") or fail ("FAIL") writing tests in case the configured test | ||
#' CKAN settings don't work. | ||
#' @seealso \code{\link{setup_ckanr}}, | ||
#' \code{\link{get_default_url}}, \code{\link{get_default_key}}, | ||
#' \code{\link{get_test_url}}, \code{\link{get_test_key}}, | ||
#' \code{\link{get_test_did}}, \code{\link{get_test_rid}}, | ||
#' \code{\link{get_test_gid}}, \code{get_test_oid}, | ||
#' \code{get_test_behaviour}. | ||
#' @family ckanr settings | ||
#' @examples | ||
#' ckanr_settings() | ||
ckanr_settings <- function() { | ||
ops <- list(url = Sys.getenv("CKANR_DEFAULT_URL", ""), | ||
key = Sys.getenv("CKANR_DEFAULT_KEY", ""), | ||
test_url = Sys.getenv("CKANR_TEST_URL", ""), | ||
test_key = Sys.getenv("CKANR_TEST_KEY", ""), | ||
test_did = Sys.getenv("CKANR_TEST_DID", ""), | ||
test_rid = Sys.getenv("CKANR_TEST_RID", ""), | ||
test_gid = Sys.getenv("CKANR_TEST_GID", ""), | ||
test_oid = Sys.getenv("CKANR_TEST_OID", ""), | ||
test_behaviour = Sys.getenv("CKANR_TEST_BEHAVIOUR", "") | ||
) | ||
structure(ops, class = "ckanr_settings") | ||
} | ||
|
||
#' @export | ||
print.ckanr_settings <- function(x, ...) { | ||
cat("<ckanr settings>", sep = "\n") | ||
cat(" Base URL: ", x$url, "\n") | ||
cat(" API key: ", x$key, "\n") | ||
cat(" Test CKAN URL:", x$test_url, "\n") | ||
cat(" Test CKAN API key:", x$test_key, "\n") | ||
cat(" Test CKAN dataset ID:", x$test_did, "\n") | ||
cat(" Test CKAN resource ID:", x$test_rid, "\n") | ||
cat(" Test CKAN group ID:", x$test_gid, "\n") | ||
cat(" Test CKAN organization ID:", x$test_oid, "\n") | ||
cat(" Test behaviour if CKAN offline:", x$test_behaviour) | ||
} | ||
|
||
#------------------------------------------------------------------------------# | ||
# Setters | ||
# | ||
#' Configure default CKAN settings | ||
#' | ||
#' @export | ||
#' @param url A CKAN URL (optional), default: "http://data.techno-science.ca/" | ||
#' @param key A CKAN API key (optional, character) | ||
#' @param test_url (optional, character) A valid CKAN URL for testing purposes | ||
#' @param test_key (optional, character) A valid CKAN API key privileged to | ||
#' create datasets at \code{test_url} | ||
#' @param test_did (optional, character) A valid CKAN dataset ID, existing at | ||
#' \code{test_url} | ||
#' @param test_rid (optional, character) A valid CKAN resource ID, attached to | ||
#' \code{did} | ||
#' @param test_gid (optional, character) A valid CKAN group name at \code{test_url} | ||
#' @param test_oid (optional, character) A valid CKAN organization name at | ||
#' \code{test_url} | ||
#' @param test_behaviour (optional, character) Whether to fail ("FAIL") or skip | ||
#' ("SKIP") writing tests in case of problems with the configured test CKAN. | ||
#' @details | ||
#' \code{setup_ckanr} sets CKAN connection details. \code{ckanr}'s functions | ||
#' default to use the default URL and API key unless specified explicitly. | ||
#' | ||
#' \code{ckanr}'s automated tests require a valid CKAN URL, a privileged API key | ||
#' for that URL, plus the IDs of an existing dataset and an existing resource, | ||
#' repectively. | ||
#' | ||
#' The writing tests (create, update, delete) can fail for two reasons: | ||
#' failures in \code{ckanr}'s code which the tests aim to detect, | ||
#' or failures in the configured CKAN, which are not necessarily a problem | ||
#' with \code{ckanr}'s code but prevent the tests to prove otherwise. | ||
#' | ||
#' Setting \code{test_behaviour} to \code{"SKIP"} will allow writing tests to skip | ||
#' if the configured test CKAN fails. This is desirable to e.g. test the other | ||
#' functions even if the tester has no write access to a CKAN instance. | ||
#' | ||
#' Setting \code{test_behaviour} to \code{"FAIL"} will let the tester find any | ||
#' problems with both the configured test CKAN and the writing functions. | ||
#' | ||
#' @examples | ||
#' # CKAN users without admin/editor privileges could run: | ||
#' setup_ckanr(url="http://data.techno-science.ca/") | ||
#' | ||
#' # Privileged CKAN editor/admin users can run: | ||
#' setup_ckanr(url="http://data.techno-science.ca/", key="some-CKAN-API-key") | ||
#' | ||
#' # ckanR developers/testers can run: | ||
#' setup_ckanr(url="http://data.techno-science.ca/", key="some-CKAN-API-key", | ||
#' test_url="http://test-ckan.gov/",test_key="test-ckan-API-key", | ||
#' test_did="test-ckan-dataset-id",test_rid="test-ckan-resource-id", | ||
#' test_gid="test-group-name", test_oid="test-organzation-name", | ||
#' test_behaviour="FAIL") | ||
#' | ||
#' # Not specifying the default CKAN URL will reset the CKAN URL to its default | ||
#' # "http://data.techno-science.ca/": | ||
#' setup_ckanr() | ||
setup_ckanr <- function( | ||
url="http://data.techno-science.ca/", | ||
key=NULL, | ||
test_url=NULL, | ||
test_key=NULL, | ||
test_did=NULL, | ||
test_rid=NULL, | ||
test_gid=NULL, | ||
test_oid=NULL, | ||
test_behaviour=NULL){ | ||
Sys.setenv("CKANR_DEFAULT_URL" = url) | ||
if (!is.null(key)) Sys.setenv("CKANR_DEFAULT_KEY" = key) | ||
if (!is.null(test_url)) Sys.setenv("CKANR_TEST_URL" = test_url) | ||
if (!is.null(test_key)) Sys.setenv("CKANR_TEST_KEY" = test_key) | ||
if (!is.null(test_did)) Sys.setenv("CKANR_TEST_DID" = test_did) | ||
if (!is.null(test_rid)) Sys.setenv("CKANR_TEST_RID" = test_rid) | ||
if (!is.null(test_gid)) Sys.setenv("CKANR_TEST_GID" = test_gid) | ||
if (!is.null(test_oid)) Sys.setenv("CKANR_TEST_OID" = test_oid) | ||
if (!is.null(test_behaviour)) Sys.setenv("CKANR_TEST_BEHAVIOUR" = test_behaviour) | ||
} | ||
|
||
#------------------------------------------------------------------------------# | ||
# Getters | ||
# | ||
#' @export | ||
#' @rdname ckanr_settings | ||
get_default_url <- function(){ Sys.getenv("CKANR_DEFAULT_URL") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_default_key <- function(){ Sys.getenv("CKANR_DEFAULT_KEY") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_test_url <- function(){ Sys.getenv("CKANR_TEST_URL") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_test_key <- function(){ Sys.getenv("CKANR_TEST_KEY") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_test_did <- function(){ Sys.getenv("CKANR_TEST_DID") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_test_rid <- function(){ Sys.getenv("CKANR_TEST_RID") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_test_gid <- function(){ Sys.getenv("CKANR_TEST_GID") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_test_oid <- function(){ Sys.getenv("CKANR_TEST_OID") } | ||
|
||
#' @export | ||
#' @rdname ckanr_settings | ||
get_test_behaviour <- function(){ Sys.getenv("CKANR_TEST_BEHAVIOUR") } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@florianm I would suggest making this function to set settings the same name format as the function to get settings: So
ckanr_setup
andckanr_settings
, that okay?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be even more consistent, will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great 👍