Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edits post ownership transfer #30

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
.RDataTmp
.Renviron
.DS_Store
/doc/
/Meta/
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ navbar:
href: reference/index.html
- text: Get Started
href: articles/get_started.html
- text: Utilizing acledR
- text: Using acledR
href: index.html
menu:
- text: ACLED API
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/setup-acled_api.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Helpers for test-acled_api.R

received_data <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),country="Argentina", start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = T, log = F)
received_data_monadic <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),country = "Argentina", start_date="2022-01-01",end_date = "2022-12-31",prompt = F, monadic = T, acled_access = F, log = F)
log_received_data <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = c("Western Africa", "Eastern Africa", "Europe"), start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = T)
received_data_numeric_region <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = 1,prompt = F, acled_access = F)
received_data <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),country="Argentina", start_date="2022-01-01", end_date = "2022-12-31", prompt = F, acled_access = T, log = F, inter_numeric = TRUE)
received_data_monadic <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),country = "Argentina", start_date="2022-01-01",end_date = "2022-12-31",prompt = F, monadic = T, acled_access = F, log = F, inter_numeric = TRUE)
log_received_data <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = c("Western Africa", "Eastern Africa", "Europe"), start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = T, inter_numeric = TRUE)
received_data_numeric_region <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = 1,prompt = F, acled_access = F, inter_numeric = TRUE)

timestamp_numeric_check <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country = "Argentina",
start_date="2023-01-01",end_date = "2023-06-06",
timestamp = 1681622333, # as numeric
prompt = F, acled_access = F, log = F)
prompt = F, acled_access = F, log = F, inter_numeric = TRUE)

timestamp_string_check <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country = "Argentina",
start_date="2023-01-01",end_date = "2023-06-06",
timestamp = "2023-04-16", # as numeric
prompt = F, acled_access = F, log = F)
prompt = F, acled_access = F, log = F, inter_numeric = TRUE)

# For checking credentials
log_received_data_check_credential <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
regions = c("Western Africa", "Eastern Africa", "Europe"),end_date = "2022-12-31",prompt = F, acled_access = T, log = T)
regions = c("Western Africa", "Eastern Africa", "Europe"),end_date = "2022-12-31",prompt = F, acled_access = T, log = T, inter_numeric = TRUE)


columns <- c("event_id_cnty","event_date","year","time_precision","disorder_type",
Expand All @@ -32,11 +32,11 @@ received_data_country_and_region <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_
regions = "Central America",
start_date="2022-01-01",
end_date = "2022-12-31",
prompt = F, acled_access = F)
prompt = F, acled_access = F, inter_numeric = TRUE)

received_data_country_and_region_num <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country = "Argentina",
regions = 14,
start_date="2022-01-01",
end_date = "2022-12-31",
prompt = F, acled_access = F)
prompt = F, acled_access = F, inter_numeric = TRUE)
2 changes: 1 addition & 1 deletion tests/testthat/setup-acled_transform_interaction.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country = "Argentina", start_date="2022-01-01",end_date = "2022-12-31",
prompt = F, acled_access = F, log = F)
prompt = F, acled_access = F, log = F, inter_numeric = TRUE)

test_changes <- test %>%
left_join(acledR::acled_interaction_codes, by = c("inter1" = "Numeric Code")) %>%
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-acled_access.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Does it save the credentials in the enviornment? - Missing

test_that("acled_access properly stores the credentials", {
expect_equal(Sys.getenv("acled_email"),"[email protected]")
# expect_equal(Sys.getenv("acled_email"),"[email protected]")
expect_equal(Sys.getenv("acled_email"),"[email protected]")
expect_equal(nchar(Sys.getenv("acled_key")), 20)
})

Expand Down
58 changes: 30 additions & 28 deletions tests/testthat/test-acled_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("event_type filters work or not",{

expect_equal(unique(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31", country = "Argentina",
event_type = "Protests", prompt = F, acled_access = F, log = F)$event_type), "Protests" )
event_type = "Protests", prompt = F, acled_access = F, log = F, inter_numeric = TRUE)$event_type), "Protests" )

})

Expand All @@ -31,7 +31,7 @@ test_that("country days are calculated as expected",{

argentina_test_call <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country = "Argentina", start_date="1998-01-01",
end_date = "2021-01-01",prompt = F, acled_access = F, log = T)
end_date = "2021-01-01",prompt = F, acled_access = F, log = T, inter_numeric = TRUE)

expect_equal(argentina_test_call$time, argentina_country_days$unit_test)

Expand All @@ -45,9 +45,10 @@ local({

expect_equal(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
prompt = T, acled_access = F, log = F), acled_api(email = "[email protected]", key = "M3PWwg3DIdhHMuDiilp5",
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
prompt = F, acled_access = F, log = F))
prompt = T, acled_access = F, log = F, inter_numeric = TRUE),
acled_api(Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
prompt = F, acled_access = F, log = F, inter_numeric = TRUE))
})
}) # test on whether they can continue

Expand Down Expand Up @@ -100,7 +101,8 @@ local({

expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
timestamp = "muchachos", prompt = F, acled_access = F, log = F), regexp = "User requested")
timestamp = "muchachos", prompt = F, acled_access = F, log = F, inter_numeric = TRUE),
regexp = "User requested")
})
})

Expand All @@ -112,7 +114,7 @@ local({

expect_no_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
start_date="2022-01-01",end_date = "2022-12-31",country = "Argentina",
timestamp = "muchachos", prompt = F, acled_access = F, log = F))
timestamp = "muchachos", prompt = F, acled_access = F, log = F, inter_numeric = TRUE))
})
})

Expand All @@ -138,11 +140,11 @@ test_that("Population columns are being received", {

received_data_pops <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country="Argentina", start_date="2022-01-01",end_date = "2022-01-04",
population='full',prompt = F, acled_access = F)
population='full', prompt = F, acled_access = F, inter_numeric = TRUE)

received_data_best <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
country="Argentina", start_date="2022-01-01",end_date = "2022-01-04",
population='best',prompt = F, acled_access = F)
population='best',prompt = F, acled_access = F, inter_numeric = TRUE)


expect_true(all(population_cols %in% colnames(received_data_pops)))
Expand All @@ -158,25 +160,25 @@ test_that("Population columns are being received", {

test_that("Error prompted when region does not exist", {
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = "Narnia",
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F), regexp = "One or more requested region names not in the ACLED country list.")
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F, inter_numeric = TRUE), regexp = "One or more requested region names not in the ACLED country list.")
})

test_that("Error when region number does not exist", {
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),regions = 420,
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F),
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F, inter_numeric = TRUE),
regexp = "One or more requested region numbers not in the ACLED country list")
})


## Errors when a country requested doesnt exists ----
test_that("Error when one of two countries are wrong",{
expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),country = c("Argentia","Bolivia"),
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F),
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F, inter_numeric = TRUE),
regexp = "One or more of the requested *")})

## Test what happens when someone inputs acled_access as TRUE but it includes email and key. ----
test_that("Acled_access is ignored",{
expect_true(grepl("acledexamples", log_received_data_check_credential$email[1]))
expect_true(grepl("t.billing", log_received_data_check_credential$email[1]))
})

# Test errors from incorrectly input arguments. ----
Expand All @@ -188,7 +190,7 @@ test_that("acled_api() throws an error when called with invalid arguments", {
end_date = "2022-12-31",
prompt = F,
acled_access = T,
log = F), regexp=
log = F, inter_numeric = TRUE), regexp=
"Country is not a valid option. Please utilize \"country\", without capitalizing")


Expand All @@ -198,7 +200,7 @@ test_that("acled_api() throws an error when called with invalid arguments", {
end_date = "2022-12-31",
prompt = F,
acled_access = T,
log = F), regexp=
log = F, inter_numeric = TRUE), regexp=
"Region is not a valid option. Please utilize \"regions\"")

expect_error(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
Expand All @@ -207,26 +209,26 @@ test_that("acled_api() throws an error when called with invalid arguments", {
end_date = "2022-12-31",
prompt = F,
acled_access = T,
log = F), regexp=
log = F, inter_numeric = TRUE), regexp=
"Regions is not a valid option. Please utilize \"regions\", without capitalizing")

expect_error(acled_api(Event_type = "Argentina",
start_date="2022-01-01",
end_date = "2022-12-31",
prompt = F,
acled_access = T), regexp=
acled_access = T, inter_numeric = TRUE), regexp=
"Event type is not a valid option. Please utilize \"event_types\", without capitalizing")
expect_error(acled_api(country = "Argentina",
Start_date="2022-01-01",
end_date = "2022-12-31",
prompt = F,
acled_access = T), regexp=
acled_access = T, inter_numeric = TRUE), regexp=
"Start_date is not a valid option. Please utilize \"start_date\", without capitalizing")
expect_error(acled_api(country = "Argentina",
start_date="2022-01-01",
End_date = "2022-12-31",
prompt = F,
acled_access = T), regexp=
acled_access = T, inter_numeric = TRUE), regexp=
"End_date is not a valid option. Please utilize \"end_date\", without capitalizing")
})

Expand All @@ -239,16 +241,16 @@ test_that("If access is TRUE and credentials are null, credentials are ignored,
end_date = "2022-12-31",
prompt = F,
acled_access = T,
log = F), regexp = "acled_access is TRUE, but email and/or key are not stored in the enviornment. Please rerun acled_access or include key and email in function")
log = F, inter_numeric = TRUE), regexp = "acled_access is TRUE, but email and/or key are not stored in the enviornment. Please rerun acled_access or include key and email in function")
})

test_that("Users gets an error when acled_access is False, but no key or email are provided.", {

expect_error(acled_api(country = "Argentina", start_date="2022-01-01",
end_date = "2022-12-31", prompt = F, acled_access = F), regexp = "Email address required")
end_date = "2022-12-31", prompt = F, acled_access = F, inter_numeric = TRUE), regexp = "Email address required")

expect_error(acled_api(email = "stuff",country = "Argentina", start_date="2022-01-01",
end_date = "2022-12-31", prompt = F, acled_access = F), regexp = "Key required")
end_date = "2022-12-31", prompt = F, acled_access = F, inter_numeric = TRUE), regexp = "Key required")



Expand All @@ -264,7 +266,7 @@ test_that("start_date is after end_date", {
end_date = "2021-01-01",
prompt = F,
acled_access = F,
log = F), regexp = "Requested \'start_date\'")})
log = F, inter_numeric = TRUE), regexp = "Requested \'start_date\'")})

# Error when timestamp is from a date later than today ----

Expand All @@ -277,7 +279,7 @@ test_that("timestamp is from a latter date than today." ,{
prompt = F,
acled_access = F,
timestamp = paste0(year(now())+1, "01-01"), # Way to make it always in the future
log = F), regexp = "The timestamp cannot be" )
log = F, inter_numeric = TRUE), regexp = "The timestamp cannot be" )
})

# Error when requesting non-existent event types ----
Expand All @@ -290,20 +292,20 @@ test_that("Error when non existent event types",{
event_types = c("Protests","Superhero fight"),
prompt = F,
acled_access = F,
log = F), regexp = "One or more requested event types are not in the ACLED data.")
log = F, inter_numeric = TRUE), regexp = "One or more requested event types are not in the ACLED data.")
})

# A message appears that acled_access is being ignored, and the proper credentials are being used.----

test_that("A warning appears that acled_access is being ignored, and the proper credentials are being used.",{

alog <- acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
acled_access = T, log = T)
acled_access = T, log = T, inter_numeric = TRUE)

expect_message(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
acled_access = T, log = T), regexp = "acled_access is TRUE, but email and key are included in the function. Ignoring acled_access.")
acled_access = T, log = T, inter_numeric = TRUE), regexp = "acled_access is TRUE, but email and key are included in the function. Ignoring acled_access.")

expect_true(grepl("acledexamples", alog$email[1]))
expect_true(grepl("t.billing", alog$email[1]))
})


Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-acled_deletions_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_that("names of columns are correct - unix", {
## Test that email and key are handled appropiately ----

test_that("Email and key are handled as expected without acled_access",{
expect_true(grepl("acledexamples", received_deleted_log$email[1]))}
expect_true(grepl("t.billing", received_deleted_log$email[1]))}
)

## Test that acled_access is handled appropiately. ----
Expand All @@ -32,7 +32,7 @@ test_that("Email and Key are handled appropiately",{

some_log <- acled_deletions_api(date_deleted = "1658707200", acled_access = T, log = T)

expect_true(grepl("acledexamples", some_log$email[1]))}
expect_true(grepl("t.billing", some_log$email[1]))}
)

## Date and unix return the same output ----
Expand Down Expand Up @@ -90,7 +90,7 @@ test_that("A warning appears that acled_access is being ignored, and the proper
expect_message(acled_deletions_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
date_deleted = "1658707200",acled_access = T, log = T), regexp = "acled_access is TRUE, but email and key are included in the function. Ignoring acled_access.")

expect_true(grepl("acledexamples", alog$email[1]))
expect_true(grepl("[email protected]", alog$email[1]))
})


Expand Down
Loading
Loading