Esempio n. 1
0
def test_offer_get_all_by_server_id(app, db, session):
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)

    assert len(
        api.offer_get_all_by_server_id(scoped_context,
                                       test_offer_data["server_id"])) == 1
Esempio n. 2
0
def test_offer_create_invalid_negative_cost_admin(is_resource_admin, app, db,
                                                  session):
    is_resource_admin.return_value = True
    data = dict(test_offer_data)
    data['cost'] = -1

    with pytest.raises(ValueError):
        api.offer_create(data, scoped_context)
Esempio n. 3
0
def test_offer_create_duplicate_resource_pass(is_resource_admin, app, db,
                                              session):
    is_resource_admin.return_value = True
    test_offer_data_expired = test_offer_data.copy()
    test_offer_data_expired["status"] = statuses.EXPIRED

    api.offer_create(test_offer_data_expired, scoped_context)
    api.offer_create(test_offer_data, scoped_context)
Esempio n. 4
0
def test_offer_get_all_by_server_id_and_status(app, db, session):
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)

    assert len(
        api.offer_get_all_by_server_id(scoped_context,
                                       test_offer_data["server_id"],
                                       "expired")) == 0
Esempio n. 5
0
def test_offer_get_all_by_resource_id(is_resource_admin, app, db, session):
    is_resource_admin.return_value = True
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)

    assert len(
        api.offer_get_all_by_resource_id(scoped_context,
                                         test_offer_data["resource_id"])) == 1
Esempio n. 6
0
def test_offer_create_duplicate_server_id_pass(app, db, session):
    test_offer_data_expired = test_offer_data.copy()
    expired_provider_offer_id = 'a41fadc1-6ae9-47e5-a74e-2dcf2b4dd55b'
    test_offer_data_expired["status"] = "expired"
    test_offer_data_expired["provider_offer_id"] = expired_provider_offer_id

    api.offer_create(test_offer_data_expired, scoped_context)
    api.offer_create(test_offer_data, scoped_context)
Esempio n. 7
0
def test_offer_delete_scoped_valid(is_resource_admin, app, db, session):
    is_resource_admin.return_value = True
    offer = api.offer_create(test_offer_data, scoped_context)
    api.offer_destroy(offer.offer_id, scoped_context)
    with pytest.raises(e.ResourceNotFound) as excinfo:
        api.offer_get("NotHere", scoped_context)
    assert (excinfo.value.code == 404)
Esempio n. 8
0
def test_offer_update_scoped_valid(app, db, session):
    offer = api.offer_create(test_offer_data, scoped_context)
    offer = api.offer_update(offer.marketplace_offer_id,
                             dict(status='testing'), scoped_context)
    check = api.offer_get(offer.marketplace_offer_id, scoped_context)

    assert check.status == 'testing'
Esempio n. 9
0
    def create(cls, data, context):
        if 'config' not in data:
            ro = ro_factory.ResourceObjectFactory.get_resource_object(
                data['resource_type'], data['resource_id'])
            data['config'] = ro.get_node_config()

        o = db.offer_create(data, context)
        return cls._from_db_object(cls(), o)
Esempio n. 10
0
def test_offer_update(app, db, session):
    offer = api.offer_create(test_offer_data)
    offer = api.offer_update(offer.marketplace_offer_id,
                             dict(status='testing'))
    check = api.offer_get(offer.marketplace_offer_id)

    assert check.status == 'testing'
    assert check.creator_id == '3456'
Esempio n. 11
0
def test_offer_update_scoped_valid(is_resource_admin, app, db, session):
    is_resource_admin.return_value = True
    offer = api.offer_create(test_offer_data, scoped_context)
    offer = api.offer_update(offer.offer_id, dict(status=statuses.EXPIRED),
                             scoped_context)
    check = api.offer_get(offer.offer_id, scoped_context)

    assert check.status == statuses.EXPIRED
Esempio n. 12
0
def test_offer_update_scoped_invalid(app, db, session):
    offer = api.offer_create(test_offer_data, scoped_context)

    with pytest.raises(e.ResourceNoPermission) as excinfo:
        api.offer_update(offer.marketplace_offer_id, dict(status='testing'),
                         scoped_context_2)
    assert (excinfo.value.code == 403)

    check = api.offer_get(offer.marketplace_offer_id, scoped_context)
    assert check.status != 'testing'
Esempio n. 13
0
def test_offer_update_scoped_invalid(is_resource_admin, app, db, session):
    is_resource_admin.return_value = True
    offer = api.offer_create(test_offer_data, scoped_context)

    with pytest.raises(e.ResourceNoPermission) as excinfo:
        api.offer_update(offer.offer_id, dict(status=statuses.EXPIRED),
                         scoped_context_2)
    assert (excinfo.value.code == 403)

    check = api.offer_get(offer.offer_id, scoped_context)
    assert check.status != statuses.EXPIRED
Esempio n. 14
0
def test_offer_get_all_found(is_resource_admin, app, db, session):
    is_resource_admin.return_value = True
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)
    api.offer_create(test_offer_data_3, scoped_context_2)

    assert len(api.offer_get_all(scoped_context)) == 3
Esempio n. 15
0
def test_offer_get_all_unexpired_scoped(app, db, session):
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)
    api.offer_create(test_offer_data_3, scoped_context_2)

    offers = api.offer_get_all_unexpired(scoped_context)
    assert len(offers) == 1
Esempio n. 16
0
def test_offer_get_all_unexpired_scoped(is_resource_admin, app, db, session):
    is_resource_admin.return_value = True
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)
    api.offer_create(test_offer_data_3, scoped_context_2)

    offers = api.offer_get_all_unexpired(scoped_context)
    assert len(offers) == 1
Esempio n. 17
0
def create_test_contract_data_for_ocr():
    bid = api.bid_create(test_bid_data_1, scoped_context)
    offer = api.offer_create(test_offer_data, scoped_context)

    contract_data = dict(time_created=now,
                         status='available',
                         start_time=now - timedelta(days=2),
                         end_time=now - timedelta(days=1),
                         cost=0.0,
                         bid_id=bid.marketplace_bid_id,
                         offers=[offer.marketplace_offer_id],
                         project_id='5599')

    return contract_data, offer.marketplace_offer_id
Esempio n. 18
0
def create_test_contract_data_for_ocr(is_resource_admin):
    is_resource_admin.return_value = True
    bid = api.bid_create(test_bid_data_1, scoped_context)
    offer = api.offer_create(test_offer_data, scoped_context)

    contract_data = dict(time_created=now,
                         status=statuses.AVAILABLE,
                         start_time=now - timedelta(days=2),
                         end_time=now - timedelta(days=1),
                         cost=0.0,
                         bid_id=bid.bid_id,
                         offers=[offer.offer_id],
                         project_id='5599')

    return contract_data, offer.offer_id
Esempio n. 19
0
def test_offer_get_found(app, db, session):
    m = api.offer_create(test_offer_data, scoped_context)
    assert (api.offer_get(m.marketplace_offer_id, scoped_context))
Esempio n. 20
0
def test_offer_get_all_by_project_id(app, db, session):
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)
    api.offer_create(test_offer_data_3, scoped_context_2)

    assert len(api.offer_get_all_by_project_id(scoped_context)) == 2
Esempio n. 21
0
 def create(cls, data, context):
     o = db.offer_create(data, context)
     return cls._from_db_object(cls(), o)
Esempio n. 22
0
def test_offer_delete_scoped_invalid(app, db, session):
    offer = api.offer_create(test_offer_data, scoped_context)
    api.offer_destroy(offer.marketplace_offer_id, scoped_context_2)
    check = api.offer_get(offer.marketplace_offer_id, scoped_context)
    assert check is not None
Esempio n. 23
0
def test_offer_delete_admin(app, db, session):
    offer = api.offer_create(test_offer_data, scoped_context_2)
    api.offer_destroy(offer.marketplace_offer_id, admin_context)
    check = api.offer_get(offer.marketplace_offer_id, scoped_context_2)
    assert check is None
Esempio n. 24
0
def test_offer_create_invalid_negative_cost_admin(app, db, session):
    data = dict(test_offer_data)
    data['cost'] = -1

    with pytest.raises(ValueError):
        api.offer_create(data, scoped_context)
Esempio n. 25
0
def test_offer_create_invalid_no_cost_admin(app, db, session):
    data = dict(test_offer_data)
    del data['cost']

    with pytest.raises(DBError):
        api.offer_create(data, scoped_context)
Esempio n. 26
0
def test_offer_create_duplicate_server_id_fail(app, db, session):
    api.offer_create(test_offer_data, scoped_context)
    with pytest.raises(ValueError):
        api.offer_create(test_offer_data, scoped_context)
Esempio n. 27
0
def test_offer_delete_scoped_valid(app, db, session):
    offer = api.offer_create(test_offer_data, scoped_context)
    api.offer_destroy(offer.marketplace_offer_id, scoped_context)
    with pytest.raises(e.ResourceNotFound) as excinfo:
        api.offer_get("NotHere", scoped_context)
    assert (excinfo.value.code == 404)
Esempio n. 28
0
def test_offer_create(app, db, session):
    offer = api.offer_create(test_offer_data, scoped_context)
    check = api.offer_get(offer.marketplace_offer_id, scoped_context)

    assert check.to_dict() == offer.to_dict()
Esempio n. 29
0
def test_offer_delete_scoped_invalid(app, db, session):
    offer = api.offer_create(test_offer_data, scoped_context)
    with pytest.raises(e.ResourceNoPermission) as excinfo:
        api.offer_destroy(offer.marketplace_offer_id, scoped_context_2)
    assert (excinfo.value.code == 403)
Esempio n. 30
0
def test_offer_get_all_found(app, db, session):
    api.offer_create(test_offer_data, scoped_context)
    api.offer_create(test_offer_data_2, scoped_context)
    api.offer_create(test_offer_data_3, scoped_context_2)

    assert len(api.offer_get_all(scoped_context)) == 3