diff --git a/Project.toml b/Project.toml index 6c5e463..26d19c9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GBIF" uuid = "ee291a33-5a6c-5552-a3c8-0f29a1181037" authors = ["Timothée Poisot "] -version = "0.3.2" +version = "0.3.3" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -14,11 +14,3 @@ HTTP = "0.8, 0.9" JSON = "0.21" Requires = "1.0" julia = "1.3" - -[extras] -DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Test", "DataFrames", "Query"] diff --git a/src/paging.jl b/src/paging.jl index 7995cb6..6cc2761 100644 --- a/src/paging.jl +++ b/src/paging.jl @@ -13,7 +13,7 @@ function _internal_limit_update!(o::GBIFRecords) limit_index = findfirst((p) -> string(p.first) == "limit", o.query) limit = isnothing(limit_index) ? 20 : o.query[limit_index].second if (length(o) + limit) > size(o) - deleteat!(o.query, limit_index) + isnothing(limit_index) || deleteat!(o.query, limit_index) push!(o.query, "limit" => size(o) - length(o)) end end diff --git a/src/requires/dataframes.jl b/src/requires/dataframes.jl index 59c5b36..e01aa1f 100644 --- a/src/requires/dataframes.jl +++ b/src/requires/dataframes.jl @@ -1,6 +1,6 @@ @info "Loading DataFrames support for GBIF.jl" -format_gbif_entity(t::Missing) = missing +format_gbif_entity(::Missing) = missing format_gbif_entity(t::Pair{String,Int64}) = t.first import .DataFrames: DataFrame diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..7b1419d --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,4 @@ +[deps] +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/occurrences.jl b/test/occurrences.jl index b829abb..c8632a7 100644 --- a/test/occurrences.jl +++ b/test/occurrences.jl @@ -1,21 +1,36 @@ module TestGBIFRecords - using GBIF - using Test +using GBIF +using Test - # Version using pairs - set1 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true) - @test typeof(set1) == GBIFRecords - @test length(set1) == 20 +# Version using pairs +set1 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true) +@test typeof(set1) == GBIFRecords +@test length(set1) == 20 - # Version with no query parameters - set2 = occurrences() - @test typeof(set2) == GBIFRecords - @test length(set2) == 20 +# Version with no query parameters +set2 = occurrences() +@test typeof(set2) == GBIFRecords +@test length(set2) == 20 - # Version using ranged pairs - set3 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true, "decimalLatitude" => (0.0,50.0)) - @test typeof(set3) == GBIFRecords - @test length(set3) == 20 +# Version using ranged pairs +set3 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true, "decimalLatitude" => (0.0, 50.0)) +@test typeof(set3) == GBIFRecords +@test length(set3) == 20 + +# Version with the full query - this one has about 250 records +serval = GBIF.taxon("Leptailurus serval", strict=true) +obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40)) +while length(obs) < size(obs) + occurrences!(obs) +end +@test length(obs) == size(obs) + +# Version with the full query AND a set page size - this one has about 250 records +obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40), "limit" => 45) +while length(obs) < size(obs) + occurrences!(obs) +end +@test length(obs) == size(obs) end