Skip to content

Commit

Permalink
Fix the GBIF issue for single argument queries (#166)
Browse files Browse the repository at this point in the history
* 🐛add tests to capture #165

* update README

* ✅ fix a bug due to GBIF re-adding a formerly missing occurrence

* ⚠️  add error when the value is not part of the enum key

* 🐛 update the imported modules for edgecase test

* ℹ️ add a temporary log to see the query string

* ✅ the tests are passing

Closes #165
  • Loading branch information
tpoisot authored Apr 16, 2023
1 parent ff4a23e commit ce74a0a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion GBIF/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GBIF"
uuid = "ee291a33-5a6c-5552-a3c8-0f29a1181037"
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.4.1"
version = "0.4.2"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
5 changes: 3 additions & 2 deletions GBIF/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# GBIF wrapper for Julia

This is project offers an interface to the [GBIF] search API from
This is project offers an interface to the GBIF search API from
Julia. Current efforts focus on querying and exporting occurrences through the
`occurrence/search` endpoint. There is partial support for the taxonomic API.

The recommended way to use this package is through the
`SpeciesDistributionToolkit` package.
`SpeciesDistributionToolkit` package, which will transparently export all of the
`GBIF` types and methods.
5 changes: 4 additions & 1 deletion GBIF/src/occurrence.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
format_querypair_stem(stem::Bool) = replace(string(stem), " " => "%20")
format_querypair_stem(stem::Any) = replace(string(stem), " " => "%20")

function format_querypair_stem(stem::Tuple{T, T}) where {T <: Number}
Expand Down Expand Up @@ -44,7 +45,9 @@ function occurrence(key::String)::GBIFRecord
return GBIFRecord(result)
catch err
if err isa HTTP.Exceptions.StatusError
throw("Occurrence $(key) (at $(occ_url)) cannot be accessed - error code: $(err.status)")
throw(
"Occurrence $(key) (at $(occ_url)) cannot be accessed - error code: $(err.status)",
)
else
throw("Occurrence $(key) cannot be accessed")
end
Expand Down
4 changes: 3 additions & 1 deletion GBIF/src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function validate_occurrence_query(query::Pair)

# ENUMs
if query.first keys(gbifenums)
@assert query.second gbifenums[query.first]
if !(query.second gbifenums[query.first])
@error "The value $(query.second) is not a valid value for $(query.first)"
end
end
end
13 changes: 13 additions & 0 deletions GBIF/test/edgecases.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module GBIFEdgeCasesTest
using Test
using GBIF

# When there is a single argument used for a query, sometimes the second position gets
# converted to not text
queryset = ["hasCoordinate" => true]
@test length(occurrences(queryset...)) > 0

queryset = ["hasCoordinate" => true]
@test length(occurrences(taxon("Alces alces"), queryset...)) > 0

end
5 changes: 3 additions & 2 deletions GBIF/test/occurrence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ o = occurrence(k)
@test o.key == k

# This occurrence has been deleted, so this needs some wrapping
k = 1258202889
@test_throws "cannot be accessed - error code" occurrence(k)
# It has been added back at some point
# k = 1258202889
# @test_throws "cannot be accessed - error code" occurrence(k)

# This occurrence is incorrectly formatted for some reason
k = 1039645472
Expand Down
1 change: 1 addition & 0 deletions GBIF/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tests = [
"methods" => "methods.jl",
"query support" => "query.jl",
"tables interface" => "tables.jl",
"edge cases" => "edgecases.jl",
]

for test in tests
Expand Down

2 comments on commit ce74a0a

@tpoisot
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir="GBIF"

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/81693

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a GBIF-v0.4.2 -m "<description of version>" ce74a0a7bfa9344454589722f6af4c10a6a32613
git push origin GBIF-v0.4.2

Please sign in to comment.