forked from nasa/python_cmr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tool.py
87 lines (60 loc) · 2.6 KB
/
test_tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import unittest
from cmr.queries import ToolQuery
class TestToolClass(unittest.TestCase):
def test_name(self):
query = ToolQuery()
query.name("name")
self.assertIn("name", query.params)
self.assertEqual(query.params["name"], "name")
def test_provider(self):
query = ToolQuery()
query.provider("provider")
self.assertIn("provider", query.params)
self.assertEqual(query.params["provider"], "provider")
def test_native_id(self):
query = ToolQuery()
query.native_id("native_id")
self.assertIn("native_id", query.params)
self.assertEqual(query.params["native_id"], ["native_id"])
def test_native_ids(self):
query = ToolQuery()
query.native_id(["native_id1", "native_id2"])
self.assertIn("native_id", query.params)
self.assertEqual(query.params["native_id"], ["native_id1", "native_id2"])
def test_valid_formats(self):
query = ToolQuery()
formats = [
"json", "xml", "echo10", "iso", "iso19115",
"csv", "atom", "kml", "native", "dif", "dif10",
"opendata", "umm_json", "umm_json_v1_1" "umm_json_v1_9"]
for _format in formats:
query.format(_format)
self.assertEqual(query._format, _format)
def test_invalid_format(self):
query = ToolQuery()
with self.assertRaises(ValueError):
query.format("invalid")
query.format("jsonn")
query.format("iso19116")
def test_valid_concept_id(self):
query = ToolQuery()
query.concept_id("T1299783579-LPDAAC_ECS")
self.assertEqual(query.params["concept_id"], ["T1299783579-LPDAAC_ECS"])
query.concept_id(["T1299783579-LPDAAC_ECS", "T1441380236-PODAAC"])
self.assertEqual(query.params["concept_id"], ["T1299783579-LPDAAC_ECS", "T1441380236-PODAAC"])
def test_invalid_concept_id(self):
query = ToolQuery()
with self.assertRaises(ValueError):
query.concept_id("G1327299284-LPDAAC_ECS")
with self.assertRaises(ValueError):
query.concept_id(["C1299783579-LPDAAC_ECS", "G1327299284-LPDAAC_ECS"])
def test_token(self):
query = ToolQuery()
query.token("123TOKEN")
self.assertIn("Authorization", query.headers)
self.assertEqual(query.headers["Authorization"], "123TOKEN")
def bearer_test_token(self):
query = ToolQuery()
query.bearer_token("123TOKEN")
self.assertIn("Authorization", query.headers)
self.assertEqual(query.headers["Authorization"], "Bearer 123TOKEN")