Ejemplo n.º 1
0
def test_request_type_validation(type_num, is_valid):
    if is_valid:
        models.Request(type=type_num)
    else:
        with pytest.raises(
                ValidationError,
                match=f'{type_num} is not a valid request type number'):
            models.Request(type=type_num)
Ejemplo n.º 2
0
def test_request_add_state_invalid_state(db):
    binary_image = models.Image(pull_specification='quay.io/image:latest')
    db.session.add(binary_image)
    request = models.Request(binary_image=binary_image, type=models.RequestTypeMapping.add.value)
    db.session.add(request)
    with pytest.raises(ValidationError, match='The state "invalid" is invalid'):
        request.add_state('invalid', 'Starting things up')
Ejemplo n.º 3
0
def test_request_add_state_already_done(state, db):
    binary_image = models.Image(pull_specification='quay.io/image:latest')
    db.session.add(binary_image)
    request = models.Request(binary_image=binary_image, type=models.RequestTypeMapping.add.value)
    db.session.add(request)
    with pytest.raises(ValidationError, match=f'A {state} request cannot change states'):
        request.add_state(state, 'Done')
        db.session.commit()
        request.add_state('in_progress', 'Oops!')
Ejemplo n.º 4
0
def test_patch_request_forbidden_user(db, worker_forbidden_env, client):
    binary_image = models.Image(pull_specification='quay.io/image:latest')
    db.session.add(binary_image)
    request = models.Request(
        binary_image=binary_image,
        type=models.RequestTypeMapping.add.value,
    )
    db.session.add(request)

    rv = client.patch('/api/v1/builds/1',
                      json={'arches': ['s390x']},
                      environ_base=worker_forbidden_env)
    assert rv.status_code == 403
    assert 'This API endpoint is restricted to IIB workers' == rv.json['error']
Ejemplo n.º 5
0
def test_request_add_state(db):
    binary_image = models.Image(pull_specification='quay.io/image:latest')
    db.session.add(binary_image)
    request = models.Request(binary_image=binary_image, type=models.RequestTypeMapping.add.value)
    db.session.add(request)
    request.add_state('in_progress', 'Starting things up')
    request.add_state('complete', 'All done!')
    db.session.commit()

    assert len(request.states) == 2
    assert request.state.state_name == 'complete'
    assert request.state.state_reason == 'All done!'
    assert request.states[0].state_name == 'in_progress'
    # Ensure that request.state is the latest state
    assert request.state == request.states[1]
Ejemplo n.º 6
0
def test_patch_request_invalid_params_format(data, error_msg, db,
                                             worker_auth_env, client):
    binary_image = models.Image(pull_specification='quay.io/image:latest')
    db.session.add(binary_image)
    request = models.Request(
        binary_image=binary_image,
        type=models.RequestTypeMapping.add.value,
    )
    db.session.add(request)

    rv = client.patch('/api/v1/builds/1',
                      json=data,
                      environ_base=worker_auth_env)
    assert rv.status_code == 400
    assert error_msg == rv.json['error']
Ejemplo n.º 7
0
def test_request_add_architecture(db):
    binary_image = models.Image(pull_specification='quay.io/image:latest')
    db.session.add(binary_image)
    request = models.Request(binary_image=binary_image, type=models.RequestTypeMapping.add.value,)
    db.session.add(request)
    request.add_architecture('amd64')
    request.add_architecture('s390x')
    db.session.commit()
    assert len(request.architectures) == 2
    assert request.architectures[0].name == 'amd64'
    assert request.architectures[1].name == 's390x'

    # Verify that the method is idempotent
    request.add_architecture('amd64')
    db.session.commit()
    assert len(request.architectures) == 2
Ejemplo n.º 8
0
def test_patch_request_success(db, worker_auth_env, client):
    bundles = [
        'quay.io/some-operator:v1.0.0',
        'quay.io/some-operator:v1.1.0',
        'quay.io/some-operator2:v2.0.0',
        'quay.io/some-operator2:v2.1.0',
    ]

    bundle_mapping = {
        'some-operator': bundles[0:2],
        'some-operator2': bundles[2:],
    }

    data = {
        'arches': ['arches'],
        'bundle_mapping': bundle_mapping,
        'state': 'complete',
        'state_reason': 'All done!',
        'index_image': 'index:image',
    }

    response_json = {
        'arches': ['arches'],
        'binary_image':
        'quay.io/image:latest',
        'binary_image_resolved':
        None,
        'bundle_mapping':
        bundle_mapping,
        'bundles':
        bundles,
        'from_index':
        None,
        'from_index_resolved':
        None,
        'id':
        1,
        'index_image':
        'index:image',
        'organization':
        None,
        'removed_operators': [],
        'request_type':
        'add',
        'state':
        'complete',
        'state_history': [
            {
                'state': 'complete',
                'state_reason': 'All done!',
                'updated': '2020-02-12T17:03:00Z'
            },
            {
                'state': 'in_progress',
                'state_reason': 'Starting things up',
                'updated': '2020-02-12T17:03:00Z',
            },
        ],
        'state_reason':
        'All done!',
        'updated':
        '2020-02-12T17:03:00Z',
        'user':
        None,
    }

    binary_image = models.Image(pull_specification='quay.io/image:latest')
    db.session.add(binary_image)
    request = models.Request(
        binary_image=binary_image,
        type=models.RequestTypeMapping.add.value,
    )
    db.session.add(request)
    for bundle in bundles:
        request.bundles.append(Image.get_or_create(bundle))
    request.add_state('in_progress', 'Starting things up')
    db.session.commit()

    rv = client.patch('/api/v1/builds/1',
                      json=data,
                      environ_base=worker_auth_env)
    rv_json = rv.json
    rv_json['state_history'][0]['updated'] = '2020-02-12T17:03:00Z'
    rv_json['state_history'][1]['updated'] = '2020-02-12T17:03:00Z'
    rv_json['updated'] = '2020-02-12T17:03:00Z'
    assert rv.status_code == 200
    assert rv_json == response_json