From 6218021defd79c094799739197b646058cd5cd3e Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Mon, 31 May 2021 18:04:06 +0530 Subject: [PATCH 1/8] Incresed Code Coverage --- DESCRIPTION | 3 +- NAMESPACE | 1 + R/api.R | 1 + tests/fixtures/check_api_version.yml | 33 ++++++++++++ tests/fixtures/check_authentication.yml | 39 ++++++++++++++ tests/fixtures/check_last_audit.yml | 35 ++++++++++++ tests/fixtures/create_bugzilla_key.yml | 71 +++++++++++++++++++++++++ tests/fixtures/valid_key.yml | 1 + tests/testthat/setup-bugRzilla.R | 59 ++++++++++++++++++++ 9 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/check_api_version.yml create mode 100644 tests/fixtures/check_authentication.yml create mode 100644 tests/fixtures/check_last_audit.yml create mode 100644 tests/fixtures/create_bugzilla_key.yml create mode 100644 tests/fixtures/valid_key.yml diff --git a/DESCRIPTION b/DESCRIPTION index ca85fd9..e09841e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,8 @@ Imports: httr, methods, utils, - tools + tools, + httptest Suggests: covr, knitr, diff --git a/NAMESPACE b/NAMESPACE index 8fb5035..c05d995 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,7 @@ export(get_history) export(post_bug) export(post_comment) export(set_key) +import(httptest) importFrom(cli,cat_rule) importFrom(cli,cli_alert) importFrom(cli,cli_alert_danger) diff --git a/R/api.R b/R/api.R index 800fb98..5795bca 100644 --- a/R/api.R +++ b/R/api.R @@ -17,6 +17,7 @@ missing_key <- function(key) { #' @importFrom cli cli_ul #' @importFrom utils browseURL #' @export +#' @import httptest create_bugzilla_key <- function(host) { host <- missing_host(host) url <- paste0(host, "userprefs.cgi?tab=apikey") diff --git a/tests/fixtures/check_api_version.yml b/tests/fixtures/check_api_version.yml new file mode 100644 index 0000000..f34166b --- /dev/null +++ b/tests/fixtures/check_api_version.yml @@ -0,0 +1,33 @@ +http_interactions: +- request: + method: get + uri: https://bugs.r-project.org/bugzilla/rest/version + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + date: Mon, 31 May 2021 03:18:02 GMT + server: gazelle + etag: eTsYwUQ9/dEzCleTaxjJ5A + content-length: '20' + content-type: application/json; charset=UTF-8 + access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, + x-bugzilla-api-key, x-bugzilla-password, x-bugzilla-token, x-bugzilla-login + access-control-allow-origin: '*' + x-content-type-options: nosniff + x-frame-options: SAMEORIGIN + x-xss-protection: 1; mode=block + body: + encoding: UTF-8 + file: no + string: '{"version":"5.1.2+"}' + recorded_at: 2021-05-31 03:18:02 GMT + recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/check_authentication.yml b/tests/fixtures/check_authentication.yml new file mode 100644 index 0000000..ef8177e --- /dev/null +++ b/tests/fixtures/check_authentication.yml @@ -0,0 +1,39 @@ +http_interactions: +- request: + method: get + uri: https://bugs.r-project.org/bugzilla/rest/whoami + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + X-BUGZILLA-API-KEY: https://bugs.r-project.org/bugzilla/ + User-agent: https://github.com/llrs/bugRzilla/ + response: + status: + status_code: 400 + category: Client error + reason: Bad Request + message: 'Client error: (400) Bad Request' + headers: + date: Mon, 31 May 2021 03:18:01 GMT + server: gazelle + etag: QoEOn1fkyvtzNJvFp167rw + content-length: '185' + content-type: application/json; charset=UTF-8 + access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, + x-bugzilla-login, x-bugzilla-token, x-bugzilla-password, x-bugzilla-api-key + access-control-allow-origin: '*' + x-content-type-options: nosniff + x-frame-options: SAMEORIGIN + x-xss-protection: 1; mode=block + set-cookie: Bugzilla_login_request_cookie=MGh4nMQZ13; domain=bugs.r-project.org; + path=/bugzilla/; secure; HttpOnly + connection: close + body: + encoding: UTF-8 + file: no + string: '{"code":"306","error":true,"message":"The API key you specified is + invalid. Please check that you typed it correctly.","documentation":"https://bugzilla.readthedocs.org/en/latest/api/"}' + recorded_at: 2021-05-31 03:18:00 GMT + recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/check_last_audit.yml b/tests/fixtures/check_last_audit.yml new file mode 100644 index 0000000..358ca0f --- /dev/null +++ b/tests/fixtures/check_last_audit.yml @@ -0,0 +1,35 @@ +http_interactions: +- request: + method: get + uri: https://bugs.r-project.org/bugzilla/rest/last_audit_time + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + date: Mon, 31 May 2021 03:04:29 GMT + server: gazelle + etag: GIrwjX1k17GX4FOvl+NcVA + content-length: '42' + content-type: application/json; charset=UTF-8 + access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, + x-bugzilla-login, x-bugzilla-password, x-bugzilla-token, x-bugzilla-api-key + access-control-allow-origin: '*' + x-content-type-options: nosniff + x-frame-options: SAMEORIGIN + x-xss-protection: 1; mode=block + set-cookie: Bugzilla_login_request_cookie=l0ZOvJZzmk; domain=bugs.r-project.org; + path=/bugzilla/; secure; HttpOnly + body: + encoding: UTF-8 + file: no + string: '{"last_audit_time":"2021-05-27T01:19:10Z"}' + recorded_at: 2021-05-31 03:04:28 GMT + recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/create_bugzilla_key.yml b/tests/fixtures/create_bugzilla_key.yml new file mode 100644 index 0000000..5d53183 --- /dev/null +++ b/tests/fixtures/create_bugzilla_key.yml @@ -0,0 +1,71 @@ +http_interactions: +- request: + method: get + uri: https://bugs.r-project.org/bugzilla/rest/version + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + date: Sun, 30 May 2021 22:29:14 GMT + server: gazelle + etag: eTsYwUQ9/dEzCleTaxjJ5A + content-length: '20' + content-type: application/json; charset=UTF-8 + access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, + x-bugzilla-login, x-bugzilla-token, x-bugzilla-password, x-bugzilla-api-key + access-control-allow-origin: '*' + x-content-type-options: nosniff + x-frame-options: SAMEORIGIN + x-xss-protection: 1; mode=block + set-cookie: Bugzilla_login_request_cookie=bkWtzcH9Y2; domain=bugs.r-project.org; + path=/bugzilla/; secure; HttpOnly + body: + encoding: UTF-8 + file: no + string: '{"version":"5.1.2+"}' + recorded_at: 2021-05-30 22:29:15 GMT + recorded_with: vcr/0.6.0, webmockr/0.8.0 +- request: + method: get + uri: https://bugs.r-project.org/bugzilla/rest/whoami + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + X-BUGZILLA-API-KEY: foobar + User-agent: https://github.com/llrs/bugRzilla/ + response: + status: + status_code: 400 + category: Client error + reason: Bad Request + message: 'Client error: (400) Bad Request' + headers: + date: Sun, 30 May 2021 22:29:14 GMT + server: gazelle + etag: QoEOn1fkyvtzNJvFp167rw + content-length: '185' + content-type: application/json; charset=UTF-8 + access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, + x-bugzilla-api-key, x-bugzilla-password, x-bugzilla-token, x-bugzilla-login + access-control-allow-origin: '*' + x-content-type-options: nosniff + x-frame-options: SAMEORIGIN + x-xss-protection: 1; mode=block + connection: close + body: + encoding: UTF-8 + file: no + string: '{"documentation":"https://bugzilla.readthedocs.org/en/latest/api/","message":"The + API key you specified is invalid. Please check that you typed it correctly.","error":true,"code":"306"}' + recorded_at: 2021-05-30 22:29:15 GMT + recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/valid_key.yml b/tests/fixtures/valid_key.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/fixtures/valid_key.yml @@ -0,0 +1 @@ + diff --git a/tests/testthat/setup-bugRzilla.R b/tests/testthat/setup-bugRzilla.R index e56a6b7..a48750b 100644 --- a/tests/testthat/setup-bugRzilla.R +++ b/tests/testthat/setup-bugRzilla.R @@ -1,4 +1,5 @@ library("vcr") # *Required* as vcr is set up on loading +library("httptest") vcr_dir <- vcr::vcr_test_path("fixtures") if (!nzchar(Sys.getenv("R_BUGZILLA"))) { @@ -12,6 +13,52 @@ if (!nzchar(Sys.getenv("R_BUGZILLA"))) { use_key() +test_that("create_bugzilla_key works", { + vcr::use_cassette("create_bugzilla_key", { + host <- "https://bugs.r-project.org/bugzilla/" + cbk <- create_bugzilla_key(host) + }) + expect_equal(a <- paste0(host, "userprefs.cgi?tab=apikey"), url) + cli::test_that_cli("cli_alert_warning works", { + expect_snapshot({ + cli::cli_alert_warning("This package hasn't been tested with this Bugzilla version.") + }) + }) +}) + + +test_that("check_authentication works", { + vcr::use_cassette("check_authentication", { + ca <- check_authentication(host) + }) + expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/") + cli::test_that_cli("cli_alert_danger",{ + expect_snapshot({ + cli::cli_alert_danger("Not authenticated on this site.") + cli::cli_alert_success("Authenticated on this site!") + }) + }) +}) + +test_that("check_api_version works", { + vcr::use_cassette("check_api_version", { + cav <- check_api_version(host) + }) + expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/") +}) + + +test_that("check_last_audit works", { + vcr::use_cassette("check_last_audit", { + product <- "R" + cla <- check_last_audit(product, host) + }) + expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/") + httptest::expect_GET(paste0(host, "rest/last_audit_time"), "https://bugs.r-project.org/bugzilla/rest/last_audit_time") + expect_equal(missing_product(product), "R") +}) + + invisible(vcr::vcr_configure( dir = vcr_dir, filter_request_headers = list( @@ -19,3 +66,15 @@ invisible(vcr::vcr_configure( "X-BUGZILLA-API-KEY" = "Removing this header too just in case") )) vcr::check_cassette_names() + + +test_that("valid_key works", { + use_cassette("valid_key", { + vk <- valid_key("R_BUGZILLA") + }) + cli::test_that_cli("cli_alert_danger", { + expect_snapshot({ + cli::cli_alert_danger("Key not valid or not set.") + }) + }) +}) From 2380373b87684ad79e748b8818d7cc91b6936ac8 Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Thu, 3 Jun 2021 18:11:43 +0530 Subject: [PATCH 2/8] Increased Code Coverage --- DESCRIPTION | 4 +- NAMESPACE | 1 - R/api.R | 1 - tests/fixtures/set_key.yml | 1 + tests/testthat/_snaps/api.md | 104 +++++++++++++++++++++++++++++++ tests/testthat/setup-bugRzilla.R | 64 +------------------ tests/testthat/test-api.R | 59 ++++++++++++++++++ 7 files changed, 169 insertions(+), 65 deletions(-) create mode 100644 tests/fixtures/set_key.yml create mode 100644 tests/testthat/_snaps/api.md create mode 100644 tests/testthat/test-api.R diff --git a/DESCRIPTION b/DESCRIPTION index e09841e..e7615a4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,14 +17,14 @@ Imports: httr, methods, utils, - tools, - httptest + tools Suggests: covr, knitr, reprex, rmarkdown, testthat (>= 3.0.0), + httptest, vcr VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index c05d995..8fb5035 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,7 +12,6 @@ export(get_history) export(post_bug) export(post_comment) export(set_key) -import(httptest) importFrom(cli,cat_rule) importFrom(cli,cli_alert) importFrom(cli,cli_alert_danger) diff --git a/R/api.R b/R/api.R index 5795bca..800fb98 100644 --- a/R/api.R +++ b/R/api.R @@ -17,7 +17,6 @@ missing_key <- function(key) { #' @importFrom cli cli_ul #' @importFrom utils browseURL #' @export -#' @import httptest create_bugzilla_key <- function(host) { host <- missing_host(host) url <- paste0(host, "userprefs.cgi?tab=apikey") diff --git a/tests/fixtures/set_key.yml b/tests/fixtures/set_key.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/fixtures/set_key.yml @@ -0,0 +1 @@ + diff --git a/tests/testthat/_snaps/api.md b/tests/testthat/_snaps/api.md new file mode 100644 index 0000000..cf26cfe --- /dev/null +++ b/tests/testthat/_snaps/api.md @@ -0,0 +1,104 @@ +# cli_alert_warning works [plain] + + Code + cli::cli_alert_warning( + "This package hasn't been tested with this Bugzilla version.") + Message + ! This package hasn't been tested with this Bugzilla version. + +# cli_alert_warning works [ansi] + + Code + cli::cli_alert_warning( + "This package hasn't been tested with this Bugzilla version.") + Message + ! This package hasn't been tested with this Bugzilla version. + +# cli_alert_warning works [unicode] + + Code + cli::cli_alert_warning( + "This package hasn't been tested with this Bugzilla version.") + Message + ! This package hasn't been tested with this Bugzilla version. + +# cli_alert_warning works [fancy] + + Code + cli::cli_alert_warning( + "This package hasn't been tested with this Bugzilla version.") + Message + ! This package hasn't been tested with this Bugzilla version. + +# cli_alert_danger [plain] + + Code + cli::cli_alert_danger("Not authenticated on this site.") + Message + x Not authenticated on this site. + Code + cli::cli_alert_success("Authenticated on this site!") + Message + v Authenticated on this site! + +# cli_alert_danger [ansi] + + Code + cli::cli_alert_danger("Not authenticated on this site.") + Message + x Not authenticated on this site. + Code + cli::cli_alert_success("Authenticated on this site!") + Message + v Authenticated on this site! + +# cli_alert_danger [unicode] + + Code + cli::cli_alert_danger("Not authenticated on this site.") + Message + ✖ Not authenticated on this site. + Code + cli::cli_alert_success("Authenticated on this site!") + Message + ✔ Authenticated on this site! + +# cli_alert_danger [fancy] + + Code + cli::cli_alert_danger("Not authenticated on this site.") + Message + ✖ Not authenticated on this site. + Code + cli::cli_alert_success("Authenticated on this site!") + Message + ✔ Authenticated on this site! + +# cli_alert_dangers [plain] + + Code + cli::cli_alert_danger("Key not valid or not set.") + Message + x Key not valid or not set. + +# cli_alert_dangers [ansi] + + Code + cli::cli_alert_danger("Key not valid or not set.") + Message + x Key not valid or not set. + +# cli_alert_dangers [unicode] + + Code + cli::cli_alert_danger("Key not valid or not set.") + Message + ✖ Key not valid or not set. + +# cli_alert_dangers [fancy] + + Code + cli::cli_alert_danger("Key not valid or not set.") + Message + ✖ Key not valid or not set. + diff --git a/tests/testthat/setup-bugRzilla.R b/tests/testthat/setup-bugRzilla.R index a48750b..4c9e171 100644 --- a/tests/testthat/setup-bugRzilla.R +++ b/tests/testthat/setup-bugRzilla.R @@ -1,5 +1,5 @@ library("vcr") # *Required* as vcr is set up on loading -library("httptest") +library("httptest") # *Required* as hhtptest is set up on loading vcr_dir <- vcr::vcr_test_path("fixtures") if (!nzchar(Sys.getenv("R_BUGZILLA"))) { @@ -13,68 +13,10 @@ if (!nzchar(Sys.getenv("R_BUGZILLA"))) { use_key() -test_that("create_bugzilla_key works", { - vcr::use_cassette("create_bugzilla_key", { - host <- "https://bugs.r-project.org/bugzilla/" - cbk <- create_bugzilla_key(host) - }) - expect_equal(a <- paste0(host, "userprefs.cgi?tab=apikey"), url) - cli::test_that_cli("cli_alert_warning works", { - expect_snapshot({ - cli::cli_alert_warning("This package hasn't been tested with this Bugzilla version.") - }) - }) -}) - - -test_that("check_authentication works", { - vcr::use_cassette("check_authentication", { - ca <- check_authentication(host) - }) - expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/") - cli::test_that_cli("cli_alert_danger",{ - expect_snapshot({ - cli::cli_alert_danger("Not authenticated on this site.") - cli::cli_alert_success("Authenticated on this site!") - }) - }) -}) - -test_that("check_api_version works", { - vcr::use_cassette("check_api_version", { - cav <- check_api_version(host) - }) - expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/") -}) - - -test_that("check_last_audit works", { - vcr::use_cassette("check_last_audit", { - product <- "R" - cla <- check_last_audit(product, host) - }) - expect_equal(missing_host(host), "https://bugs.r-project.org/bugzilla/") - httptest::expect_GET(paste0(host, "rest/last_audit_time"), "https://bugs.r-project.org/bugzilla/rest/last_audit_time") - expect_equal(missing_product(product), "R") -}) - - invisible(vcr::vcr_configure( dir = vcr_dir, filter_request_headers = list( - "Authorization" = "My bearer token is safe", - "X-BUGZILLA-API-KEY" = "Removing this header too just in case") + "Authorization" = "My bearer token is safe", + "X-BUGZILLA-API-KEY" = "Removing this header too just in case") )) vcr::check_cassette_names() - - -test_that("valid_key works", { - use_cassette("valid_key", { - vk <- valid_key("R_BUGZILLA") - }) - cli::test_that_cli("cli_alert_danger", { - expect_snapshot({ - cli::cli_alert_danger("Key not valid or not set.") - }) - }) -}) diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R new file mode 100644 index 0000000..0d2ac24 --- /dev/null +++ b/tests/testthat/test-api.R @@ -0,0 +1,59 @@ +test_that("create_bugzilla_key works", { + vcr::use_cassette("create_bugzilla_key", { + cbk <- create_bugzilla_key(missing_host()) + url <- "https://bugs.r-project.org/bugzilla/userprefs.cgi?tab=apikey" + }) + expect_equal(paste0(missing_host(), "userprefs.cgi?tab=apikey"), url) + expect_condition() + cli::test_that_cli("cli_alert_warning works", { + expect_snapshot({ + cli::cli_alert_warning("This package hasn't been tested with this Bugzilla version.") + }) + }) +}) + + +test_that("check_authentication works", { + vcr::use_cassette("check_authentication", { + ca <- check_authentication(missing_host()) + }) + expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") + cli::test_that_cli("cli_alert_danger",{ + expect_snapshot({ + cli::cli_alert_danger("Not authenticated on this site.") + cli::cli_alert_success("Authenticated on this site!") + }) + }) +}) + + +test_that("check_api_version works", { + vcr::use_cassette("check_api_version", { + cav <- check_api_version(missing_host()) + }) + expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") +}) + + +test_that("check_last_audit works", { + vcr::use_cassette("check_last_audit", { + cla <- check_last_audit(missing_product(), missing_host()) + }) + expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") + expect_equal(missing_product(), "R") + expect_s3_class(GET(paste0(missing_host(), "rest/last_audit_time")), "response") +}) + + +test_that("valid_key works", { + use_cassette("valid_key", { + vk <- valid_key(use_key()) + }) + cli::test_that_cli("cli_alert_dangers", { + expect_snapshot({ + cli::cli_alert_danger("Key not valid or not set.") + }) + }) +}) + +snapshot_accept('R/api.R') From 023bd3df4e727f32b73e067b7ff04750bc45d72d Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Tue, 8 Jun 2021 18:50:17 +0530 Subject: [PATCH 3/8] PR updates --- tests/fixtures/create_bugzilla_key.yml | 23 +++++----- tests/fixtures/params.yml | 1 + tests/testthat/_snaps/api.md | 38 +++++++++++------ tests/testthat/setup-bugRzilla.R | 1 - tests/testthat/test-api.R | 58 ++++++++++++++++++++++---- tests/testthat/test-bug_search.R | 23 ++++++++++ 6 files changed, 114 insertions(+), 30 deletions(-) create mode 100644 tests/fixtures/params.yml create mode 100644 tests/testthat/test-bug_search.R diff --git a/tests/fixtures/create_bugzilla_key.yml b/tests/fixtures/create_bugzilla_key.yml index 5d53183..c5a677d 100644 --- a/tests/fixtures/create_bugzilla_key.yml +++ b/tests/fixtures/create_bugzilla_key.yml @@ -7,6 +7,8 @@ http_interactions: string: '' headers: Accept: application/json, text/xml, application/xml, */* + Authorization: My bearer token is safe + X-BUGZILLA-API-KEY: Removing this header too just in case response: status: status_code: 200 @@ -14,24 +16,24 @@ http_interactions: reason: OK message: 'Success: (200) OK' headers: - date: Sun, 30 May 2021 22:29:14 GMT + date: Sat, 05 Jun 2021 21:04:49 GMT server: gazelle etag: eTsYwUQ9/dEzCleTaxjJ5A content-length: '20' content-type: application/json; charset=UTF-8 access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, - x-bugzilla-login, x-bugzilla-token, x-bugzilla-password, x-bugzilla-api-key + x-bugzilla-password, x-bugzilla-token, x-bugzilla-login, x-bugzilla-api-key access-control-allow-origin: '*' x-content-type-options: nosniff x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block - set-cookie: Bugzilla_login_request_cookie=bkWtzcH9Y2; domain=bugs.r-project.org; + set-cookie: Bugzilla_login_request_cookie=nG2w3negvv; domain=bugs.r-project.org; path=/bugzilla/; secure; HttpOnly body: encoding: UTF-8 file: no string: '{"version":"5.1.2+"}' - recorded_at: 2021-05-30 22:29:15 GMT + recorded_at: 2021-06-05 21:04:49 GMT recorded_with: vcr/0.6.0, webmockr/0.8.0 - request: method: get @@ -41,8 +43,9 @@ http_interactions: string: '' headers: Accept: application/json, text/xml, application/xml, */* - X-BUGZILLA-API-KEY: foobar + X-BUGZILLA-API-KEY: Removing this header too just in case User-agent: https://github.com/llrs/bugRzilla/ + Authorization: My bearer token is safe response: status: status_code: 400 @@ -50,13 +53,13 @@ http_interactions: reason: Bad Request message: 'Client error: (400) Bad Request' headers: - date: Sun, 30 May 2021 22:29:14 GMT + date: Sat, 05 Jun 2021 21:04:49 GMT server: gazelle etag: QoEOn1fkyvtzNJvFp167rw content-length: '185' content-type: application/json; charset=UTF-8 access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, - x-bugzilla-api-key, x-bugzilla-password, x-bugzilla-token, x-bugzilla-login + x-bugzilla-api-key, x-bugzilla-login, x-bugzilla-password, x-bugzilla-token access-control-allow-origin: '*' x-content-type-options: nosniff x-frame-options: SAMEORIGIN @@ -65,7 +68,7 @@ http_interactions: body: encoding: UTF-8 file: no - string: '{"documentation":"https://bugzilla.readthedocs.org/en/latest/api/","message":"The - API key you specified is invalid. Please check that you typed it correctly.","error":true,"code":"306"}' - recorded_at: 2021-05-30 22:29:15 GMT + string: '{"code":"306","message":"The API key you specified is invalid. Please + check that you typed it correctly.","error":true,"documentation":"https://bugzilla.readthedocs.org/en/latest/api/"}' + recorded_at: 2021-06-05 21:04:49 GMT recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/params.yml b/tests/fixtures/params.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/fixtures/params.yml @@ -0,0 +1 @@ + diff --git a/tests/testthat/_snaps/api.md b/tests/testthat/_snaps/api.md index cf26cfe..1383036 100644 --- a/tests/testthat/_snaps/api.md +++ b/tests/testthat/_snaps/api.md @@ -1,4 +1,4 @@ -# cli_alert_warning works [plain] +# cli_alert_warning [plain] Code cli::cli_alert_warning( @@ -6,7 +6,7 @@ Message ! This package hasn't been tested with this Bugzilla version. -# cli_alert_warning works [ansi] +# cli_alert_warning [ansi] Code cli::cli_alert_warning( @@ -14,7 +14,7 @@ Message ! This package hasn't been tested with this Bugzilla version. -# cli_alert_warning works [unicode] +# cli_alert_warning [unicode] Code cli::cli_alert_warning( @@ -22,7 +22,7 @@ Message ! This package hasn't been tested with this Bugzilla version. -# cli_alert_warning works [fancy] +# cli_alert_warning [fancy] Code cli::cli_alert_warning( @@ -30,7 +30,21 @@ Message ! This package hasn't been tested with this Bugzilla version. -# cli_alert_danger [plain] +# ul [plain] + + Code + cli::cli_ul("Create the API key on the website.") + Message + * Create the API key on the website. + +# ul [unicode] + + Code + cli::cli_ul("Create the API key on the website.") + Message + • Create the API key on the website. + +# ca_cli_alert_danger [plain] Code cli::cli_alert_danger("Not authenticated on this site.") @@ -41,7 +55,7 @@ Message v Authenticated on this site! -# cli_alert_danger [ansi] +# ca_cli_alert_danger [ansi] Code cli::cli_alert_danger("Not authenticated on this site.") @@ -52,7 +66,7 @@ Message v Authenticated on this site! -# cli_alert_danger [unicode] +# ca_cli_alert_danger [unicode] Code cli::cli_alert_danger("Not authenticated on this site.") @@ -63,7 +77,7 @@ Message ✔ Authenticated on this site! -# cli_alert_danger [fancy] +# ca_cli_alert_danger [fancy] Code cli::cli_alert_danger("Not authenticated on this site.") @@ -74,28 +88,28 @@ Message ✔ Authenticated on this site! -# cli_alert_dangers [plain] +# vk_cli_alert_danger [plain] Code cli::cli_alert_danger("Key not valid or not set.") Message x Key not valid or not set. -# cli_alert_dangers [ansi] +# vk_cli_alert_danger [ansi] Code cli::cli_alert_danger("Key not valid or not set.") Message x Key not valid or not set. -# cli_alert_dangers [unicode] +# vk_cli_alert_danger [unicode] Code cli::cli_alert_danger("Key not valid or not set.") Message ✖ Key not valid or not set. -# cli_alert_dangers [fancy] +# vk_cli_alert_danger [fancy] Code cli::cli_alert_danger("Key not valid or not set.") diff --git a/tests/testthat/setup-bugRzilla.R b/tests/testthat/setup-bugRzilla.R index 4c9e171..76b34cc 100644 --- a/tests/testthat/setup-bugRzilla.R +++ b/tests/testthat/setup-bugRzilla.R @@ -1,5 +1,4 @@ library("vcr") # *Required* as vcr is set up on loading -library("httptest") # *Required* as hhtptest is set up on loading vcr_dir <- vcr::vcr_test_path("fixtures") if (!nzchar(Sys.getenv("R_BUGZILLA"))) { diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index 0d2ac24..69059e6 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -1,24 +1,67 @@ +# This is to check the create_bugzilla_key function test_that("create_bugzilla_key works", { vcr::use_cassette("create_bugzilla_key", { cbk <- create_bugzilla_key(missing_host()) url <- "https://bugs.r-project.org/bugzilla/userprefs.cgi?tab=apikey" }) + expect_equal(missing_host(),"https://bugs.r-project.org/bugzilla/") expect_equal(paste0(missing_host(), "userprefs.cgi?tab=apikey"), url) - expect_condition() - cli::test_that_cli("cli_alert_warning works", { + cli::test_that_cli( configs = c("plain", "ansi", "unicode", "fancy"), "cli_alert_warning", { expect_snapshot({ cli::cli_alert_warning("This package hasn't been tested with this Bugzilla version.") }) }) + cli::test_that_cli(configs = c("plain", "unicode"),"ul", { + expect_snapshot({ + cli::cli_ul("Create the API key on the website.") + }) + }) }) +# This is to check the set_key function +test_that("set_key works", { + vcr::use_cassette("set_key", { + sk <- set_key() + }) + expect_equal(write_renviron(key = sk, value = sk, file = app_file()), NULL) +}) + + +# # This is to check the check_key function +# test_that("check_key works", { +# vcr::use_cassette("check_key", { +# sk <- check_key(use_key(), verbose = FALSE) +# path <- app_file() +# key_name <- use_key() +# }) +# cli::test_that_cli("sk_cli_alert_danger", { +# expect_snapshot({ +# cli_alert_danger("Key {.code {key_name}} not found on {.path {path}}.") +# }) +# }) +# }) +# +# +# # This is to check the use_key function +# test_that("use_key works", { +# vcr::use_cassette("use_key", { +# key_name <- use_key() +# }) +# cli::test_that_cli("uk_cli_alert_danger", { +# expect_snapshot({ +# cli::cli_alert_danger("Key {.code {key_name}} not found. Use {.code set_key()}") +# }) +# }) +# }) + +# This is to check the check_authentication function test_that("check_authentication works", { vcr::use_cassette("check_authentication", { ca <- check_authentication(missing_host()) }) expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") - cli::test_that_cli("cli_alert_danger",{ + cli::test_that_cli("ca_cli_alert_danger",{ expect_snapshot({ cli::cli_alert_danger("Not authenticated on this site.") cli::cli_alert_success("Authenticated on this site!") @@ -27,6 +70,7 @@ test_that("check_authentication works", { }) +# This is to check the check_api_version function test_that("check_api_version works", { vcr::use_cassette("check_api_version", { cav <- check_api_version(missing_host()) @@ -35,6 +79,7 @@ test_that("check_api_version works", { }) +# This is to check the check_last_audit function test_that("check_last_audit works", { vcr::use_cassette("check_last_audit", { cla <- check_last_audit(missing_product(), missing_host()) @@ -45,15 +90,14 @@ test_that("check_last_audit works", { }) +# This is to check the valid_key function test_that("valid_key works", { - use_cassette("valid_key", { + vcr::use_cassette("valid_key", { vk <- valid_key(use_key()) }) - cli::test_that_cli("cli_alert_dangers", { + cli::test_that_cli("vk_cli_alert_danger", { expect_snapshot({ cli::cli_alert_danger("Key not valid or not set.") }) }) }) - -snapshot_accept('R/api.R') diff --git a/tests/testthat/test-bug_search.R b/tests/testthat/test-bug_search.R new file mode 100644 index 0000000..0a732a8 --- /dev/null +++ b/tests/testthat/test-bug_search.R @@ -0,0 +1,23 @@ +valid_parameters <- c("alias", "assigned_to", "component", "creation_time", + "creator", "id", "last_change_time", "limit", + "longdescs.count", "offset", "op_sys", "platform", + "priority", "product", "resolution", "severity", + "status", "summary", "tags", "target_milestone", + "qa_contact", "url", "version", "whiteboard", + "quicksearch") + +# test_that("bug_search works", { +# vcr::use_cassette("bug_search", { +# bs <- bug_search() +# url <- "https://bugs.r-project.org/bugzilla/rest/bug?id=1" +# params <- params(1) +# }) +# expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") +# }) + +test_that("params works", { + vcr::use_cassette("params", { + par <- params() + }) + expect_true(all(names(par) %in% valid_parameters)) +}) From 2312166a1323b77160198280c1570cc238020948 Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Mon, 14 Jun 2021 14:01:51 +0530 Subject: [PATCH 4/8] PR updates --- tests/fixtures/check_api_version.yml | 33 ------ tests/fixtures/check_authentication.yml | 39 ------- tests/fixtures/check_last_audit.yml | 14 +-- tests/fixtures/create_bugzilla_key.yml | 74 ------------- tests/fixtures/params.yml | 1 - tests/fixtures/valid_key.yml | 1 - tests/testthat/_snaps/api.md | 132 ++++++++++-------------- tests/testthat/test-api.R | 87 ++++------------ tests/testthat/test-bug_search.R | 10 +- tests/testthat/test-get_fields.R | 4 +- tests/testthat/test-post_help.R | 18 ++++ 11 files changed, 106 insertions(+), 307 deletions(-) delete mode 100644 tests/fixtures/check_api_version.yml delete mode 100644 tests/fixtures/check_authentication.yml delete mode 100644 tests/fixtures/create_bugzilla_key.yml delete mode 100644 tests/fixtures/params.yml delete mode 100644 tests/fixtures/valid_key.yml create mode 100644 tests/testthat/test-post_help.R diff --git a/tests/fixtures/check_api_version.yml b/tests/fixtures/check_api_version.yml deleted file mode 100644 index f34166b..0000000 --- a/tests/fixtures/check_api_version.yml +++ /dev/null @@ -1,33 +0,0 @@ -http_interactions: -- request: - method: get - uri: https://bugs.r-project.org/bugzilla/rest/version - body: - encoding: '' - string: '' - headers: - Accept: application/json, text/xml, application/xml, */* - response: - status: - status_code: 200 - category: Success - reason: OK - message: 'Success: (200) OK' - headers: - date: Mon, 31 May 2021 03:18:02 GMT - server: gazelle - etag: eTsYwUQ9/dEzCleTaxjJ5A - content-length: '20' - content-type: application/json; charset=UTF-8 - access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, - x-bugzilla-api-key, x-bugzilla-password, x-bugzilla-token, x-bugzilla-login - access-control-allow-origin: '*' - x-content-type-options: nosniff - x-frame-options: SAMEORIGIN - x-xss-protection: 1; mode=block - body: - encoding: UTF-8 - file: no - string: '{"version":"5.1.2+"}' - recorded_at: 2021-05-31 03:18:02 GMT - recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/check_authentication.yml b/tests/fixtures/check_authentication.yml deleted file mode 100644 index ef8177e..0000000 --- a/tests/fixtures/check_authentication.yml +++ /dev/null @@ -1,39 +0,0 @@ -http_interactions: -- request: - method: get - uri: https://bugs.r-project.org/bugzilla/rest/whoami - body: - encoding: '' - string: '' - headers: - Accept: application/json, text/xml, application/xml, */* - X-BUGZILLA-API-KEY: https://bugs.r-project.org/bugzilla/ - User-agent: https://github.com/llrs/bugRzilla/ - response: - status: - status_code: 400 - category: Client error - reason: Bad Request - message: 'Client error: (400) Bad Request' - headers: - date: Mon, 31 May 2021 03:18:01 GMT - server: gazelle - etag: QoEOn1fkyvtzNJvFp167rw - content-length: '185' - content-type: application/json; charset=UTF-8 - access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, - x-bugzilla-login, x-bugzilla-token, x-bugzilla-password, x-bugzilla-api-key - access-control-allow-origin: '*' - x-content-type-options: nosniff - x-frame-options: SAMEORIGIN - x-xss-protection: 1; mode=block - set-cookie: Bugzilla_login_request_cookie=MGh4nMQZ13; domain=bugs.r-project.org; - path=/bugzilla/; secure; HttpOnly - connection: close - body: - encoding: UTF-8 - file: no - string: '{"code":"306","error":true,"message":"The API key you specified is - invalid. Please check that you typed it correctly.","documentation":"https://bugzilla.readthedocs.org/en/latest/api/"}' - recorded_at: 2021-05-31 03:18:00 GMT - recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/check_last_audit.yml b/tests/fixtures/check_last_audit.yml index 358ca0f..97224fb 100644 --- a/tests/fixtures/check_last_audit.yml +++ b/tests/fixtures/check_last_audit.yml @@ -7,6 +7,8 @@ http_interactions: string: '' headers: Accept: application/json, text/xml, application/xml, */* + Authorization: My bearer token is safe + X-BUGZILLA-API-KEY: Removing this header too just in case response: status: status_code: 200 @@ -14,22 +16,20 @@ http_interactions: reason: OK message: 'Success: (200) OK' headers: - date: Mon, 31 May 2021 03:04:29 GMT + date: Sat, 12 Jun 2021 22:38:08 GMT server: gazelle - etag: GIrwjX1k17GX4FOvl+NcVA + etag: /kF0g2q98GJLV5YGfBdm7Q content-length: '42' content-type: application/json; charset=UTF-8 access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, - x-bugzilla-login, x-bugzilla-password, x-bugzilla-token, x-bugzilla-api-key + x-bugzilla-api-key, x-bugzilla-login, x-bugzilla-token, x-bugzilla-password access-control-allow-origin: '*' x-content-type-options: nosniff x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block - set-cookie: Bugzilla_login_request_cookie=l0ZOvJZzmk; domain=bugs.r-project.org; - path=/bugzilla/; secure; HttpOnly body: encoding: UTF-8 file: no - string: '{"last_audit_time":"2021-05-27T01:19:10Z"}' - recorded_at: 2021-05-31 03:04:28 GMT + string: '{"last_audit_time":"2021-06-09T23:47:55Z"}' + recorded_at: 2021-06-12 22:38:08 GMT recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/create_bugzilla_key.yml b/tests/fixtures/create_bugzilla_key.yml deleted file mode 100644 index c5a677d..0000000 --- a/tests/fixtures/create_bugzilla_key.yml +++ /dev/null @@ -1,74 +0,0 @@ -http_interactions: -- request: - method: get - uri: https://bugs.r-project.org/bugzilla/rest/version - body: - encoding: '' - string: '' - headers: - Accept: application/json, text/xml, application/xml, */* - Authorization: My bearer token is safe - X-BUGZILLA-API-KEY: Removing this header too just in case - response: - status: - status_code: 200 - category: Success - reason: OK - message: 'Success: (200) OK' - headers: - date: Sat, 05 Jun 2021 21:04:49 GMT - server: gazelle - etag: eTsYwUQ9/dEzCleTaxjJ5A - content-length: '20' - content-type: application/json; charset=UTF-8 - access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, - x-bugzilla-password, x-bugzilla-token, x-bugzilla-login, x-bugzilla-api-key - access-control-allow-origin: '*' - x-content-type-options: nosniff - x-frame-options: SAMEORIGIN - x-xss-protection: 1; mode=block - set-cookie: Bugzilla_login_request_cookie=nG2w3negvv; domain=bugs.r-project.org; - path=/bugzilla/; secure; HttpOnly - body: - encoding: UTF-8 - file: no - string: '{"version":"5.1.2+"}' - recorded_at: 2021-06-05 21:04:49 GMT - recorded_with: vcr/0.6.0, webmockr/0.8.0 -- request: - method: get - uri: https://bugs.r-project.org/bugzilla/rest/whoami - body: - encoding: '' - string: '' - headers: - Accept: application/json, text/xml, application/xml, */* - X-BUGZILLA-API-KEY: Removing this header too just in case - User-agent: https://github.com/llrs/bugRzilla/ - Authorization: My bearer token is safe - response: - status: - status_code: 400 - category: Client error - reason: Bad Request - message: 'Client error: (400) Bad Request' - headers: - date: Sat, 05 Jun 2021 21:04:49 GMT - server: gazelle - etag: QoEOn1fkyvtzNJvFp167rw - content-length: '185' - content-type: application/json; charset=UTF-8 - access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, - x-bugzilla-api-key, x-bugzilla-login, x-bugzilla-password, x-bugzilla-token - access-control-allow-origin: '*' - x-content-type-options: nosniff - x-frame-options: SAMEORIGIN - x-xss-protection: 1; mode=block - connection: close - body: - encoding: UTF-8 - file: no - string: '{"code":"306","message":"The API key you specified is invalid. Please - check that you typed it correctly.","error":true,"documentation":"https://bugzilla.readthedocs.org/en/latest/api/"}' - recorded_at: 2021-06-05 21:04:49 GMT - recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/params.yml b/tests/fixtures/params.yml deleted file mode 100644 index 8b13789..0000000 --- a/tests/fixtures/params.yml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/fixtures/valid_key.yml b/tests/fixtures/valid_key.yml deleted file mode 100644 index 8b13789..0000000 --- a/tests/fixtures/valid_key.yml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/testthat/_snaps/api.md b/tests/testthat/_snaps/api.md index 1383036..c01b490 100644 --- a/tests/testthat/_snaps/api.md +++ b/tests/testthat/_snaps/api.md @@ -1,118 +1,98 @@ -# cli_alert_warning [plain] +# create_bugzilla_key() works [plain] Code - cli::cli_alert_warning( - "This package hasn't been tested with this Bugzilla version.") + create_bugzilla_key(host = missing_host()) Message - ! This package hasn't been tested with this Bugzilla version. - -# cli_alert_warning [ansi] - - Code - cli::cli_alert_warning( - "This package hasn't been tested with this Bugzilla version.") - Message - ! This package hasn't been tested with this Bugzilla version. - -# cli_alert_warning [unicode] - - Code - cli::cli_alert_warning( - "This package hasn't been tested with this Bugzilla version.") - Message - ! This package hasn't been tested with this Bugzilla version. + i Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + v Found key `R_BUGZILLA`. + v Using key `R_BUGZILLA`. + x Not authenticated on this site. + v Authenticated on this site! -# cli_alert_warning [fancy] +# create_bugzilla_key() works [unicode] Code - cli::cli_alert_warning( - "This package hasn't been tested with this Bugzilla version.") + create_bugzilla_key(host = missing_host()) Message - ! This package hasn't been tested with this Bugzilla version. + ℹ Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + ✔ Found key `R_BUGZILLA`. + ✔ Using key `R_BUGZILLA`. + ✖ Not authenticated on this site. + ✔ Authenticated on this site! -# ul [plain] +# check_key() works [plain] Code - cli::cli_ul("Create the API key on the website.") + check_key(key_name = missing_key(), verbose = TRUE) Message - * Create the API key on the website. + i Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + v Found key `R_BUGZILLA`. + Output + [1] TRUE -# ul [unicode] +# check_key() works [unicode] Code - cli::cli_ul("Create the API key on the website.") + check_key(key_name = missing_key(), verbose = TRUE) Message - • Create the API key on the website. + ℹ Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + ✔ Found key `R_BUGZILLA`. + Output + [1] TRUE -# ca_cli_alert_danger [plain] +# use_key() works [plain] Code - cli::cli_alert_danger("Not authenticated on this site.") - Message - x Not authenticated on this site. - Code - cli::cli_alert_success("Authenticated on this site!") + use_key(missing_key()) Message - v Authenticated on this site! + v Using key `R_BUGZILLA`. -# ca_cli_alert_danger [ansi] +--- Code - cli::cli_alert_danger("Not authenticated on this site.") - Message - x Not authenticated on this site. - Code - cli::cli_alert_success("Authenticated on this site!") - Message - v Authenticated on this site! + !check_key(key_name = missing_key(), verbose = FALSE) + Output + [1] FALSE -# ca_cli_alert_danger [unicode] +# use_key() works [unicode] Code - cli::cli_alert_danger("Not authenticated on this site.") + use_key(missing_key()) Message - ✖ Not authenticated on this site. - Code - cli::cli_alert_success("Authenticated on this site!") - Message - ✔ Authenticated on this site! + ✔ Using key `R_BUGZILLA`. -# ca_cli_alert_danger [fancy] +--- Code - cli::cli_alert_danger("Not authenticated on this site.") - Message - ✖ Not authenticated on this site. - Code - cli::cli_alert_success("Authenticated on this site!") - Message - ✔ Authenticated on this site! + !check_key(key_name = missing_key(), verbose = FALSE) + Output + [1] FALSE -# vk_cli_alert_danger [plain] +# valid_key() works [plain] Code - cli::cli_alert_danger("Key not valid or not set.") - Message - x Key not valid or not set. + valid_key(key = missing_key()) + Output + [1] TRUE -# vk_cli_alert_danger [ansi] +# valid_key() works [ansi] Code - cli::cli_alert_danger("Key not valid or not set.") - Message - x Key not valid or not set. + valid_key(key = missing_key()) + Output + [1] TRUE -# vk_cli_alert_danger [unicode] +# valid_key() works [unicode] Code - cli::cli_alert_danger("Key not valid or not set.") - Message - ✖ Key not valid or not set. + valid_key(key = missing_key()) + Output + [1] TRUE -# vk_cli_alert_danger [fancy] +# valid_key() works [fancy] Code - cli::cli_alert_danger("Key not valid or not set.") - Message - ✖ Key not valid or not set. + valid_key(key = missing_key()) + Output + [1] TRUE diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index 69059e6..98153f1 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -1,20 +1,8 @@ # This is to check the create_bugzilla_key function -test_that("create_bugzilla_key works", { - vcr::use_cassette("create_bugzilla_key", { - cbk <- create_bugzilla_key(missing_host()) - url <- "https://bugs.r-project.org/bugzilla/userprefs.cgi?tab=apikey" - }) - expect_equal(missing_host(),"https://bugs.r-project.org/bugzilla/") - expect_equal(paste0(missing_host(), "userprefs.cgi?tab=apikey"), url) - cli::test_that_cli( configs = c("plain", "ansi", "unicode", "fancy"), "cli_alert_warning", { - expect_snapshot({ - cli::cli_alert_warning("This package hasn't been tested with this Bugzilla version.") - }) - }) - cli::test_that_cli(configs = c("plain", "unicode"),"ul", { - expect_snapshot({ - cli::cli_ul("Create the API key on the website.") - }) +cli::test_that_cli(configs = c("plain", "unicode"), "create_bugzilla_key() works", { + url <- "https://bugs.r-project.org/bugzilla/userprefs.cgi?tab=apikey" + expect_snapshot({ + create_bugzilla_key(host = missing_host()) }) }) @@ -22,60 +10,28 @@ test_that("create_bugzilla_key works", { # This is to check the set_key function test_that("set_key works", { vcr::use_cassette("set_key", { - sk <- set_key() + sk <- set_key(missing_key(), key_name = "R_BUGZILLA") }) expect_equal(write_renviron(key = sk, value = sk, file = app_file()), NULL) }) -# # This is to check the check_key function -# test_that("check_key works", { -# vcr::use_cassette("check_key", { -# sk <- check_key(use_key(), verbose = FALSE) -# path <- app_file() -# key_name <- use_key() -# }) -# cli::test_that_cli("sk_cli_alert_danger", { -# expect_snapshot({ -# cli_alert_danger("Key {.code {key_name}} not found on {.path {path}}.") -# }) -# }) -# }) -# -# -# # This is to check the use_key function -# test_that("use_key works", { -# vcr::use_cassette("use_key", { -# key_name <- use_key() -# }) -# cli::test_that_cli("uk_cli_alert_danger", { -# expect_snapshot({ -# cli::cli_alert_danger("Key {.code {key_name}} not found. Use {.code set_key()}") -# }) -# }) -# }) - -# This is to check the check_authentication function -test_that("check_authentication works", { - vcr::use_cassette("check_authentication", { - ca <- check_authentication(missing_host()) - }) - expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") - cli::test_that_cli("ca_cli_alert_danger",{ - expect_snapshot({ - cli::cli_alert_danger("Not authenticated on this site.") - cli::cli_alert_success("Authenticated on this site!") - }) +# This is to check the check_key function +cli::test_that_cli(configs = c("plain", "unicode"), "check_key() works", { + expect_snapshot({ + check_key(key_name = missing_key(), verbose = TRUE) }) }) -# This is to check the check_api_version function -test_that("check_api_version works", { - vcr::use_cassette("check_api_version", { - cav <- check_api_version(missing_host()) +# This is to check the use_key function +cli::test_that_cli(configs = c("plain", "unicode"), "use_key() works", { + expect_snapshot({ + use_key(missing_key()) + }) + expect_snapshot({ + !check_key(key_name = missing_key(), verbose = FALSE) }) - expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") }) @@ -91,13 +47,8 @@ test_that("check_last_audit works", { # This is to check the valid_key function -test_that("valid_key works", { - vcr::use_cassette("valid_key", { - vk <- valid_key(use_key()) - }) - cli::test_that_cli("vk_cli_alert_danger", { - expect_snapshot({ - cli::cli_alert_danger("Key not valid or not set.") - }) +cli::test_that_cli("valid_key() works", { + expect_snapshot({ + valid_key(key = missing_key()) }) }) diff --git a/tests/testthat/test-bug_search.R b/tests/testthat/test-bug_search.R index 0a732a8..50a021b 100644 --- a/tests/testthat/test-bug_search.R +++ b/tests/testthat/test-bug_search.R @@ -8,16 +8,14 @@ valid_parameters <- c("alias", "assigned_to", "component", "creation_time", # test_that("bug_search works", { # vcr::use_cassette("bug_search", { -# bs <- bug_search() +# bs <- bug_search(id=1) # url <- "https://bugs.r-project.org/bugzilla/rest/bug?id=1" -# params <- params(1) # }) -# expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") +# expect_equal(paste0(missing_host(), "rest/bug?", params(id=1)), "https://bugs.r-project.org/bugzilla/rest/bug?id=1") # }) test_that("params works", { - vcr::use_cassette("params", { - par <- params() - }) + par <- params() expect_true(all(names(par) %in% valid_parameters)) + expect_true(all(!names(params("ids")) %in% valid_parameters)) }) diff --git a/tests/testthat/test-get_fields.R b/tests/testthat/test-get_fields.R index 3bfa61f..f837465 100644 --- a/tests/testthat/test-get_fields.R +++ b/tests/testthat/test-get_fields.R @@ -1,6 +1,6 @@ test_that("get_fields works", { - skip_if_offline() - skip_on_cran() + # skip_if_offline() + # skip_on_cran() vcr::use_cassette("get_fields", { fi <- get_fields() }) diff --git a/tests/testthat/test-post_help.R b/tests/testthat/test-post_help.R new file mode 100644 index 0000000..92c3e0c --- /dev/null +++ b/tests/testthat/test-post_help.R @@ -0,0 +1,18 @@ +# yes <- c("Yes", "Definitely", "Positive", "For sure", "Yup", "Yeah", +# "Absolutely") +# no <- c("Not sure", "Not now", "Negative", "No", "Nope", "Absolutely not") +# +# cli::test_that_cli(configs = c("plain"), "read_documentation() works",{ +# expect_snapshot({ +# expect_equal(read_documentation(), "Cancel") +# # expect_equal(read_documentation(), no) +# # expect_equal(read_documentation(), yes) +# }) +# }) + +# test_that("ask_confirmation works", { +# vcr::use_cassette("ask_confirmation", { +# ac <- ask_confirmation(title = NULL, positive = yes, negative = no) +# }) +# expect_equal(sample(positive, 1), sample(negative, 2)) +# }) From 08a29a386f8229bd849bd4e5e840396989094cc0 Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Fri, 18 Jun 2021 02:39:23 +0530 Subject: [PATCH 5/8] PR Updates --- tests/testthat/_snaps/api.md | 28 +++++++++++++++++----------- tests/testthat/test-api.R | 12 +++++++----- tests/testthat/test-bug_search.R | 4 ++-- tests/testthat/test-get_fields.R | 4 ++-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/testthat/_snaps/api.md b/tests/testthat/_snaps/api.md index c01b490..5687dc6 100644 --- a/tests/testthat/_snaps/api.md +++ b/tests/testthat/_snaps/api.md @@ -40,33 +40,39 @@ Output [1] TRUE -# use_key() works [plain] +# check_key() fails [plain] Code - use_key(missing_key()) + !check_key(key_name = missing_key(), verbose = TRUE) Message - v Using key `R_BUGZILLA`. + i Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + v Found key `R_BUGZILLA`. + Output + [1] FALSE ---- +# check_key() fails [unicode] Code - !check_key(key_name = missing_key(), verbose = FALSE) + !check_key(key_name = missing_key(), verbose = TRUE) + Message + ℹ Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + ✔ Found key `R_BUGZILLA`. Output [1] FALSE -# use_key() works [unicode] +# use_key() works [plain] Code use_key(missing_key()) Message - ✔ Using key `R_BUGZILLA`. + v Using key `R_BUGZILLA`. ---- +# use_key() works [unicode] Code - !check_key(key_name = missing_key(), verbose = FALSE) - Output - [1] FALSE + use_key(missing_key()) + Message + ✔ Using key `R_BUGZILLA`. # valid_key() works [plain] diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index 98153f1..1ac34f1 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -1,6 +1,5 @@ # This is to check the create_bugzilla_key function cli::test_that_cli(configs = c("plain", "unicode"), "create_bugzilla_key() works", { - url <- "https://bugs.r-project.org/bugzilla/userprefs.cgi?tab=apikey" expect_snapshot({ create_bugzilla_key(host = missing_host()) }) @@ -10,7 +9,7 @@ cli::test_that_cli(configs = c("plain", "unicode"), "create_bugzilla_key() works # This is to check the set_key function test_that("set_key works", { vcr::use_cassette("set_key", { - sk <- set_key(missing_key(), key_name = "R_BUGZILLA") + sk <- set_key() }) expect_equal(write_renviron(key = sk, value = sk, file = app_file()), NULL) }) @@ -23,15 +22,18 @@ cli::test_that_cli(configs = c("plain", "unicode"), "check_key() works", { }) }) +cli::test_that_cli(configs = c("plain", "unicode"), "check_key() fails", { + expect_snapshot({ + !check_key(key_name = missing_key(), verbose = TRUE) + }) +}) + # This is to check the use_key function cli::test_that_cli(configs = c("plain", "unicode"), "use_key() works", { expect_snapshot({ use_key(missing_key()) }) - expect_snapshot({ - !check_key(key_name = missing_key(), verbose = FALSE) - }) }) diff --git a/tests/testthat/test-bug_search.R b/tests/testthat/test-bug_search.R index 50a021b..2b92eb7 100644 --- a/tests/testthat/test-bug_search.R +++ b/tests/testthat/test-bug_search.R @@ -11,11 +11,11 @@ valid_parameters <- c("alias", "assigned_to", "component", "creation_time", # bs <- bug_search(id=1) # url <- "https://bugs.r-project.org/bugzilla/rest/bug?id=1" # }) -# expect_equal(paste0(missing_host(), "rest/bug?", params(id=1)), "https://bugs.r-project.org/bugzilla/rest/bug?id=1") +# expect_equal(paste0(missing_host(), "rest/bug?", params(id=1)), url) # }) test_that("params works", { par <- params() expect_true(all(names(par) %in% valid_parameters)) - expect_true(all(!names(params("ids")) %in% valid_parameters)) + expect_error(params(ids=1)) }) diff --git a/tests/testthat/test-get_fields.R b/tests/testthat/test-get_fields.R index f837465..3bfa61f 100644 --- a/tests/testthat/test-get_fields.R +++ b/tests/testthat/test-get_fields.R @@ -1,6 +1,6 @@ test_that("get_fields works", { - # skip_if_offline() - # skip_on_cran() + skip_if_offline() + skip_on_cran() vcr::use_cassette("get_fields", { fi <- get_fields() }) From 9c9d3b1fc41002a6fb7adcd79b96fa6e7832aad6 Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Fri, 18 Jun 2021 02:46:18 +0530 Subject: [PATCH 6/8] PR Updates --- tests/testthat/_snaps/api.md | 20 -------------------- tests/testthat/test-api.R | 10 +++++----- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/tests/testthat/_snaps/api.md b/tests/testthat/_snaps/api.md index 5687dc6..911532f 100644 --- a/tests/testthat/_snaps/api.md +++ b/tests/testthat/_snaps/api.md @@ -40,26 +40,6 @@ Output [1] TRUE -# check_key() fails [plain] - - Code - !check_key(key_name = missing_key(), verbose = TRUE) - Message - i Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. - v Found key `R_BUGZILLA`. - Output - [1] FALSE - -# check_key() fails [unicode] - - Code - !check_key(key_name = missing_key(), verbose = TRUE) - Message - ℹ Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. - ✔ Found key `R_BUGZILLA`. - Output - [1] FALSE - # use_key() works [plain] Code diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index 1ac34f1..82ec6cf 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -22,11 +22,11 @@ cli::test_that_cli(configs = c("plain", "unicode"), "check_key() works", { }) }) -cli::test_that_cli(configs = c("plain", "unicode"), "check_key() fails", { - expect_snapshot({ - !check_key(key_name = missing_key(), verbose = TRUE) - }) -}) +# cli::test_that_cli(configs = c("plain", "unicode"), "check_key() fails", { +# expect_snapshot({ +# !check_key(key_name = missing_key(), verbose = TRUE) +# }) +# }) # This is to check the use_key function From 4b38103fce244edba47ab6971a83c9d19d5917c7 Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Sat, 19 Jun 2021 02:56:40 +0530 Subject: [PATCH 7/8] PR Updates --- DESCRIPTION | 1 - tests/fixtures/check_last_audit.yml | 8 ++++---- tests/fixtures/set_key.yml | 1 - tests/testthat/_snaps/api.md | 22 ++++++++-------------- tests/testthat/test-api.R | 25 ++++++++----------------- 5 files changed, 20 insertions(+), 37 deletions(-) delete mode 100644 tests/fixtures/set_key.yml diff --git a/DESCRIPTION b/DESCRIPTION index e7615a4..ca85fd9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,6 @@ Suggests: reprex, rmarkdown, testthat (>= 3.0.0), - httptest, vcr VignetteBuilder: knitr diff --git a/tests/fixtures/check_last_audit.yml b/tests/fixtures/check_last_audit.yml index 97224fb..c37d5ef 100644 --- a/tests/fixtures/check_last_audit.yml +++ b/tests/fixtures/check_last_audit.yml @@ -16,9 +16,9 @@ http_interactions: reason: OK message: 'Success: (200) OK' headers: - date: Sat, 12 Jun 2021 22:38:08 GMT + date: Fri, 18 Jun 2021 20:57:31 GMT server: gazelle - etag: /kF0g2q98GJLV5YGfBdm7Q + etag: nuyzry+9UExbGXwyRTkrfQ content-length: '42' content-type: application/json; charset=UTF-8 access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, @@ -30,6 +30,6 @@ http_interactions: body: encoding: UTF-8 file: no - string: '{"last_audit_time":"2021-06-09T23:47:55Z"}' - recorded_at: 2021-06-12 22:38:08 GMT + string: '{"last_audit_time":"2021-06-18T20:47:32Z"}' + recorded_at: 2021-06-18 20:57:31 GMT recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/fixtures/set_key.yml b/tests/fixtures/set_key.yml deleted file mode 100644 index 8b13789..0000000 --- a/tests/fixtures/set_key.yml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/testthat/_snaps/api.md b/tests/testthat/_snaps/api.md index 911532f..915943b 100644 --- a/tests/testthat/_snaps/api.md +++ b/tests/testthat/_snaps/api.md @@ -1,7 +1,7 @@ # create_bugzilla_key() works [plain] Code - create_bugzilla_key(host = missing_host()) + create_bugzilla_key() Message i Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. v Found key `R_BUGZILLA`. @@ -12,7 +12,7 @@ # create_bugzilla_key() works [unicode] Code - create_bugzilla_key(host = missing_host()) + create_bugzilla_key() Message ℹ Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. ✔ Found key `R_BUGZILLA`. @@ -23,20 +23,14 @@ # check_key() works [plain] Code - check_key(key_name = missing_key(), verbose = TRUE) - Message - i Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. - v Found key `R_BUGZILLA`. + check_key(key_name = missing_key(), verbose = FALSE) Output [1] TRUE # check_key() works [unicode] Code - check_key(key_name = missing_key(), verbose = TRUE) - Message - ℹ Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. - ✔ Found key `R_BUGZILLA`. + check_key(key_name = missing_key(), verbose = FALSE) Output [1] TRUE @@ -57,28 +51,28 @@ # valid_key() works [plain] Code - valid_key(key = missing_key()) + valid_key(key = "hgfcchg12") Output [1] TRUE # valid_key() works [ansi] Code - valid_key(key = missing_key()) + valid_key(key = "hgfcchg12") Output [1] TRUE # valid_key() works [unicode] Code - valid_key(key = missing_key()) + valid_key(key = "hgfcchg12") Output [1] TRUE # valid_key() works [fancy] Code - valid_key(key = missing_key()) + valid_key(key = "hgfcchg12") Output [1] TRUE diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index 82ec6cf..64b1ea4 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -1,34 +1,27 @@ # This is to check the create_bugzilla_key function cli::test_that_cli(configs = c("plain", "unicode"), "create_bugzilla_key() works", { expect_snapshot({ - create_bugzilla_key(host = missing_host()) + create_bugzilla_key() }) }) # This is to check the set_key function test_that("set_key works", { - vcr::use_cassette("set_key", { - sk <- set_key() - }) + skip_on_ci() + sk <- set_key() expect_equal(write_renviron(key = sk, value = sk, file = app_file()), NULL) }) # This is to check the check_key function cli::test_that_cli(configs = c("plain", "unicode"), "check_key() works", { + skip_on_ci() expect_snapshot({ - check_key(key_name = missing_key(), verbose = TRUE) + check_key(key_name = missing_key(), verbose = FALSE) }) }) -# cli::test_that_cli(configs = c("plain", "unicode"), "check_key() fails", { -# expect_snapshot({ -# !check_key(key_name = missing_key(), verbose = TRUE) -# }) -# }) - - # This is to check the use_key function cli::test_that_cli(configs = c("plain", "unicode"), "use_key() works", { expect_snapshot({ @@ -40,17 +33,15 @@ cli::test_that_cli(configs = c("plain", "unicode"), "use_key() works", { # This is to check the check_last_audit function test_that("check_last_audit works", { vcr::use_cassette("check_last_audit", { - cla <- check_last_audit(missing_product(), missing_host()) + cla <- check_last_audit() }) - expect_equal(missing_host(), "https://bugs.r-project.org/bugzilla/") - expect_equal(missing_product(), "R") - expect_s3_class(GET(paste0(missing_host(), "rest/last_audit_time")), "response") + expect_s3_class(cla, "POSIXlt") }) # This is to check the valid_key function cli::test_that_cli("valid_key() works", { expect_snapshot({ - valid_key(key = missing_key()) + valid_key(key = "hgfcchg12") }) }) From 21d60acfbebb4409e131165c3c6468cac4b4f41f Mon Sep 17 00:00:00 2001 From: kpiyush04 <04kpiyush@gmail.com> Date: Sat, 19 Jun 2021 03:05:25 +0530 Subject: [PATCH 8/8] PR Updates --- tests/testthat/test-api.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index 64b1ea4..e2a6bdf 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -1,5 +1,6 @@ # This is to check the create_bugzilla_key function cli::test_that_cli(configs = c("plain", "unicode"), "create_bugzilla_key() works", { + skip_on_ci() expect_snapshot({ create_bugzilla_key() })