Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
John Waller committed Apr 22, 2024
1 parent 5309b4f commit b88de0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pygbif/occurrences/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __init__(self, creator, email, polygon=None):
self.predicates = []
self._main_pred_type = "and"
self._predicate = {"type": self._main_pred_type, "predicates": self.predicates}
# self._verbatim_extensions = None
self._verbatim_extensions = None

self.url = "http://api.gbif.org/v1/occurrence/download/request"
self.header = {
Expand Down Expand Up @@ -376,7 +376,7 @@ def verbatim_extensions(self, value):
self._verbatim_extensions = value
self.payload["verbatimExtensions"] = self._verbatim_extensions
else:
raise Exception("verbatim extensions can only be used with the DWCA format")
raise Exception("verbatim_extensions can only be used with the DWCA format")

@property
def format(self):
Expand Down
18 changes: 18 additions & 0 deletions test/test-occurrences-download_request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import requests
import unittest
import pytest

from pygbif.occurrences.download import GbifDownload, download

Expand Down Expand Up @@ -195,3 +196,20 @@ def test_geometry_predicate(self):
payload["predicate"]["predicates"][0],
{"type": "within", "geometry": "POLYGON((-82.7 36.9, -85.0 35.6, -81.0 33.5, -79.4 36.3, -79.4 36.3, -82.7 36.9))"},
)

def test_verbatim_extension(self):
dl_key, payload = download(
["taxonKey = 1"], user="dummy", email="dummy", pwd="dummy", format="DWCA", verbatim_extensions = ["http://rs.tdwg.org/ac/terms/Multimedia","http://data.ggbn.org/schemas/ggbn/terms/Amplification"]
)

self.assertListEqual(
payload["verbatimExtensions"],
["http://rs.tdwg.org/ac/terms/Multimedia","http://data.ggbn.org/schemas/ggbn/terms/Amplification"],
)

def test_verbatim_extension_fails_well(self):
with self.assertRaisesRegex(Exception, "verbatim_extensions can only be used with the DWCA format"):
dl_key, payload = download(
["taxonKey = 1"], user="dummy", email="dummy", pwd="dummy", format="SIMPLE_CSV", verbatim_extensions = ["http://rs.tdwg.org/ac/terms/Multimedia","http://data.ggbn.org/schemas/ggbn/terms/Amplification"]
)

0 comments on commit b88de0b

Please sign in to comment.