Skip to content

Commit

Permalink
tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steffilazerte committed Sep 28, 2023
1 parent 42f2c61 commit b02f985
Showing 1 changed file with 55 additions and 61 deletions.
116 changes: 55 additions & 61 deletions tests/testthat/test_01_server.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

# srvXXX tests ---------------------------------------
test_that("srvXXX work as expected", {

skip_if_no_auth()

## srv meta ----------------------

# srvRecvMetadataForProjects
expect_silent(s <- srvRecvMetadataForProjects(projectIDs = 213)) %>%
expect_type("list")
Expand All @@ -15,7 +14,7 @@ test_that("srvXXX work as expected", {
expect_gt(nrow(s$antDeps), 0)
expect_gt(nrow(s$nodeDeps), 0)
expect_gt(nrow(s$projs), 0)

expect_silent(s <- srvRecvMetadataForProjects(projectIDs = NULL)) %>%
expect_type("list")
expect_named(s, c("recvDeps", "antDeps", "nodeDeps", "projs"))
Expand All @@ -24,7 +23,7 @@ test_that("srvXXX work as expected", {
expect_gt(nrow(s$antDeps), 0)
expect_gt(nrow(s$nodeDeps), 0)
expect_gt(nrow(s$projs), 0)

# srvMetadataForReceivers
d <- srvDeviceIDForReceiver("CTT-5031194D3168")$deviceID
expect_silent(meta_recv <- srvMetadataForReceivers(deviceIDs = d)) %>%
Expand All @@ -33,7 +32,7 @@ test_that("srvXXX work as expected", {
expect_gt(nrow(meta_recv$recvDeps), 0)
expect_gt(nrow(meta_recv$antDeps), 0)
expect_gt(nrow(meta_recv$projs), 0)

# srvMetadataForTags
expect_silent(s <- srvMetadataForTags(motusTagIDs = 29876)) %>%
expect_type("list")
Expand All @@ -43,130 +42,130 @@ test_that("srvXXX work as expected", {
expect_s3_class(s$tagProps, "data.frame") # might be empty
expect_gt(nrow(s$species), 0)
expect_gt(nrow(s$projs), 0)


## srvAuth --------------------
expect_silent(srvAuth()) %>%
expect_type("character")


## srv regular ----------------

# srvActivityForAll
expect_silent(s <- srvActivityForAll(batchID = 0, hourBin = 0)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

b <- s$batchID[1]

# srvActivityForBatches - From Project 4, non-deprecated
expect_silent(s <- srvActivityForBatches(batchID = b)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvAPIinfo
expect_silent(s <- srvAPIinfo()) %>%
expect_type("list")
expect_named(s, c("maxRows", "dataVersion", "currentPkgVersion"))
expect_gt(s$maxRows, 0)
expect_gt(s$dataVersion, 0)

# srvBatchesForReceiver - From Project 1 (SG-4002BBBK1580)
expect_silent(s <- srvBatchesForReceiver(deviceID = 217, batchID = 0)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

b217 <- s$batchID[s$numHits > 0][1]

# srvBatchesForTagProject
expect_silent(s <- srvBatchesForTagProject(projectID = 1, batchID = 0)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

b1 <- s$batchID[nrow(s)]

#srvBatchesForReceiverDeprecated
expect_silent(s <- srvBatchesForReceiverDeprecated(217)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

#srvBatchesForTagDeprecated
expect_silent(s <- srvBatchesForTagProjectDeprecated(1)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvDeviceIDForReceiver
expect_silent(s <- srvDeviceIDForReceiver(serno = "CTT-5031194D3168")) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvGPSForAll
expect_silent(s <- srvGPSForAll(gpsID = 0)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

b_gps <- s$batchID[1]

# srvGPSForReceiver - deviceID = 6115; CTT-5031194D3168
expect_silent(s <- srvGPSForReceiver(batchID = b_gps)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvGPSForTagProject - Not sure what's going on
#expect_silent(s <- srvGPSForTagProject(projectID = p, batchID = 0)) %>%
# expect_s3_class("data.frame")
#expect_gt(nrow(s), 0)

# srvHitsForReceiver
expect_silent(s <- srvHitsForReceiver(batchID = b217, hitID = 0)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvHitsForTagProject
expect_silent(s <- srvHitsForTagProject(projectID = 1, batchID = b1)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvNodes
expect_silent(s <- srvNodes(projectID = 207, batchID = 1019183)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvProjectAmbiguitiesForTagProject - *****************************
expect_silent(s <- srvProjectAmbiguitiesForTagProject(projectID = 176)) %>%
expect_s3_class("data.frame")
expect_equal(nrow(s), 0) ## WHAT IS THIS, EXACTLY?

# srvPulseCountsForReceiver - CTT-5031194D3168
# expect_silent(s <- srvPulseCountsForReceiver(batchID = 40570, ant = 0)) %>%
# expect_s3_class("data.frame")
# expect_gt(nrow(s), 0)

# srvReceiversForProject
# expect_silent(s <- srvReceiversForProject(projectID = 204)) %>%
# expect_s3_class("data.frame")
# expect_gt(nrow(s), 0)

# srvRunsForReceiver - CTT-5031194D3168
# expect_silent(s <- srvRunsForReceiver(batchID = 1582469, runID = 0)) %>%
# expect_s3_class("data.frame")
# expect_gt(nrow(s), 0)

# srvRunsForTagProject
expect_silent(s <- srvRunsForTagProject(projectID = 4, batchID = 120474)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvSizeOfUpdateForReceiver
expect_silent(s <- srvSizeOfUpdateForReceiver(deviceID = 217, batchID = 0)) %>%
expect_s3_class("data.frame")
expect_gt(nrow(s), 0)

# srvSizeOfUpdateForTagProject
# expect_silent(s <- srvSizeOfUpdateForTagProject(projectID = 204, batchID = 0)) %>%
# expect_s3_class("data.frame")
# expect_gt(nrow(s), 0)

# srvTagMetadataForProjects
expect_silent(s <- srvTagMetadataForProjects(projectIDs = 25)) %>%
expect_type("list")
Expand All @@ -176,7 +175,7 @@ test_that("srvXXX work as expected", {
#expect_gt(nrow(s$tagProps), 0)
expect_gt(nrow(s$species), 0)
expect_gt(nrow(s$projs), 0)

expect_silent(s <- srvTagMetadataForProjects(projectIDs = NULL)) %>%
expect_type("list")
expect_gt(nrow(s$tags), 0)
Expand All @@ -185,7 +184,7 @@ test_that("srvXXX work as expected", {
expect_gt(nrow(s$tagProps), 0)
expect_gt(nrow(s$species), 0)
expect_gt(nrow(s$projs), 0)

# srvTagsForAmbiguities
expect_silent(s <- srvTagsForAmbiguities(ambigIDs = -56)) %>%
expect_s3_class("data.frame")
Expand All @@ -198,25 +197,26 @@ test_that("srvXXX work as expected", {
test_that("tagme() errors appropriately", {
skip_on_cran()
sample_auth()

withr::local_file("project-10.motus")
withr::local_file("CTT-5031194D3168.motus")
expect_error(expect_message(tagme(projRecv = 10, new = TRUE, update = TRUE),
"updateMotusDb"),
"You do not have permission")

expect_error(expect_message(tagme(projRecv = "CTT-5031194D3168",
new = TRUE, update = TRUE),
"updateMotusDb"),
"Either") #...
expect_error(expect_message(
withr::local_db_connection(tagme(projRecv = 10, new = TRUE, update = TRUE)),
"updateMotusDb"),
"You do not have permission")

expect_error(expect_message(
withr::local_db_connection(tagme(projRecv = "CTT-5031194D3168",
new = TRUE, update = TRUE)),
"updateMotusDb"),
"Either") #...
})


# Projects downloads ---------------------------------------
test_that("tagme() downloads data - Projects", {
test_that("Proj - tagme() downloads data - Projects", {
skip_on_cran()
sample_auth()

withr::local_file("project-176.motus")
expect_message(tags <- withr::local_db_connection(
tagme(projRecv = 176, new = TRUE, update = TRUE))) %>%
Expand All @@ -225,11 +225,10 @@ test_that("tagme() downloads data - Projects", {
})


# Receivers download ------------------------------------------------------
test_that("tagme() downloads data - Receivers", {
test_that("Recv - tagme() downloads data - Receivers", {
skip_on_cran()
skip_if_no_auth()

withr::local_file("SG-3115BBBK1127.motus")
expect_message(tags <- withr::local_db_connection(
tagme("SG-3115BBBK1127", new = TRUE, update = TRUE))) %>%
Expand All @@ -238,8 +237,7 @@ test_that("tagme() downloads data - Receivers", {
})


# Projects countOnly = TRUE ---------------------------------------------------
test_that("tagme with countOnly (tellme) - Projects", {
test_that("Proj - tagme() with countOnly (tellme) - Projects", {
skip_on_cran()
sample_auth()
withr::local_file("project-176.motus")
Expand All @@ -252,8 +250,8 @@ test_that("tagme with countOnly (tellme) - Projects", {
expect_s3_class("data.frame")
})

# Receivers countOnly = TRUE ---------------------------------------------------
test_that("tagme with countOnly (tellme) - Receivers", {

test_that("Recv - tagme() with countOnly (tellme) - Receivers", {
skip_on_cran()
skip_if_no_auth()

Expand All @@ -263,7 +261,6 @@ test_that("tagme with countOnly (tellme) - Receivers", {
})


# Timeouts ----------------------------------------------------------------
test_that("srvQuery handles time out graciously", {

sample_auth()
Expand All @@ -278,7 +275,6 @@ test_that("srvQuery handles time out graciously", {
})


# srvAuth errors ----------------------------------------------------------
test_that("srvAuth handles errors informatively", {
expect_message(motusLogout())
sessionVariable(name = "userLogin", val = "motus.samp")
Expand All @@ -299,8 +295,6 @@ test_that("metadata()", {
suppressMessages()
})

# srvAuth package version --------------------------------------------------

test_that("srvAuth errors/warns/passes on package version", {
sample_auth()
expect_silent(srvAuth())
Expand Down

0 comments on commit b02f985

Please sign in to comment.