-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add testing for keyring; improve messaging to user for setting api token
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
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 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,50 @@ | ||
library(REDCapExporter) | ||
|
||
# Test if a new keyring can be built | ||
kr <- keyring::backend_file$new() | ||
try(kr$keyring_delete("testingring"), silent = TRUE) | ||
|
||
x <- tryCatch(REDCapExporter_keyring_check("testingring"), message = function(m) {m}) | ||
stopifnot(identical(x$message, "File based keyring testingring has been created\n")) | ||
x <- tryCatch(REDCapExporter_keyring_check("testingring"), message = function(m) {m}) | ||
stopifnot(identical(x$message, "File based keyring testingring exists\n")) | ||
|
||
# Expect that this will error because we are not interactive and a password | ||
# prompt cannot be filled in | ||
x <- | ||
tryCatch( | ||
REDCapExporter_add_api_token(project = 'testingproject', keyring = 'testingring'), | ||
error = function(e) e | ||
) | ||
|
||
stopifnot(inherits(x, "error")) | ||
stopifnot(isTRUE(grepl("Aborted setting keyring key", x$message))) | ||
|
||
# expect the get api token to fail as the token for the testingproject has not | ||
# been set | ||
x <- | ||
tryCatch( | ||
REDCapExporter_get_api_token(project = 'testingproject', keyring = 'testingring'), | ||
error = function(e) e | ||
) | ||
|
||
stopifnot(inherits(x, "error")) | ||
stopifnot(isTRUE(grepl("specified item could not be found in the keychain", x$message))) | ||
|
||
# create token | ||
kr$set_with_value(service = "testingproject", password = "testingTOKEN", keyring = "testingring") | ||
|
||
|
||
# verify you can get the token | ||
stopifnot( | ||
identical( | ||
REDCapExporter_get_api_token(project = 'testingproject', keyring = 'testingring') | ||
, | ||
"testingTOKEN" | ||
)) | ||
|
||
|
||
# the REDCapExporter_add_api_token should return a message that the token | ||
# already exists | ||
#REDCapExporter_add_api_token(project = 'testingproject', keyring = 'testingring') | ||
|