|
7 | 7 | import responses |
8 | 8 |
|
9 | 9 | from api.constants import ARCSECOND_API_URL_DEV |
10 | | -from arcsecond import ArcsecondConfig, DatasetUploadContext, DatasetFileUploader |
| 10 | +from arcsecond import ArcsecondConfig, DatasetUploadContext, DatasetFileUploader, AllSkyCameraImageUploadContext, \ |
| 11 | + AllSkyCameraImageFileUploader |
11 | 12 | from arcsecond.cloud.uploader.constants import Substatus, Status |
12 | 13 | from arcsecond.options import State |
13 | | -from tests.utils import prepare_successful_login, prepare_upload_files |
| 14 | +from tests.utils import prepare_successful_login, prepare_upload_files, prepare_upload_allskyimage |
14 | 15 |
|
15 | 16 |
|
16 | 17 | @responses.activate |
17 | | -def test_full_upload_process(): |
| 18 | +def test_full_upload_process_datafiles(): |
18 | 19 | dataset_uuid = str(uuid.uuid4()) |
19 | 20 | telescope_uuid = str(uuid.uuid4()) |
20 | 21 | org_subdomain = 'test-portal' |
@@ -76,3 +77,65 @@ def test_full_upload_process(): |
76 | 77 | assert status.value == Status.OK.value |
77 | 78 | assert substatus.value == Substatus.DONE.value |
78 | 79 | assert error is None |
| 80 | + |
| 81 | + |
| 82 | +@responses.activate |
| 83 | +def test_full_upload_process_allskyimages(): |
| 84 | + camera_uuid = str(uuid.uuid4()) |
| 85 | + org_subdomain = 'test-portal' |
| 86 | + |
| 87 | + prepare_successful_login(org_subdomain) |
| 88 | + prepare_upload_allskyimage(camera_uuid, org_subdomain) |
| 89 | + |
| 90 | + # file upload |
| 91 | + image_id = random.randint(1, 1000) |
| 92 | + responses.post( |
| 93 | + "/".join([ARCSECOND_API_URL_DEV, org_subdomain, 'allskycameraimages']) + "/", |
| 94 | + status=201, |
| 95 | + json={"status": "success", "id": image_id} |
| 96 | + ) |
| 97 | + # update metadata |
| 98 | + responses.patch( |
| 99 | + "/".join([ARCSECOND_API_URL_DEV, org_subdomain, 'allskycameraimages', str(image_id)]) + "/", |
| 100 | + status=200, |
| 101 | + json={"id": image_id} |
| 102 | + ) |
| 103 | + |
| 104 | + state = State(is_using_cli=False, verbose=False, api_name='cloud') |
| 105 | + config = { |
| 106 | + 'cloud': { |
| 107 | + 'username': 'dummy', |
| 108 | + 'upload_key': '1234', |
| 109 | + 'api_server': ARCSECOND_API_URL_DEV |
| 110 | + } |
| 111 | + } |
| 112 | + config = ArcsecondConfig(state, config) # it will read your config file. |
| 113 | + |
| 114 | + context = AllSkyCameraImageUploadContext( |
| 115 | + config, |
| 116 | + input_camera_uuid=camera_uuid, |
| 117 | + org_subdomain=org_subdomain |
| 118 | + ) |
| 119 | + |
| 120 | + context.validate() # important step to perform before uploading. |
| 121 | + fixtures_dir = Path(__file__).parent.parent.parent.parent / "fixtures" |
| 122 | + fixture_files = list(fixtures_dir.glob('*.fits')) |
| 123 | + |
| 124 | + for fixture_file in fixture_files: |
| 125 | + # Create a temporary directory and copy the fixture file there |
| 126 | + with tempfile.TemporaryDirectory() as temp_dir: |
| 127 | + temp_path = Path(temp_dir) / fixture_file.name |
| 128 | + shutil.copy(fixture_file, temp_path) |
| 129 | + |
| 130 | + # Use the actual file for uploading |
| 131 | + uploader = AllSkyCameraImageFileUploader( |
| 132 | + context, |
| 133 | + str(temp_dir), |
| 134 | + str(temp_path), |
| 135 | + display_progress=False |
| 136 | + ) |
| 137 | + |
| 138 | + status, substatus, error = uploader.upload_file() |
| 139 | + assert status.value == Status.OK.value |
| 140 | + assert substatus.value == Substatus.DONE.value |
| 141 | + assert error is None |
0 commit comments