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] 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)) +})