|
2 | 2 | import pytest |
3 | 3 | import responses |
4 | 4 | import six |
| 5 | +import os |
5 | 6 |
|
6 | 7 | from opus.api import API |
7 | | -from opus.cli import read, data, metadata |
| 8 | +from opus.cli import read, data, metadata, image |
8 | 9 |
|
9 | 10 |
|
10 | 11 | @pytest.fixture |
@@ -101,3 +102,49 @@ def test_cli_metadata(api): |
101 | 102 | assert responses.calls[0].response.text == json |
102 | 103 |
|
103 | 104 | assert resp.ring_obs_id == 'S_IMG_CO_ISS_1459551972_N' |
| 105 | + |
| 106 | + |
| 107 | +@responses.activate |
| 108 | +def test_cli_image(api): |
| 109 | + img = open('tests/api/image/med/S_IMG_CO_ISS_1459551972_N.json', 'r').read() |
| 110 | + responses.add(responses.GET, |
| 111 | + 'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json', |
| 112 | + body=img) |
| 113 | + |
| 114 | + argv = ['S_IMG_CO_ISS_1459551972_N', '--size', 'med'] |
| 115 | + resp = image(argv, api=api) |
| 116 | + |
| 117 | + assert len(responses.calls) == 1 |
| 118 | + assert responses.calls[0].request.url == 'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json' |
| 119 | + assert responses.calls[0].response.text == img |
| 120 | + |
| 121 | + assert resp == 'https://pds-rings.seti.org/holdings/previews/COISS_2xxx/COISS_2001/data/1459551663_1459568594/N1459551972_1_med.jpg' |
| 122 | + |
| 123 | + |
| 124 | +@responses.activate |
| 125 | +def test_cli_image_download(api): |
| 126 | + fname = 'N1459551972_1_med.jpg' |
| 127 | + jpg = 'https://pds-rings.seti.org/holdings/previews/COISS_2xxx/COISS_2001/data/1459551663_1459568594/N1459551972_1_med.jpg' |
| 128 | + |
| 129 | + img = open('tests/api/image/med/S_IMG_CO_ISS_1459551972_N.json', 'r').read() |
| 130 | + responses.add(responses.GET, |
| 131 | + 'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json', |
| 132 | + body=img) |
| 133 | + |
| 134 | + with open('tests/api/image/med/'+fname, 'rb') as img: |
| 135 | + responses.add(responses.GET, jpg, |
| 136 | + body=img.read(), status=200, |
| 137 | + content_type='image/jpeg', |
| 138 | + stream=True |
| 139 | + ) |
| 140 | + |
| 141 | + argv = ['S_IMG_CO_ISS_1459551972_N', '--output', 'tests/test.jpg'] |
| 142 | + resp = image(argv, api=api) |
| 143 | + |
| 144 | + assert len(responses.calls) == 2 |
| 145 | + assert responses.calls[0].request.url == 'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json' |
| 146 | + assert responses.calls[1].request.url == jpg |
| 147 | + |
| 148 | + assert resp == 'tests/test.jpg' |
| 149 | + assert os.path.isfile('tests/test.jpg') |
| 150 | + os.remove('tests/test.jpg') |
0 commit comments