- Notifications
You must be signed in to change notification settings - Fork85
Open
Description
The Connect client object is not tested.
There was an old test that was labeled "Users API" but tested the entire Connect object workflow. It was deleted in#1183 and is pasted below. Perhaps using this as a starting point makes sense.
test_that("Users API", { skip_on_cran() skip_on_os("windows") skip("connect user test skipped.")## rm db/*.dbserver<- serverInfo(findServer())connect<- connectClient(server$url,list())id<- paste(as.hexmode(sample(256,bytes)-1),collapse="")# add a userrecord<- userRecord(email= paste0("user",id,"@gmail.com"),username= paste0("user",id),first_name="User",last_name="Resu",password= paste0("password",id) )response<-connect$addUser(record)# check a couple main fields expect_equal(response[c("email","first_name","last_name","username")],list(email=record$email,first_name=record$first_name,last_name=record$last_name,username=record$username ) )# make sure we returned an empty password field (or no password field?) expect_true(response$password%in%""|| is.null(response$password))# generate a tokenaccountId<-response$idtoken<- generateToken()tokenResponse<-connect$addToken(list(token=token$token,public_key=token$public_key,user_id=accountId )) Sys.sleep(1)# open the URL in the browserutils::browseURL(tokenResponse$token_claim_url)# Sleep for a second so we can be sure that automatic auth happened Sys.sleep(2)# finally, create a fully authenticated client using the new token, and# keep trying to authenticate until we're successfulconnect<- connectClient(service=server$url,authInfo=list(token=token$token,private_key=token$private_key) )repeat { tryCatch( {user<-connect$currentUser()break },error=function(e,...) {# we expect this to return unauthorized until the token becomes active,# but bubble other errorsif (length(grep("401 - Unauthorized",e$message))==0) { stop(e) } Sys.sleep(1) } ) }# Create and remove an example application## Create itsplineReticulator<-connect$createApplication("SplineReticulator")# Update the account id (since we have moved from unauthed user# to authed user)accountId<-splineReticulator$user_id## Confirm it existsapps<-connect$listApplications(accountId)app<-apps[[which(sapply(apps,`[[`,"id")==splineReticulator$id)]] expect_true(app$name=="SplineReticulator")## Upload a bundlepwd_splat<- strsplit(getwd(),"/")[[1]]if (pwd_splat[length(pwd_splat)]=="rsconnect") {path<-"tests/testthat/test-shinyApp/test-shinyApp.tar.gz" }else {path<-"test-shinyApp/test-shinyApp.tar.gz" }response<-connect$uploadApplication(splineReticulator$id, normalizePath(path=path) )## Deploy an applicationappId<-response$app_idresponse<-connect$deployApplication(list(id=appId))id<-response$id## Query the app for success / failureresponse<-connect$waitForTask(id)## Terminate the application (does not remove it from store)connect$terminateApplication(appId)apps<-connect$listApplications(accountId) expect_false(response$id%in% sapply(apps,"[[","id"))})
Metadata
Metadata
Assignees
Labels
No labels