Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
ISSUE-147 Implement integration tests for drive.py (#148)
Browse files Browse the repository at this point in the history
* ISSUE-147 Implement integration tests for drive.py
  • Loading branch information
lewismc committed Aug 5, 2019
1 parent 97ecf31 commit 9fa161c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ doc.txt

# Example files
examples/*.nc

# Test drive data
podaac/tests/allData
podaac/*.zip
6 changes: 3 additions & 3 deletions examples/Using podaacpy to interact with PO.DAAC Drive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
" process_level='2', \n",
" bbox='-81,28,-67,40', \n",
" pretty='True', \n",
" format='atom', \n",
" _format='atom', \n",
" full='True')\n",
"print(ds_result)"
]
Expand Down Expand Up @@ -143,7 +143,7 @@
" bbox='-81,28,-67,40',\n",
" sort_by='timeAsc',\n",
" items_per_page='400',\n",
" format='atom',\n",
" _format='atom',\n",
" pretty='True')\n",
"#print(result)\n",
"searchStr = 'totalResults'\n",
Expand Down Expand Up @@ -271,7 +271,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions examples/podaac.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[drive]
urs_username = podaacdemo
urs_password = ZAnTpYoP9bgHnHb5UClG
urs_username = podaacpy
urs_password = hZHYQ17yuag25zivK8F
webdav_url = https://podaac-tools.jpl.nasa.gov/drive/files
18 changes: 10 additions & 8 deletions podaac/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ def __init__(self, file, username, password, webdav_url='https://podaac-tools.jp
'''
config = configparser.ConfigParser()
if file:
config.read_file(open(file, 'r'))
else:
config.read('podaac.ini')
self.USERNAME = config['drive']['urs_username']
self.PASSWORD = config['drive']['urs_password']
self.URL = config['drive']['webdav_url']
config_file_path = os.path.join(os.path.dirname(__file__), "tests", file)
config.read_file(open(config_file_path, 'r'))
self.USERNAME = config['drive']['urs_username']
self.PASSWORD = config['drive']['urs_password']
self.URL = config['drive']['webdav_url']
if username:
self.USERNAME = username
if password:
Expand Down Expand Up @@ -88,7 +87,6 @@ def download_granules(self, granule_collection=None, path=''):

for granule_url in granule_collection:
directory_structure, granule = os.path.split(granule_url[46:])
print(directory_structure + ":" + granule)
granule_name = os.path.splitext(granule)[0]
if path == '':
granule_path = os.path.join(os.path.dirname(__file__), directory_structure)
Expand All @@ -97,7 +95,11 @@ def download_granules(self, granule_collection=None, path=''):
r = requests.get(granule_url, auth=HTTPBasicAuth(self.USERNAME, self.PASSWORD), stream=True)
if r.status_code != 200:
raise PermissionError("Granule: '%s' not downloaded. Please check authentication configuration and try again." % (granule))
os.makedirs(granule_path, exist_ok=True)
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path # python 2 backport
Path(granule_path).mkdir(parents=True, exist_ok=True)
with open(granule_path + "/" + granule, 'wb') as f:
for chunk in r:
f.write(chunk)
Expand Down
2 changes: 1 addition & 1 deletion podaac/oceancolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def file_search(self, sensor='', sdate='', edate='', dtype='', add_url='1', resu
print(error)
raise

return response.text
return str(response.text)

def get_file(self, url='', path=''):
'''It is possible to mimic FTP bulk data downloads using the \
Expand Down
41 changes: 41 additions & 0 deletions podaac/tests/drive_test.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion podaac/tests/oceancolor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_file_search(self):
dtype='L3b', add_url='1', results_as_file='1', search='*DAY_CHL*')

assert data != None
print(data)
assert isinstance(data, str)
assert len(data) != 0

Expand Down
4 changes: 4 additions & 0 deletions podaac/tests/podaac.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[drive]
urs_username = podaacpy
urs_password = hZHYQ17yuag25zivK8F
webdav_url = https://podaac-tools.jpl.nasa.gov/drive/files
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
]
_description = 'PO.DAAC Python API'
_download_url = 'http:https://pypi.python.org/pypi/podaacpy/'
_requirements = ["beautifulsoup4", "configparser", "defusedxml", "future", "requests"]
_requirements = ["beautifulsoup4", "configparser", "defusedxml", "future", "pathlib2", "requests"]
_keywords = ['dataset', 'granule', 'compliance', 'nasa', 'jpl', 'podaac']
_license = 'Apache License, Version 2.0'
_long_description = 'A python utility library for interacting with NASA JPLs PO.DAAC'
Expand Down

1 comment on commit 9fa161c

@noah-de
Copy link
Collaborator

@noah-de noah-de commented on 9fa161c Aug 5, 2019

Choose a reason for hiding this comment

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

Thanks for your quick work on this.
Sorry I couldn't be a more helpful reviewer today.

Please sign in to comment.