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)
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)
def test_delete_category(db: Session) -> None: created = insert_category(db) category_from_db = crud.category.get_by_id(db, created.id) assert category_from_db deleted = crud.category.remove(db, id=created.id) category_from_db = crud.category.get_by_id(db, created.id) assert category_from_db is None assert deleted.id == created.id
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)
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)
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)
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)