inbo / etn

R package to access data from the European Tracking Network
https://inbo.github.io/etn/
MIT License
6 stars 5 forks source link

316 use etnservice as a dependency and drop sql helpers #317

Open PietrH opened 1 month ago

PietrH commented 1 month ago

When I first started working on this, I didn't implement the changes to the helper immediately, but rather experimented in a single function: b03e88f86b1c8145343945666e4530e7d67d88f7, later on I moved this change to the forward_to_api() helper, meaning that a lot of lines can be removed. All this code still exists of course, just in etnservice instead of here as a duplicate.

From this PR onward, the API and local database connection should always return exactly the same result, any differences resulting from unintended type parsing should be considered a bug.

It seems not all the changes from v2.3 are present in this branch, namely the vignettes.

API - SQL mismatch

mismatches for:

get_cpod_projects

[1] "get_cpod_projects"
Error: `api_result` (`actual`) not identical to `sql_result` (`expected`).

`actual$moratorium` is a character vector ('0', '1', '1', '1', '0', ...)
`expected$moratorium` is a logical vector (FALSE, TRUE, TRUE, TRUE, FALSE, ...)

list_animal_ids: missing animal ID

56314 known id is missing from both the API and SQL result, I've sent an email to Claudia

PietrH commented 1 month ago

Should we have a seperate test file that checks if the API and SQL return the same results? Or should these tests be included in the function test files?

I'm quite tempted to use:

for(function_to_test in getNamespaceExports("etnservice")) {
  test_that(paste(
    function_to_test,
    "returns same result over api as over local db connection"
  ),
  {
    skip_if_offline()

    api_result <- do.call(function_to_test, list(api = TRUE))
    sql_result <- do.call(function_to_test, list(api = FALSE))
    expect_identical(api_result, sql_result, label = function_to_test)
  })
}

But not all functions run without arguments (returned objects too large?)

peterdesmet commented 1 month ago

Maybe this is a good use case for a custom expectation.

For example, you could create a expect_call_agnostic(), with one argument: a function call. The helper could grab the function call (and its arguments), run it locally and over API and expect the result to be the same.

It could then be called as part of a regular test-function.R file:


testthat("get_animals() returns same result locally and via API", {
  expect_call_agnostic(get_animals(animal_id = "5"))
})
PietrH commented 1 month ago

That sounds great! Do you think we should include that here, or rather as a separate PR?

PietrH commented 1 month ago

9 functions currently fail to return the same result over the api as over a local connection.

peterdesmet commented 1 month ago

That sounds great! Do you think we should include that here, or rather as a separate PR?

I'll leave that to you

PietrH commented 1 month ago

Ready for review, this is a merge to the next release branch. There will be R CMD Check errors due to a mismatch between the API and SQL returned results, apart from that, it should work!

Quite a nice reduction, this will make keeping etn and etnservice in sync much much easier :sunflower:

PietrH commented 1 month ago

I have dropped a number of dependencies and helpers that are now unused (they were moved to etnservice)

PietrH commented 2 weeks ago

That sounds great! Do you think we should include that here, or rather as a separate PR?

I'll leave that to you

This is going to take more work than I want to tackle in this PR, so I'll leave it like it is here. Issue #330