Skip to content

Commit 1f69340

Browse files
committed
update readme, extra tests
1 parent 500377d commit 1f69340

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ payload = {
6565
'profile_id': 2
6666
}
6767

68-
api.create_job(job_id, payload=payload)
68+
api.update_job(job_id, payload=payload)
6969
```
7070

7171
For all payload options, consult the [API documentation](https://studio-docs.skylabtech.ai/#tag/job/operation/updateJobById).

skylab_studio/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class api: #pylint: disable=invalid-name
3434
"""
3535

3636
# initialization
37-
api_url = os.environ['SKYLAB_API_URL'] or 'https://studio.skylabtech.ai:443'
37+
try:
38+
api_url = os.environ['SKYLAB_API_URL']
39+
except KeyError:
40+
api_url = 'https://studio.skylabtech.ai:443'
3841

3942
# this is not package version -> used to construct the request base url
4043
api_version = '1'
@@ -239,7 +242,8 @@ def list_photos(self):
239242
def get_upload_url(self, payload={"use_cache_upload": False}):
240243
return self._api_request('photos/upload_url', 'GET', payload=payload)
241244

242-
def create_photo(self, payload=None):
245+
# todo privatize this method and test photo_upload
246+
def _create_photo(self, payload=None):
243247
""" API call to create a photo """
244248
return self._api_request(
245249
'photos',
@@ -282,7 +286,7 @@ def upload_photo(self, photo_path, model, id):
282286
headers = { 'X-Amz-Tagging': 'job=photo&api=true' }
283287

284288
# Ask studio to create the photo record
285-
photo_resp = self.create_photo(photo_data)
289+
photo_resp = self._create_photo(photo_data)
286290

287291
if photo_resp.status_code != 201:
288292
raise Exception('Unable to create the photo object')

test/test-portrait-1.JPG

438 KB
Loading

test/test_api.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ def test_create_profile(api):
121121
assert profile_id is not None
122122
assert result.status_code == 201
123123

124+
def test_upload_photo(api, pytestconfig):
125+
global job_id
126+
global photo_id
127+
128+
result = api.upload_photo(f"{pytestconfig.rootdir}/test/test-portrait-1.JPG", 'job', job_id)
129+
130+
assert result['photo']['id'] is not None
131+
photo_id = result['photo']['id']
132+
assert result['upload_response'] == 200
133+
124134
def test_get_profile(api):
125135
global profile_id
126136
result = api.get_profile(profile_id)
@@ -138,32 +148,6 @@ def test_list_photos(api):
138148
result = api.list_photos()
139149
assert result.status_code == 200
140150

141-
def test_create_photo(api):
142-
global photo_id
143-
global profile_id
144-
145-
job_name = str(uuid.uuid4())
146-
job_payload = {
147-
'name': job_name,
148-
'profile_id': 24
149-
}
150-
151-
result = api.create_job(payload=job_payload)
152-
job_id = result.json()['id']
153-
154-
photo_name = str(uuid.uuid4())
155-
payload = {
156-
"job_id": job_id,
157-
"name": photo_name,
158-
"use_cache_upload": False
159-
}
160-
161-
photo_result = api.create_photo(payload=payload)
162-
photo_id = photo_result.json()['id']
163-
164-
assert photo_id is not 0
165-
assert result.status_code == 201
166-
167151
def test_get_photo(api):
168152
global photo_id
169153
result = api.get_photo(photo_id)

0 commit comments

Comments
 (0)