-
Notifications
You must be signed in to change notification settings - Fork 17
/
topics-contributing.Rmd
73 lines (47 loc) · 3.12 KB
/
topics-contributing.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Contributor friendliness {#contributor-friendliness}
How do you make your package wrapping an HTTP resource contributor-friendly?
rOpenSci has some general advice on [contributor-friendliness](https://devguide.ropensci.org/collaboration.html#friendlyfiles).
Now, there are some more aspects when dealing with HTTP testing.
## Taking notes about encryption
In your contributing guide, make sure you note how you e.g. created an encrypted token for the tests. Link to a script that one could run to re-create it. Good for future contributors including yourself!
## Providing a sandbox
It might be very neat to provide a **sandbox**, even if just for yourself.
* If interacting with say Twitter API you might want to create a Twitter account dedicated to this.
```{=html}
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">And this is why you don’t use live API credentials in your tests 🤣. Leaving up for the humorous replies <a href="https://t.co/x0COfvt2QD">https://t.co/x0COfvt2QD</a></p>— Hadley Wickham (@hadleywickham) <a href="https://twitter.com/hadleywickham/status/1365663264563204101?ref_src=twsrc%5Etfw">February 27, 2021</a></blockquote>
```
* If interacting with some sort of web platform you might want to create an account special for storing test data.
* Some web APIs provide a test API key, a test account that one can request access to.
Make sure to take notes on how to create / request access to a sandbox, in your contributing guide.
## Switching between accounts depending on the development mode
Your package might have some behaviour to load a default token for instance, placed in an app dir.
Now, for testing, you might want it to load another token, and you probably also want the token choice to be as automatic as possible.
The [rtweet package](https://github.com/ropensci/rtweet) has such logic.
* It [detects testing/dev mode](https://github.com/ropensci/rtweet/blob/f46bc98f9ac8433c7681d48ed778358bc22a552c/R/utils.R#L132).
```r
is_testing <- function() {
identical(Sys.getenv("TESTTHAT"), "true")
}
is_dev_mode <- function() {
exists(".__DEVTOOLS__", .getNamespace("rtweet"))
}
```
* If some environment variables are present it is able to [create a testing token](https://github.com/ropensci/rtweet/blob/270733c6bf46b2be794d7492d4a4e31d384db0b7/R/auth.R#L281).
```r
rtweet_test <- function() {
access_token <- Sys.getenv("RTWEET_ACCESS_TOKEN")
access_secret <- Sys.getenv("RTWEET_ACCESS_SECRET")
if (identical(access_token, "") || identical(access_secret, "")) {
return()
}
rtweet_bot(
"7rX1CfEYOjrtZenmBhjljPzO3",
"rM3HOLDqmjWzr9UN4cvscchlkFprPNNg99zJJU5R8iYtpC0P0q",
access_token,
access_secret
)
}
```
* The [testing token or a default token is loaded depending on the development mode](https://github.com/ropensci/rtweet/blob/270733c6bf46b2be794d7492d4a4e31d384db0b7/R/auth.R#L234).
## Documenting HTTP testing
Contributors to the package might not be familiar with the HTTP testing package(s) you use (this is true of any non-trivial test setup). Make sure your contributing guide mentions pre-requisites and link to resources (maybe even this very book?).