Skip to content

Commit

Permalink
respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
toph-allen committed Nov 8, 2024
1 parent 64a57cd commit f4ab09d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
5 changes: 4 additions & 1 deletion R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ get_users <- function(src, page_size = 500, prefix = NULL, limit = Inf) {
get_groups <- function(src, page_size = 500, prefix = NULL, limit = Inf) {
validate_R6_class(src, "Connect")

# The `v1/groups` endpoint always returns the first page when `prefix` is
# specified, so the page_offset function, which increments until it hits an
# empty page, fails.
if (!is.null(prefix)) {
response <- src$groups(page_size = page_size, prefix = prefix)
res <- response$results
} else {
res <- page_offset(src, src$groups(page_size = page_size, prefix = prefix), limit = limit)
res <- page_offset(src, src$groups(page_size = page_size, prefix = NULL), limit = limit)
}

out <- parse_connectapi_typed(res, connectapi_ptypes$groups)
Expand Down
33 changes: 33 additions & 0 deletions tests/testthat/2024.08.0/__api__/v1/groups-125d47.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// get_groups(client, page_size = 5, limit = 10)
// used in test-get.R
{
"results": [
{
"guid": "54ed1e9d",
"name": "~!@#$%^&*()_+",
"owner_guid": "6ca57cef"
},
{
"guid": "bdba3381",
"name": "1111",
"owner_guid": "434f97ab"
},
{
"guid": "bd3f6262",
"name": "2_viewer_group",
"owner_guid": "0fc96747"
},
{
"guid": "88777348",
"name": "amanda_test_group",
"owner_guid": "f7e346b4"
},
{
"guid": "3d6971cd",
"name": "a_new_group",
"owner_guid": "3be5e66d"
}
],
"current_page": 1,
"total": 67
}
33 changes: 33 additions & 0 deletions tests/testthat/2024.08.0/__api__/v1/groups-4eaf46.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// get_groups(client, page_size = 5, limit = 10)
// used in test-get.R
{
"results": [
{
"guid": "129334f1",
"name": "azurepipelines",
"owner_guid": "0fc96747"
},
{
"guid": "b72c488e",
"name": "cgGroup01",
"owner_guid": "fd9158a2"
},
{
"guid": "567c9bd7",
"name": "chris_test_group",
"owner_guid": "6634098f"
},
{
"guid": "a6fb5cea",
"name": "connect_dev",
"owner_guid": "1a7a5703"
},
{
"guid": "68bad75b",
"name": "cool_kids_of_the_dmv",
"owner_guid": "1270410b"
}
],
"current_page": 2,
"total": 67
}
18 changes: 18 additions & 0 deletions tests/testthat/2024.08.0/__api__/v1/groups-deae1f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// get_groups(client, page_size = 2, prefix = "c")
// used in test-get.R
{
"results": [
{
"guid": "a6fb5cea",
"name": "connect_dev",
"owner_guid": "1a7a5703"
},
{
"guid": "68bad75b",
"name": "cool_kids_of_the_dmv",
"owner_guid": "1270410b"
}
],
"current_page": 1,
"total": 2
}
24 changes: 24 additions & 0 deletions tests/testthat/test-get.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,27 @@ test_that("get_runtimes() restricts available runtimes based on Connect version.
'`runtimes` must be one of "r", "python"; received: "r", "quarto".'
)
})

with_mock_api({
client <- connect(server = "https://connect.example", api_key = "fake")
test_that("get_groups() paginates with no prefix", {
# To get this result, the code has to paginate through two API requests.
# groups-4eaf46.json
# groups-125d47.json

result <- get_groups(client, page_size = 5, limit = 10)
expected_names <- c("~!@#$%^&*()_+", "1111", "2_viewer_group", "amanda_test_group",
"a_new_group", "azurepipelines", "cgGroup01", "chris_test_group",

Check warning on line 127 in tests/testthat/test-get.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-get.R,line=127,col=6,[indentation_linter] Hanging indent should be 24 spaces but is 6 spaces.
"connect_dev", "cool_kids_of_the_dmv")
expect_identical(result$name, expected_names)
})

test_that("get_groups() does not paginate when called with a prefix", {
# Only one response exists for this query; by succeeding this test verifies
# that the pagination behavior is not engaged.
# groups-deae1f.json

result <- get_groups(client, page_size = 2, prefix = "c")
expect_identical(result$name, c("connect_dev", "cool_kids_of_the_dmv"))
})
})

0 comments on commit f4ab09d

Please sign in to comment.