Ejemplo n.º 1
0
def test_offer_contract_relationship_get_by_id(app, db, session):
    contract_data, _ = create_test_contract_data_for_ocr()
    api.contract_create(contract_data, admin_context)
    ocr = api.offer_contract_relationship_get_all(admin_context)
    assert len(api.offer_contract_relationship_get_all(admin_context)) == 1
    assert (api.offer_contract_relationship_get(
        context=admin_context,
        offer_contract_relationship_id=ocr[0].offer_contract_relationship_id
    ).offer_contract_relationship_id == ocr[0].offer_contract_relationship_id)
Ejemplo n.º 2
0
def test_offer_contract_relationship_update_invalid_scoped(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    filters = {
        'marketplace_offer_id': offer_test_id,
        'contract_id': contract.contract_id
    }
    ocrs = api.offer_contract_relationship_get_all(
        context=admin_context,
        filters=filters,
    )
    ocr_id = ocrs[0].offer_contract_relationship_id

    with pytest.raises(e.RequiresAdmin) as excinfo:
        api.offer_contract_relationship_update(
            context=scoped_context,
            offer_contract_relationship_id=ocr_id,
            values=dict(status='testing'))
    assert (excinfo.value.code == 403)

    check = api.offer_contract_relationship_get(
        context=admin_context, offer_contract_relationship_id=ocr_id)

    assert check.status != 'testing'
    assert check.marketplace_offer_id == offer_test_id
Ejemplo n.º 3
0
def test_contract_update_valid_admin(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    contract = api.contract_update(contract.contract_id,
                                   dict(status='testing'), admin_context)
    check = api.contract_get(contract.contract_id, admin_context)

    assert check.status == 'testing'
    assert check.cost == 0.0
Ejemplo n.º 4
0
def test_offer_contract_relationship_create_valid(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    ocr = api.offer_contract_relationship_get(
        marketplace_offer_id=offer_test_id,
        contract_id=contract.contract_id,
        context=admin_context)
    assert contract.contract_id == ocr.contract_id
Ejemplo n.º 5
0
def test_contract_get_all_unexpired(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)

    assert len(api.contract_get_all_unexpired(admin_context)) == 1

    api.contract_update(contract.contract_id, dict(status='expired'),
                        admin_context)
    assert len(api.contract_get_all_unexpired(admin_context)) == 0
Ejemplo n.º 6
0
def test_contract_update_invalid_scoped(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    with pytest.raises(e.ResourceNoPermission) as excinfo:
        api.contract_update(contract.contract_id, dict(status='testing'),
                            scoped_context)
    assert (excinfo.value.code == 403)
    assert (api.contract_get(contract.contract_id, admin_context).status !=
            "testing")
Ejemplo n.º 7
0
def test_contract_update_invalid_scoped(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    updated = api.contract_update(contract.contract_id, dict(status='testing'),
                                  scoped_context)
    check = api.contract_get(contract.contract_id, admin_context)

    assert check.status != 'testing'
    assert check.cost == 0.0
    assert updated is None
Ejemplo n.º 8
0
def test_offer_contract_relationship_create_valid(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    filters = {'offer_id': offer_test_id, 'contract_id': contract.contract_id}
    ocr = api.offer_contract_relationship_get_all(
        context=admin_context,
        filters=filters,
    )
    assert contract.contract_id == ocr[0].contract_id
Ejemplo n.º 9
0
def test_offer_contract_relationship_delete_invalid_scoped(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    api.offer_contract_relationship_destroy(contract_id=contract.contract_id,
                                            marketplace_offer_id=offer_test_id,
                                            context=scoped_context)
    check = api.offer_contract_relationship_get(
        contract_id=contract.contract_id,
        marketplace_offer_id=offer_test_id,
        context=admin_context)
    assert check is not None
Ejemplo n.º 10
0
def test_offer_contract_relationship_get_all_unexpired(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    api.offer_contract_relationship_get(offer_test_id, contract.contract_id)

    assert len(
        api.offer_contract_relationship_get_all_unexpired(admin_context)) == 1

    api.offer_contract_relationship_update(marketplace_offer_id=offer_test_id,
                                           contract_id=contract.contract_id,
                                           values=dict(status='expired'),
                                           context=admin_context)
    assert len(
        api.offer_contract_relationship_get_all_unexpired(admin_context)) == 0
Ejemplo n.º 11
0
def test_offer_contract_relationship_delete_invalid_scoped(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    filters = {
        'marketplace_offer_id': offer_test_id,
        'contract_id': contract.contract_id
    }
    ocrs = api.offer_contract_relationship_get_all(
        context=admin_context,
        filters=filters,
    )
    ocr_id = ocrs[0].offer_contract_relationship_id
    api.offer_contract_relationship_destroy(
        context=scoped_context, offer_contract_relationship_id=ocr_id)
    check = api.offer_contract_relationship_get(admin_context, ocr_id)
    assert check is not None
Ejemplo n.º 12
0
def test_offer_contract_relationship_delete_valid(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    filters = {'offer_id': offer_test_id, 'contract_id': contract.contract_id}
    ocrs = api.offer_contract_relationship_get_all(
        context=admin_context,
        filters=filters,
    )
    ocr_id = ocrs[0].offer_contract_relationship_id
    api.offer_contract_relationship_destroy(
        context=admin_context, offer_contract_relationship_id=ocr_id)

    with pytest.raises(e.ResourceNotFound) as excinfo:
        api.offer_contract_relationship_get(
            context=admin_context, offer_contract_relationship_id=ocr_id)
    assert (excinfo.value.code == 404)
Ejemplo n.º 13
0
def test_offer_contract_relationship_delete_invalid_scoped(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    filters = {'offer_id': offer_test_id, 'contract_id': contract.contract_id}
    ocrs = api.offer_contract_relationship_get_all(
        context=admin_context,
        filters=filters,
    )
    ocr_id = ocrs[0].offer_contract_relationship_id

    with pytest.raises(e.RequiresAdmin) as excinfo:
        api.offer_contract_relationship_destroy(
            context=scoped_context, offer_contract_relationship_id=ocr_id)
    assert (excinfo.value.code == 403)

    check = api.offer_contract_relationship_get(admin_context, ocr_id)
    assert check is not None
Ejemplo n.º 14
0
def test_offer_contract_relationship_update_valid(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    filters = {'offer_id': offer_test_id, 'contract_id': contract.contract_id}
    ocrs = api.offer_contract_relationship_get_all(
        context=admin_context,
        filters=filters,
    )
    ocr_id = ocrs[0].offer_contract_relationship_id

    api.offer_contract_relationship_update(
        context=admin_context,
        offer_contract_relationship_id=ocr_id,
        values=dict(status=statuses.EXPIRED))
    check = api.offer_contract_relationship_get(
        context=admin_context, offer_contract_relationship_id=ocr_id)

    assert check.status == statuses.EXPIRED
    assert check.offer_id == offer_test_id
Ejemplo n.º 15
0
def test_offer_contract_relationship_get_all_unexpired(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    filters = {'offer_id': offer_test_id, 'contract_id': contract.contract_id}
    ocrs = api.offer_contract_relationship_get_all(
        context=admin_context,
        filters=filters,
    )
    ocr_id = ocrs[0].offer_contract_relationship_id

    assert len(
        api.offer_contract_relationship_get_all_unexpired(admin_context)) == 1

    api.offer_contract_relationship_update(
        context=admin_context,
        offer_contract_relationship_id=ocr_id,
        values=dict(status=statuses.EXPIRED))
    assert len(
        api.offer_contract_relationship_get_all_unexpired(admin_context)) == 0
Ejemplo n.º 16
0
def test_offer_contract_relationship_update_invalid_scoped(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, admin_context)
    ocr = api.offer_contract_relationship_get(
        marketplace_offer_id=offer_test_id,
        contract_id=contract.contract_id,
        context=scoped_context)
    api.offer_contract_relationship_update(
        marketplace_offer_id=ocr.marketplace_offer_id,
        contract_id=ocr.contract_id,
        values=dict(status='testing'),
        context=scoped_context)
    check = api.offer_contract_relationship_get(
        marketplace_offer_id=offer_test_id,
        contract_id=contract.contract_id,
        context=admin_context)

    assert check.status != 'testing'
    assert check.marketplace_offer_id == offer_test_id
Ejemplo n.º 17
0
def test_offer_contract_relationship_get_all(app, db, session):
    contract_data, _ = create_test_contract_data_for_ocr()
    api.contract_create(contract_data, admin_context)

    assert len(api.offer_contract_relationship_get_all(admin_context)) == 1
Ejemplo n.º 18
0
def test_contract_delete_invalid_scoped(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    destroyed = api.contract_destroy(contract.contract_id, scoped_context)
    check = api.contract_get(contract.contract_id, admin_context)
    assert check is not None
    assert destroyed is None
Ejemplo n.º 19
0
def test_contract_delete_invalid_scoped(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    with pytest.raises(e.ResourceNoPermission) as excinfo:
        api.contract_destroy(contract.contract_id, scoped_context)
    assert (excinfo.value.code == 403)
    assert api.contract_get(contract.contract_id, admin_context)
Ejemplo n.º 20
0
def test_contract_create_invalid_scoped(app, db, session):
    data = create_test_contract_data()
    created = api.contract_create(data, scoped_context)
    assert created is None
Ejemplo n.º 21
0
def test_contract_create_invalid_admin(app, db, session):
    data = create_test_contract_data()
    del data['cost']
    with pytest.raises(DBError):
        api.contract_create(data, admin_context)
Ejemplo n.º 22
0
def test_contract_create_valid_admin(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    check = api.contract_get(contract.contract_id, admin_context)

    assert check.to_dict() == contract.to_dict()
Ejemplo n.º 23
0
def test_contract_get_all(app, db, session):
    contract_data = create_test_contract_data()
    api.contract_create(contract_data, admin_context)

    assert len(api.contract_get_all(scoped_context)) == 1
Ejemplo n.º 24
0
 def create(cls, data, context):
     c = db.contract_create(data, context)
     return cls._from_db_object(cls(), c)
Ejemplo n.º 25
0
def test_contract_create_invalid_scoped(app, db, session):
    data = create_test_contract_data()
    with pytest.raises(e.RequiresAdmin) as excinfo:
        api.contract_create(data, scoped_context)
    assert (excinfo.value.code == 403)
Ejemplo n.º 26
0
def test_offer_contract_relationship_create_invalid_scoped(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    contract = api.contract_create(contract_data, scoped_context)

    assert contract is None
Ejemplo n.º 27
0
def test_contract_delete_valid_admin(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    api.contract_destroy(contract.contract_id, admin_context)
    check = api.contract_get(contract.contract_id, admin_context)
    assert check is None
Ejemplo n.º 28
0
def test_offer_contract_relationship_create_invalid_scoped(app, db, session):
    contract_data, offer_test_id = create_test_contract_data_for_ocr()
    with pytest.raises(e.RequiresAdmin) as excinfo:
        api.contract_create(contract_data, scoped_context)
    assert (excinfo.value.code == 403)
Ejemplo n.º 29
0
def test_contract_delete_valid_admin(app, db, session):
    contract = api.contract_create(create_test_contract_data(), admin_context)
    api.contract_destroy(contract.contract_id, admin_context)
    with pytest.raises(e.ResourceNotFound) as excinfo:
        api.contract_get(contract.contract_id, admin_context)
    assert (excinfo.value.code == 404)