Skip to content

Commit c971a09

Browse files
committed
Adding image filtering for fbc_operations requests
1 parent 94276b3 commit c971a09

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

iib/web/api_v1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ def get_builds() -> flask.Response:
402402
request_add_alias = aliased(RequestAdd, flat=True)
403403
request_rm_alias = aliased(RequestRm, flat=True)
404404
request_merge_index_image_alias = aliased(RequestMergeIndexImage, flat=True)
405+
request_fbc_operations_alias = aliased(RequestFbcOperations, flat=True)
405406

406407
query_params['index_image'] = index_image
407408
# Get the image id of the image to be searched
@@ -419,6 +420,9 @@ def get_builds() -> flask.Response:
419420
Request.id == request_merge_index_image_alias.id,
420421
)
421422
.outerjoin(request_rm_alias, Request.id == request_rm_alias.id)
423+
.outerjoin(
424+
request_fbc_operations_alias, Request.id == request_fbc_operations_alias.id
425+
)
422426
)
423427

424428
query = query.filter(
@@ -427,6 +431,7 @@ def get_builds() -> flask.Response:
427431
request_add_alias.index_image_id == image_result.id,
428432
request_merge_index_image_alias.index_image_id == image_result.id,
429433
request_rm_alias.index_image_id == image_result.id,
434+
request_fbc_operations_alias.index_image_id == image_result.id,
430435
)
431436
)
432437
# if index_image is not found in image table, then raise an error

tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,39 @@ def minimal_request_rm(db):
158158
return request
159159

160160

161+
@pytest.fixture()
162+
def minimal_request_fbc_operations(db):
163+
"""
164+
Create and return an instance of the RequestFbcOperations class.
165+
166+
The request instance will have the minimal set of required attributes set,
167+
and it'll be committed to the database.
168+
169+
:param flask_sqlalchemy.SQLAlchemy db: the connection to the database
170+
:return: the newly created request object
171+
:rtype: RequestFbcOperations
172+
"""
173+
binary_image = models.Image(pull_specification='quay.io/fbc_operations/binary-image:latest')
174+
db.session.add(binary_image)
175+
from_index_image = models.Image(pull_specification='quay.io/fbc_operations/index-image:latest')
176+
db.session.add(from_index_image)
177+
fbc_fragment_image = models.Image(
178+
pull_specification='quay.io/fbc_operations/fbcfragment-image:latest'
179+
)
180+
db.session.add(fbc_fragment_image)
181+
batch = models.Batch()
182+
db.session.add(batch)
183+
request = models.RequestFbcOperations(
184+
batch=batch,
185+
binary_image=binary_image,
186+
fbc_fragment=fbc_fragment_image,
187+
from_index=from_index_image,
188+
)
189+
db.session.add(request)
190+
db.session.commit()
191+
return request
192+
193+
161194
@pytest.fixture()
162195
def minimal_request_regenerate_bundle(db):
163196
"""

tests/test_web/test_api_v1.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
from sqlalchemy.exc import DisconnectionError
99

1010
from iib.web.api_v1 import _get_unique_bundles
11-
from iib.web.models import Image, RequestAdd, RequestRm, RequestCreateEmptyIndex
11+
from iib.web.models import (
12+
Image,
13+
RequestAdd,
14+
RequestRm,
15+
RequestCreateEmptyIndex,
16+
RequestFbcOperations,
17+
)
1218

1319

1420
def test_get_build(app, auth_env, client, db):
@@ -96,7 +102,8 @@ def test_get_build(app, auth_env, client, db):
96102
def test_get_builds(app, auth_env, client, db):
97103
total_create_requests = 5
98104
total_add_requests = 50
99-
total_requests = total_create_requests + total_add_requests
105+
total_fbc_operations_requests = 5
106+
total_requests = total_create_requests + total_add_requests + total_fbc_operations_requests
100107
# flask_login.current_user is used in RequestAdd.from_json, which requires a request context
101108
with app.test_request_context(environ_base=auth_env):
102109
for i in range(total_add_requests):
@@ -116,6 +123,14 @@ def test_get_builds(app, auth_env, client, db):
116123
}
117124
request2 = RequestCreateEmptyIndex.from_json(data)
118125
db.session.add(request2)
126+
for i in range(total_fbc_operations_requests):
127+
data = {
128+
'binary_image': 'quay.io/namespace/binary_image:latest',
129+
'from_index': f'quay.io/namespace/repo:{i}',
130+
'fbc_fragment': f'quay.io/namespace/fbcfragment:{i}',
131+
}
132+
request2 = RequestFbcOperations.from_json(data)
133+
db.session.add(request2)
119134
db.session.commit()
120135

121136
rv_json = client.get('/api/v1/builds?page=2').json
@@ -151,6 +166,10 @@ def test_get_builds(app, auth_env, client, db):
151166
assert rv_json['meta']['total'] == total_add_requests
152167
assert rv_json['items'][0]['request_type'] == 'add'
153168

169+
rv_json = client.get('/api/v1/builds?request_type=fbc-operations').json
170+
assert rv_json['meta']['total'] == total_fbc_operations_requests
171+
assert rv_json['items'][0]['request_type'] == 'fbc-operations'
172+
154173
rv_json = client.get('/api/v1/builds?request_type=create-empty-index').json
155174
assert rv_json['meta']['total'] == total_create_requests
156175
assert rv_json['items'][0]['request_type'] == 'create-empty-index'
@@ -160,14 +179,22 @@ def test_get_builds(app, auth_env, client, db):
160179
assert rv_json['items'][0]['user'] == 'tbrady@DOMAIN.LOCAL'
161180

162181

163-
def test_index_image_filter(app, client, db, minimal_request_add, minimal_request_rm):
182+
def test_index_image_filter(
183+
app, client, db, minimal_request_add, minimal_request_rm, minimal_request_fbc_operations
184+
):
164185
minimal_request_add.add_state('in_progress', 'Starting things up!')
165186
minimal_request_add.index_image = Image.get_or_create('quay.io/namespace/index@sha256:fghijk')
166187
minimal_request_add.add_state('complete', 'The request is complete')
167188

168189
minimal_request_rm.add_state('in_progress', 'Starting things up!')
169190
minimal_request_rm.index_image = Image.get_or_create('quay.io/namespace/index@sha256:123456')
170191
minimal_request_rm.add_state('complete', 'The request is complete')
192+
193+
minimal_request_fbc_operations.add_state('in_progress', 'Starting things up!')
194+
minimal_request_fbc_operations.index_image = Image.get_or_create(
195+
'quay.io/namespace/index@sha256:fbcop'
196+
)
197+
minimal_request_fbc_operations.add_state('complete', 'The request is complete')
171198
db.session.commit()
172199

173200
rv_json = client.get('/api/v1/builds?index_image=quay.io/namespace/index@sha256:fghijk').json
@@ -176,6 +203,9 @@ def test_index_image_filter(app, client, db, minimal_request_add, minimal_reques
176203
rv_json = client.get('/api/v1/builds?index_image=quay.io/namespace/index@sha256:123456').json
177204
assert rv_json['meta']['total'] == 1
178205

206+
rv_json = client.get('/api/v1/builds?index_image=quay.io/namespace/index@sha256:fbcop').json
207+
assert rv_json['meta']['total'] == 1
208+
179209
rv = client.get('/api/v1/builds?index_image=quay.io/namespace/index@sha256:abc')
180210
assert rv.json == {'error': ('quay.io/namespace/index@sha256:abc is not a valid index image')}
181211

0 commit comments

Comments
 (0)