Skip to content

Commit

Permalink
PR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kpiyush04 committed Jun 8, 2021
1 parent 2380373 commit 023bd3d
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 30 deletions.
23 changes: 13 additions & 10 deletions tests/fixtures/create_bugzilla_key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ 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
category: Success
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
Expand All @@ -41,22 +43,23 @@ 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
category: Client error
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
Expand All @@ -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
1 change: 1 addition & 0 deletions tests/fixtures/params.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

38 changes: 26 additions & 12 deletions tests/testthat/_snaps/api.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
# cli_alert_warning works [plain]
# cli_alert_warning [plain]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! This package hasn't been tested with this Bugzilla version.

# cli_alert_warning works [ansi]
# cli_alert_warning [ansi]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! This package hasn't been tested with this Bugzilla version.

# cli_alert_warning works [unicode]
# cli_alert_warning [unicode]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! This package hasn't been tested with this Bugzilla version.

# cli_alert_warning works [fancy]
# cli_alert_warning [fancy]

Code
cli::cli_alert_warning(
"This package hasn't been tested with this Bugzilla version.")
Message <cliMessage>
! 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 <cliMessage>
* Create the API key on the website.

# ul [unicode]

Code
cli::cli_ul("Create the API key on the website.")
Message <cliMessage>
• Create the API key on the website.

# ca_cli_alert_danger [plain]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Expand All @@ -41,7 +55,7 @@
Message <cliMessage>
v Authenticated on this site!

# cli_alert_danger [ansi]
# ca_cli_alert_danger [ansi]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Expand All @@ -52,7 +66,7 @@
Message <cliMessage>
v Authenticated on this site!

# cli_alert_danger [unicode]
# ca_cli_alert_danger [unicode]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Expand All @@ -63,7 +77,7 @@
Message <cliMessage>
✔ Authenticated on this site!

# cli_alert_danger [fancy]
# ca_cli_alert_danger [fancy]

Code
cli::cli_alert_danger("Not authenticated on this site.")
Expand All @@ -74,28 +88,28 @@
Message <cliMessage>
✔ 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 <cliMessage>
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 <cliMessage>
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 <cliMessage>
✖ 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.")
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/setup-bugRzilla.R
Original file line number Diff line number Diff line change
@@ -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"))) {
Expand Down
58 changes: 51 additions & 7 deletions tests/testthat/test-api.R
Original file line number Diff line number Diff line change
@@ -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!")
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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')
23 changes: 23 additions & 0 deletions tests/testthat/test-bug_search.R
Original file line number Diff line number Diff line change
@@ -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))
})

0 comments on commit 023bd3d

Please sign in to comment.