|
| 1 | +import unittest |
| 2 | + |
| 3 | +from cmr.queries import VariableQuery |
| 4 | + |
| 5 | +class TestVariableClass(unittest.TestCase): |
| 6 | + |
| 7 | + def test_name(self): |
| 8 | + query = VariableQuery() |
| 9 | + query.name("name") |
| 10 | + |
| 11 | + self.assertIn("name", query.params) |
| 12 | + self.assertEqual(query.params["name"], "name") |
| 13 | + |
| 14 | + def test_provider(self): |
| 15 | + query = VariableQuery() |
| 16 | + query.provider("provider") |
| 17 | + |
| 18 | + self.assertIn("provider", query.params) |
| 19 | + self.assertEqual(query.params["provider"], "provider") |
| 20 | + |
| 21 | + def test_native_id(self): |
| 22 | + query = VariableQuery() |
| 23 | + query.native_id("native_id") |
| 24 | + |
| 25 | + self.assertIn("native_id", query.params) |
| 26 | + self.assertEqual(query.params["native_id"], ["native_id"]) |
| 27 | + |
| 28 | + def test_native_ids(self): |
| 29 | + query = VariableQuery() |
| 30 | + query.native_id(["native_id1", "native_id2"]) |
| 31 | + |
| 32 | + self.assertIn("native_id", query.params) |
| 33 | + self.assertEqual(query.params["native_id"], ["native_id1", "native_id2"]) |
| 34 | + |
| 35 | + def test_valid_formats(self): |
| 36 | + query = VariableQuery() |
| 37 | + formats = [ |
| 38 | + "json", "xml", "echo10", "iso", "iso19115", |
| 39 | + "csv", "atom", "kml", "native", "dif", "dif10", |
| 40 | + "opendata", "umm_json", "umm_json_v1_1" "umm_json_v1_9"] |
| 41 | + |
| 42 | + for _format in formats: |
| 43 | + query.format(_format) |
| 44 | + self.assertEqual(query._format, _format) |
| 45 | + |
| 46 | + def test_invalid_format(self): |
| 47 | + query = VariableQuery() |
| 48 | + |
| 49 | + with self.assertRaises(ValueError): |
| 50 | + query.format("invalid") |
| 51 | + query.format("jsonn") |
| 52 | + query.format("iso19116") |
| 53 | + |
| 54 | + def test_valid_concept_id(self): |
| 55 | + query = VariableQuery() |
| 56 | + |
| 57 | + query.concept_id("V1299783579-LPDAAC_ECS") |
| 58 | + self.assertEqual(query.params["concept_id"], ["V1299783579-LPDAAC_ECS"]) |
| 59 | + |
| 60 | + query.concept_id(["V1299783579-LPDAAC_ECS", "V1441380236-PODAAC"]) |
| 61 | + self.assertEqual(query.params["concept_id"], ["V1299783579-LPDAAC_ECS", "V1441380236-PODAAC"]) |
| 62 | + |
| 63 | + def test_invalid_concept_id(self): |
| 64 | + query = VariableQuery() |
| 65 | + |
| 66 | + with self.assertRaises(ValueError): |
| 67 | + query.concept_id("G1327299284-LPDAAC_ECS") |
| 68 | + |
| 69 | + with self.assertRaises(ValueError): |
| 70 | + query.concept_id(["C1299783579-LPDAAC_ECS", "G1327299284-LPDAAC_ECS"]) |
| 71 | + |
0 commit comments