Esempio n. 1
0
def update_collection(
        *,
        _: bool = Depends(is_authenticated),
        repository: CollectionRepository = Depends(get_collection_repository),
        id: int,
        collection_update: CollectionUpdate):
    db_collection: DBCollection = or_404(repository.get(id))
    updated: DBCollection = repository.update(
        db_collection, collection_update.dict(skip_defaults=True))
    return updated
Esempio n. 2
0
def update_collection(
    *,
    _: bool = Depends(is_authenticated),
    repository: CollectionRepository = Depends(get_collection_repository),
    id: int,
    collection_update: CollectionUpdate,
):
    db_collection: DBCollection = or_404(repository.get(id))
    updated: DBCollection = repository.update(
        db_collection, collection_update.dict(exclude_unset=True))
    return updated.to_model()
Esempio n. 3
0
async def index(
    request: Request,
    repository: CollectionRepository = Depends(get_collection_repository)):
    libraries = repository.get_all(libtype="library")
    resource_files = repository.get_all(libtype="resource")
    context = {
        "request": request,
        "libraries": libraries,
        "resource_files": resource_files,
        "version": version
    }
    return templates.TemplateResponse("libraryNames.html", context)
Esempio n. 4
0
def base_doc_view(request: Request,
                  repository: CollectionRepository,
                  collection_id: int,
                  keyword_id: Optional[int] = None):
    collection = or_404(repository.get(collection_id))
    collections = repository.get_all()
    context = {
        "request": request,
        "collection": collection,
        "keyword_id": keyword_id,
        "hierarchy": collections,
        "version": version
    }
    return templates.TemplateResponse("library.html", context)
Esempio n. 5
0
    def setUp(self) -> None:
        db_session.rollback()
        db_session.query(Keyword).delete()
        db_session.query(Collection).delete()
        self.collection_repo = CollectionRepository(db_session)
        self.keyword_repo = KeywordRepository(db_session)
        self.keywords = [
            Keyword(
                name="Test setup",
                doc="Prepare test environment, use teardown after this one",
            ),
            Keyword(name="Login keyword", doc="Perform some check"),
            Keyword(name="Teardown", doc="Clean up environment"),
        ]
        self.app_keyword = Keyword(name="Login to Application")

        self.collections = [
            Collection(name="First collection",
                       type="robot",
                       keywords=self.keywords),
            Collection(name="Second collection",
                       type="Robot",
                       keywords=[self.app_keyword]),
            Collection(name="Third", type="Library"),
        ]
        self.sorted_keywords = sorted(self.keywords + [self.app_keyword],
                                      key=lambda k: k.name)
        db_session.add_all(self.collections)
        db_session.commit()
        for item in self.collections:
            db_session.refresh(item)
Esempio n. 6
0
def create_collection(
        *,
        _: bool = Depends(is_authenticated),
        repository: CollectionRepository = Depends(get_collection_repository),
        collection: CollectionUpdate):
    db_collection: DBCollection = DBCollection(**collection.dict())
    return repository.add(db_collection)
Esempio n. 7
0
def create_collection(
    *,
    _: bool = Depends(is_authenticated),
    repository: CollectionRepository = Depends(get_collection_repository),
    collection: CollectionUpdate,
):
    db_collection: DBCollection = repository.add(
        DBCollection.create(collection))
    return db_collection.to_model()
Esempio n. 8
0
def delete_collection(
        *,
        _: bool = Depends(is_authenticated),
        repository: CollectionRepository = Depends(get_collection_repository),
        id: int):
    deleted: int = repository.delete(id)
    if deleted:
        return Response(status_code=204)
    else:
        raise HTTPException(status_code=404)
Esempio n. 9
0
def get_collections(
        repository: CollectionRepository = Depends(get_collection_repository),
        skip: int = 0,
        limit: int = 100,
        pattern: str = None,
        libtype: str = None):
    collections: List[DBCollection] = repository.get_all(skip=skip,
                                                         limit=limit,
                                                         pattern=pattern,
                                                         libtype=libtype)
    return collections
Esempio n. 10
0
def get_collections_with_stats(
        repository: CollectionRepository = Depends(get_collection_repository),
        skip: int = 0,
        limit: int = 100,
        pattern: str = None,
        libtype: str = None,
        ordering: List[OrderingItem] = Depends(get_ordering),
):
    return repository.get_all_with_stats(skip=skip,
                                         limit=limit,
                                         pattern=pattern,
                                         libtype=libtype,
                                         ordering=ordering)
Esempio n. 11
0
def create_keyword(
        *,
        _: bool = Depends(is_authenticated),
        repository: KeywordRepository = Depends(get_keyword_repository),
        collection_repository: CollectionRepository = Depends(
            get_collection_repository),
        keyword: KeywordCreate):
    collection: Optional[DBCollection] = collection_repository.get(
        keyword.collection_id)
    if not collection:
        raise HTTPException(status_code=400,
                            detail='Collection does not exist')
    db_keyword: DBKeyword = DBKeyword(**keyword.dict())
    return repository.add(db_keyword)
Esempio n. 12
0
def get_collection_repository(request: Request) -> CollectionRepository:
    return CollectionRepository(request.state.db)
Esempio n. 13
0
def get_collection(
        *,
        repository: CollectionRepository = Depends(get_collection_repository),
        id: int):
    collection: Optional[DBCollection] = repository.get(id)
    return or_404(collection)
Esempio n. 14
0
def get_collection_with_stats(
        *,
        repository: CollectionRepository = Depends(get_collection_repository),
        id: int):
    collection: Optional[CollectionWithStats] = repository.get_with_stats(id)
    return or_404(collection)