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

Commit 9fa161c

Browse files
authored
ISSUE-147 Implement integration tests for drive.py (#148)
* ISSUE-147 Implement integration tests for drive.py
1 parent 97ecf31 commit 9fa161c

9 files changed

+66
-16
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ doc.txt
7474

7575
# Example files
7676
examples/*.nc
77+
78+
# Test drive data
79+
podaac/tests/allData
80+
podaac/*.zip

examples/Using podaacpy to interact with PO.DAAC Drive.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
" process_level='2', \n",
109109
" bbox='-81,28,-67,40', \n",
110110
" pretty='True', \n",
111-
" format='atom', \n",
111+
" _format='atom', \n",
112112
" full='True')\n",
113113
"print(ds_result)"
114114
]
@@ -143,7 +143,7 @@
143143
" bbox='-81,28,-67,40',\n",
144144
" sort_by='timeAsc',\n",
145145
" items_per_page='400',\n",
146-
" format='atom',\n",
146+
" _format='atom',\n",
147147
" pretty='True')\n",
148148
"#print(result)\n",
149149
"searchStr = 'totalResults'\n",
@@ -271,7 +271,7 @@
271271
"name": "python",
272272
"nbconvert_exporter": "python",
273273
"pygments_lexer": "ipython3",
274-
"version": "3.6.5"
274+
"version": "3.7.4"
275275
}
276276
},
277277
"nbformat": 4,

examples/podaac.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[drive]
2-
urs_username = podaacdemo
3-
urs_password = ZAnTpYoP9bgHnHb5UClG
2+
urs_username = podaacpy
3+
urs_password = hZHYQ17yuag25zivK8F
44
webdav_url = https://podaac-tools.jpl.nasa.gov/drive/files

podaac/drive.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ def __init__(self, file, username, password, webdav_url='https://podaac-tools.jp
3030
'''
3131
config = configparser.ConfigParser()
3232
if file:
33-
config.read_file(open(file, 'r'))
34-
else:
35-
config.read('podaac.ini')
36-
self.USERNAME = config['drive']['urs_username']
37-
self.PASSWORD = config['drive']['urs_password']
38-
self.URL = config['drive']['webdav_url']
33+
config_file_path = os.path.join(os.path.dirname(__file__), "tests", file)
34+
config.read_file(open(config_file_path, 'r'))
35+
self.USERNAME = config['drive']['urs_username']
36+
self.PASSWORD = config['drive']['urs_password']
37+
self.URL = config['drive']['webdav_url']
3938
if username:
4039
self.USERNAME = username
4140
if password:
@@ -88,7 +87,6 @@ def download_granules(self, granule_collection=None, path=''):
8887

8988
for granule_url in granule_collection:
9089
directory_structure, granule = os.path.split(granule_url[46:])
91-
print(directory_structure + ":" + granule)
9290
granule_name = os.path.splitext(granule)[0]
9391
if path == '':
9492
granule_path = os.path.join(os.path.dirname(__file__), directory_structure)
@@ -97,7 +95,11 @@ def download_granules(self, granule_collection=None, path=''):
9795
r = requests.get(granule_url, auth=HTTPBasicAuth(self.USERNAME, self.PASSWORD), stream=True)
9896
if r.status_code != 200:
9997
raise PermissionError("Granule: '%s' not downloaded. Please check authentication configuration and try again." % (granule))
100-
os.makedirs(granule_path, exist_ok=True)
98+
try:
99+
from pathlib import Path
100+
except ImportError:
101+
from pathlib2 import Path # python 2 backport
102+
Path(granule_path).mkdir(parents=True, exist_ok=True)
101103
with open(granule_path + "/" + granule, 'wb') as f:
102104
for chunk in r:
103105
f.write(chunk)

podaac/oceancolor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def file_search(self, sensor='', sdate='', edate='', dtype='', add_url='1', resu
114114
print(error)
115115
raise
116116

117-
return response.text
117+
return str(response.text)
118118

119119
def get_file(self, url='', path=''):
120120
'''It is possible to mimic FTP bulk data downloads using the \

podaac/tests/drive_test.py

+41
Large diffs are not rendered by default.

podaac/tests/oceancolor_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def test_file_search(self):
3030
dtype='L3b', add_url='1', results_as_file='1', search='*DAY_CHL*')
3131

3232
assert data != None
33-
print(data)
3433
assert isinstance(data, str)
3534
assert len(data) != 0
3635

podaac/tests/podaac.ini

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[drive]
2+
urs_username = podaacpy
3+
urs_password = hZHYQ17yuag25zivK8F
4+
webdav_url = https://podaac-tools.jpl.nasa.gov/drive/files

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
]
3535
_description = 'PO.DAAC Python API'
3636
_download_url = 'http://pypi.python.org/pypi/podaacpy/'
37-
_requirements = ["beautifulsoup4", "configparser", "defusedxml", "future", "requests"]
37+
_requirements = ["beautifulsoup4", "configparser", "defusedxml", "future", "pathlib2", "requests"]
3838
_keywords = ['dataset', 'granule', 'compliance', 'nasa', 'jpl', 'podaac']
3939
_license = 'Apache License, Version 2.0'
4040
_long_description = 'A python utility library for interacting with NASA JPLs PO.DAAC'

0 commit comments

Comments
 (0)