def test_list_all_categories(db: Session) -> None:
    category_count = crud.category.count(db)
    categories = crud.category.filter(db)
    assert len(categories) == category_count
    created = insert_category(db)
    categories = crud.category.filter(db)
    assert len(categories) == category_count + 1
    delete_category(db, created)
Beispiel #2
0
def test_DELETE_existing_category(db: Session) -> None:
    created = insert_category(db)

    response = client.delete(f'/api/v1/category/{created.id}')
    category_from_api = response.json()
    assert response.status_code == 200
    assert created.name == category_from_api['name']

    delete_category(db, created)
Beispiel #3
0
def test_PUT_existing_category(db: Session) -> None:
    created = insert_category(db)

    category_data = {'name': 'Changed'}

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

    delete_category(db, created)
def test_update_category(db: Session) -> None:
    created = insert_category(db)
    category_from_db = crud.category.get_by_id(db, created.id)
    category_update = CategoryUpdate(name="Changed")
    updated_category = crud.category.update(db,
                                            db_object=category_from_db,
                                            object_to_update=category_update)
    category_from_db = crud.category.get_by_id(db, created.id)
    assert category_from_db.id == updated_category.id
    assert category_from_db.name == "Changed"
    delete_category(db, created)
Beispiel #5
0
def test_GET_category(db: Session) -> None:
    category_count = crud.category.count(db)
    response = client.get('/api/v1/category/')
    assert response.status_code == 200
    assert len(response.json()) == category_count
    created = insert_category(db)

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

    delete_category(db, created)
Beispiel #6
0
def test_POST_existing_category_name(db: Session) -> None:
    created = insert_category(db)

    category_data = {
        'name': created.name,
        'description': random_upper_string(),
    }
    response = client.post('/api/v1/category/', json=category_data)

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

    delete_category(db, created)
Beispiel #7
0
def test_POST_new_category(db: Session) -> None:
    category_data = create_random_category_data()
    response = client.post('/api/v1/category/', json=category_data)

    assert response.status_code == 200

    created_category = response.json()
    category_id = created_category.get("id")

    category_from_db = crud.category.get_by_id(db, category_id)

    assert category_from_db
    assert category_from_db.name == category_data['name']

    delete_category(db, category_from_db)
def test_create_category(db: Session) -> None:
    created = insert_category(db)
    category_created = crud.category.get_by_id(db, created.id)
    assert created.id == category_created.id
    assert created.description == category_created.description
    delete_category(db, created)