Пример #1
0
def test_create_prime_subscription(db: Session) -> None:
    created = insert_prime_subscription(db)
    prime_subscription_created = crud.prime_subscription.get_by_id(
        db, created.id)
    assert created.id == prime_subscription_created.id
    assert created.name == prime_subscription_created.name
    delete_prime_subscription(db, created)
Пример #2
0
def test_list_all_prime_subscriptions(db: Session) -> None:
    prime_subscription_count = crud.prime_subscription.count(db)
    prime_subscriptions = crud.prime_subscription.filter(db)
    assert len(prime_subscriptions) == prime_subscription_count
    created = insert_prime_subscription(db)
    prime_subscriptions = crud.prime_subscription.filter(db)
    assert len(prime_subscriptions) == prime_subscription_count + 1
    delete_prime_subscription(db, created)
Пример #3
0
def test_GET_existing_prime_subscription(db: Session) -> None:
    created = insert_prime_subscription(db)

    response = client.get(f'/api/v1/prime_subscription/{created.id}')
    prime_subscription_from_api = response.json()
    assert response.status_code == 200
    assert prime_subscription_from_api['name'] == created.name

    delete_prime_subscription(db, created)
Пример #4
0
def test_delete_prime_subscription(db: Session) -> None:
    created = insert_prime_subscription(db)

    prime_subscription_from_db = crud.prime_subscription.get_by_id(
        db, created.id)
    assert prime_subscription_from_db
    deleted = crud.prime_subscription.remove(db, id=created.id)
    prime_subscription_from_db = crud.prime_subscription.get_by_id(
        db, created.id)
    assert prime_subscription_from_db is None
    assert deleted.id == created.id
Пример #5
0
def test_PUT_existing_prime_subscription(db: Session) -> None:
    created = insert_prime_subscription(db)

    prime_subscription_data = {'name': 'Changed'}

    response = client.put(
        f'/api/v1/prime_subscription/{created.id}', json=prime_subscription_data)
    prime_subscription_from_api = response.json()
    assert response.status_code == 200
    assert prime_subscription_from_api['name'] == 'Changed'

    delete_prime_subscription(db, created)
Пример #6
0
def test_GET_prime_subscription(db: Session) -> None:
    prime_subscription_count = crud.prime_subscription.count(db)
    response = client.get('/api/v1/prime_subscription/')
    assert response.status_code == 200
    assert len(response.json()) == prime_subscription_count
    created = insert_prime_subscription(db)

    response = client.get('/api/v1/prime_subscription/')
    assert response.status_code == 200
    assert len(response.json()) == prime_subscription_count + 1

    delete_prime_subscription(db, created)
Пример #7
0
def test_update_prime_subscription(db: Session) -> None:
    created = insert_prime_subscription(db)
    prime_subscription_from_db = crud.prime_subscription.get_by_id(
        db, created.id)
    prime_subscription_update = PrimeSubscriptionUpdate(name="Changed")
    updated_prime_subscription = crud.prime_subscription.update(
        db,
        db_object=prime_subscription_from_db,
        object_to_update=prime_subscription_update)
    prime_subscription_from_db = crud.prime_subscription.get_by_id(
        db, created.id)
    assert prime_subscription_from_db.id == updated_prime_subscription.id
    assert prime_subscription_from_db.name == "Changed"
    delete_prime_subscription(db, created)
Пример #8
0
def test_POST_existing_prime_subscription_name(db: Session) -> None:
    created = insert_prime_subscription(db)

    prime_subscription_data = {
        'name': created.name,
        'validity': 1,
        'validity_type': random_upper_string(),
        'enabled': True
    }
    response = client.post('/api/v1/prime_subscription/',
                           json=prime_subscription_data)

    created_prime_subscription = response.json()
    assert response.status_code == 400
    assert "_id" not in created_prime_subscription

    delete_prime_subscription(db, created)