Skip to content

Commit

Permalink
Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBillson committed Feb 17, 2024
1 parent 87d849d commit b381719
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function authenticate_download()
throw(e)
end
end
(status_code != 200) && throw(ArgumentError("Authentication failed with code $(status_code)!"))
(status_code != 200) && throw(ErrorException("Authentication failed with code $(status_code)!"))

# Make Sure to Logout on Exit
if !("earthexplorer.usgs.gov" in keys(HTTP.COOKIEJAR.entries))
Expand All @@ -86,12 +86,6 @@ function authenticate_download()
HTTP.COOKIEJAR.entries["ers.cr.usgs.gov"] = Dict{String, HTTP.Cookies.Cookie}()
end

# Returns true if logged in to the download API
function logged_in()
cookies = get(HTTP.COOKIEJAR.entries, "earthexplorer.usgs.gov", nothing)
!isnothing(cookies) && "usgs.gov;/;EROS_SSO_production_secure" in keys(cookies)
end

"""
logout()
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ roi = [

# Test Zero Results
@test_throws ErrorException search("LANDSAT_9", 2, dates=dates, geom=bb)

# Test Authentication with Bad Credentials
old_pass = ENV["LANDSAT_EXPLORER_PASS"]
authenticate(ENV["LANDSAT_EXPLORER_USER"], "fail")
@test_throws ErrorException LE.api_authenticate()
@test_throws ErrorException LE.authenticate_download()
authenticate(ENV["LANDSAT_EXPLORER_USER"], old_pass)

# Test Download
logout()
Expand Down

0 comments on commit b381719

Please sign in to comment.