Skip to content
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

Bringing 4.36 back up to the main/master branch #117

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: activityinfo
Type: Package
Title: R interface to ActivityInfo.org, an information management software for
humanitarian and development operations.
Version: 4.35
Version: 4.35.1
Date: 2023-05-25
Authors@R: c(
person("Alex", "Bertram", email = "[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

## [4.35.1]
- Fix for `getQuantityTable()` (#115)

## [4.35]
- addForm() now respects folderId argument (#93)
- Add "bulk_delete", "manage_translations", and "reviewer_only" arguments to permissions (#91)
Expand Down
4 changes: 2 additions & 2 deletions R/extractLong.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param folderId (optional) the id of the folder or form to include. If omitted, the whole database will be included in the export.
#' @param includeBlanks if TRUE, the export will include a row for quantity fields with blank values. Default is FALSE.
#' @return a single data.frame with quantity values in rows, and dimensions in columns.
#' @importFrom httr GET write_disk
#' @importFrom httr GET write_disk modify_url
#' @importFrom utils read.table
#' @export
getQuantityTable <- function(databaseId = NA, folderId, includeBlanks = FALSE) {
Expand All @@ -28,7 +28,7 @@ getQuantityTable <- function(databaseId = NA, folderId, includeBlanks = FALSE) {
))

tempFile <- tempfile()
downloadUrl <- paste(activityInfoRootUrl(), status$result$downloadUrl, sep="/")
downloadUrl <- modify_url(activityInfoRootUrl(), path=status$result$downloadUrl)

GET(downloadUrl, write_disk(tempFile, overwrite=TRUE), activityInfoAuthentication())

Expand Down
2 changes: 1 addition & 1 deletion R/formField.R
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ attachmentFieldSchema <- function(label, description = NULL, code = NULL, id = c
list(
typeParameters = list(
"cardinality" = "multiple",
"kind" = "attachment"
"captureMethods" = c("CAMERA", "FILE", "SIGNATURE")
)
)
)
Expand Down
64 changes: 6 additions & 58 deletions tests/testthat/_snaps/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,59 +67,6 @@
thirdPartyTranslation = FALSE, translationFromDbMemory = FALSE,
userId = "<id value>", version = "3"), class = "databaseTree")

---

structure(list(billingAccountId = "<id value>", continuousTranslation = FALSE,
databaseId = "<id value>", description = "", grants = list(),
label = "My first database", language = "", languages = list(),
locks = list(), originalLanguage = "", ownerRef = list(email = "<id value>",
id = "<id value>", name = "Bob"), publishedTemplate = FALSE,
resources = list("Empty resources until we can ensure a sort order in the API."),
role = list(id = "<id value>", parameters = list(), resources = list()),
roles = list(list(filters = list(), grantBased = FALSE, grants = list(),
id = "<id value>", label = "Data Entry", parameters = list(),
permissions = list(list(filter = NULL, operation = "VIEW",
securityCategories = list()), list(filter = NULL,
operation = "EDIT_RECORD", securityCategories = list()),
list(filter = NULL, operation = "ADD_RECORD", securityCategories = list()),
list(filter = NULL, operation = "DELETE_RECORD",
securityCategories = list()), list(filter = NULL,
operation = "EXPORT_RECORDS", securityCategories = list())),
version = 0), list(filters = list(), grantBased = FALSE,
grants = list(), id = "<id value>", label = "Read only",
parameters = list(), permissions = list(list(filter = NULL,
operation = "VIEW", securityCategories = list())),
version = 0), list(filters = list(), grantBased = FALSE,
grants = list(), id = "<id value>", label = "Administrator",
parameters = list(), permissions = list(list(filter = NULL,
operation = "VIEW", securityCategories = list()),
list(filter = NULL, operation = "ADD_RECORD", securityCategories = list()),
list(filter = NULL, operation = "EDIT_RECORD", securityCategories = "reviewer"),
list(filter = NULL, operation = "MANAGE_REFERENCE_DATA",
securityCategories = list()), list(filter = NULL,
operation = "DELETE_RECORD", securityCategories = list()),
list(filter = NULL, operation = "BULK_DELETE", securityCategories = list()),
list(filter = NULL, operation = "EXPORT_RECORDS",
securityCategories = list()), list(filter = NULL,
operation = "MANAGE_USERS", securityCategories = list()),
list(filter = NULL, operation = "LOCK_RECORDS", securityCategories = list()),
list(filter = NULL, operation = "ADD_RESOURCE", securityCategories = list()),
list(filter = NULL, operation = "EDIT_RESOURCE",
securityCategories = list()), list(filter = NULL,
operation = "DELETE_RESOURCE", securityCategories = list()),
list(filter = NULL, operation = "MANAGE_COLLECTION_LINKS",
securityCategories = list()), list(filter = NULL,
operation = "AUDIT", securityCategories = list()),
list(filter = NULL, operation = "SHARE_REPORTS",
securityCategories = list()), list(filter = NULL,
operation = "PUBLISH_REPORTS", securityCategories = list()),
list(filter = NULL, operation = "MANAGE_ROLES", securityCategories = list()),
list(filter = NULL, operation = "MANAGE_TRANSLATIONS",
securityCategories = list())), version = 0)),
securityCategories = list(list(id = "<id value>", label = "Reviewer only")),
storage = "", suspended = FALSE, thirdPartyTranslation = FALSE,
translationFromDbMemory = FALSE, userId = "<id value>", version = "3"), class = "databaseTree")

# getDatabaseResources() works

Code
Expand Down Expand Up @@ -152,9 +99,10 @@
email = "<id value>", inviteAccepted = FALSE, inviteDate = "<date or time value>",
name = "Test database user", role = list(id = "<id value>",
parameters = list(), resources = "Empty resources until we can ensure a sort order in the API."),
userId = "<id value>", version = 1), list(databaseId = "<id value>",
deliveryStatus = "UNKNOWN", email = "<id value>", inviteAccepted = FALSE,
inviteDate = "<date or time value>", name = "Test database user",
role = list(id = "<id value>", parameters = list(), resources = "Empty resources until we can ensure a sort order in the API."),
userId = "<id value>", version = 1))
userId = "<id value>", userLicenseType = "BASIC", version = 1L),
list(databaseId = "<id value>", deliveryStatus = "UNKNOWN",
email = "<id value>", inviteAccepted = FALSE, inviteDate = "<date or time value>",
name = "Test database user", role = list(id = "<id value>",
parameters = list(), resources = "Empty resources until we can ensure a sort order in the API."),
userId = "<id value>", userLicenseType = "BASIC", version = 1L))

3 changes: 1 addition & 2 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ canonicalizeActivityInfoObject <- function(tree, replaceId = TRUE, replaceDate =
if (identical(x, structure(list(), names = character(0)))) {
return(list())
}

if (is.list(x)) {
savedAttributes <- attributes(x)

Expand Down Expand Up @@ -74,7 +74,6 @@ canonicalizeActivityInfoObject <- function(tree, replaceId = TRUE, replaceDate =
})
}


x <- lapply(x, function(y) {
recursiveCanonicalize(y, path = paste(c(path, path), collapse = "."))
})
Expand Down
14 changes: 1 addition & 13 deletions tests/testthat/test-databases.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,7 @@ testthat::test_that("getDatabaseTree() works", {
testthat::expect_s3_class(tree, "databaseTree")
testthat::expect_named(tree, c("databaseId", "userId", "version", "label", "description", "ownerRef", "billingAccountId", "language", "originalLanguage", "continuousTranslation", "translationFromDbMemory", "thirdPartyTranslation", "languages", "role", "suspended", "storage", "publishedTemplate", "resources", "grants", "locks", "roles", "securityCategories"))
testthat::expect_identical(tree$databaseId, database$databaseId)
if(tree$roles[[1]]$grantBased){
expectActivityInfoSnapshot(tree)
testthat::expect_error({
expectActivityInfoSnapshot(tree)
})
}else{
testthat::expect_error({
expectActivityInfoSnapshot(tree)
})
expectActivityInfoSnapshot(tree)
}


expectActivityInfoSnapshot(tree)
})

testthat::test_that("getDatabaseResources() works", {
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-export.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
testthat::test_that("getQuantityTable() works", {
dbTest <- addDatabase("Reporting DB")
form <- addForm(formSchema(
dbTest$databaseId,
label = "Activities",
elements = list(textFieldSchema("Province", code = "PROVINCE", key = TRUE),
quantityFieldSchema("Nb of families", code = "FAM"),
quantityFieldSchema("Nb of clinics", code = "CLINICS"))))

addRecord(formId = form$id, fieldValues = list(PROVINCE = "North", FAM = 1012, CLINICS = 5))
addRecord(formId = form$id, fieldValues = list(PROVINCE = "South", FAM = 4445, CLINICS = 13))

quantityTable <- getQuantityTable(databaseId = dbTest$databaseId)
assertthat::assert_that(nrow(quantityTable) == 4)
})
6 changes: 3 additions & 3 deletions tests/testthat/test-formField.r
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ test_that("Test deleteFormField()", {
identicalForm(fmSchm %>% deleteFormField(label = c("Text field 1", "Text field 5")), fmSchm2)
})

test_that("Test roundtrip of attachmentFieldSchema()", {
testField(attachmentFieldSchema(label = "A attachment FieldSchema field"))
})
# test_that("Test roundtrip of attachmentFieldSchema()", {
# testField(attachmentFieldSchema(label = "A attachment FieldSchema field"))
# })

test_that("Barcode fields can be created and uploaded and downloaded and are identical", {
testField(barcodeFieldSchema(label = "A barcode field"))
Expand Down
Loading