Beispiel #1
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)
Beispiel #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(skip_defaults=True))
    return updated
Beispiel #3
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()
Beispiel #4
0
 def _library_or_resource_doc_changed(
         new_collection: CollectionUpdate,
         existing_collection: Collection) -> bool:
     """Returns true if collection overall documentation has changed.
     Does not check for keywords changes"""
     reduced_existing_collection = CollectionUpdate(
         name=existing_collection.name,
         type=existing_collection.type,
         version=existing_collection.version,
         scope=existing_collection.scope,
         args=existing_collection.named_args,
         path=existing_collection.path,
         doc=existing_collection.doc,
         doc_format=existing_collection.doc_format,
     )
     return new_collection != reduced_existing_collection
Beispiel #5
0
 def _serialise_libdoc(self, libdoc: LibraryDoc,
                       path: str) -> CollectionUpdate:
     """
     Serialises LibraryDoc object to CollectionUpdate object.
     :param libdoc: LibraryDoc input object
     :param path: library path
     :return: CollectionUpdate object
     """
     return CollectionUpdate(
         name=libdoc.name,
         type=libdoc.type,
         version=libdoc.version,
         scope=libdoc.scope,
         # named_args=libdoc.named_args, # we have not used this one, yet
         path=path,
         doc=libdoc.doc + self._extract_doc_from_libdoc_inits(libdoc.inits),
         doc_format=libdoc._setter__doc_format,
     )
Beispiel #6
0
 def add_collection(self, data: CollectionUpdate) -> Tuple[int, Dict]:
     """
     Adds collection using request post method.
     """
     return self._post_request(endpoint="collections", data=data.json())
Beispiel #7
0
        FIXTURE_PATH / "test_libdoc_file.xml",
        FIXTURE_PATH / "test_resource.resource",
        FIXTURE_PATH / "test_robot.robot",
        FIXTURE_PATH / "arg_parse.py",
        FIXTURE_PATH / "data_error.py",
        FIXTURE_PATH / "LibWithInit" / "test_res_lib_dir.resource",
    })
EXPECTED_GET_EXECUTION_PATHS = {
    STATISTICS_PATH / "output.xml",
    STATISTICS_PATH / "subdir" / "output.xml",
}
EXPECTED_COLLECTION = CollectionUpdate(
    doc="Overview that should be imported for SingleClassLib.",
    doc_format="ROBOT",
    name="SingleClassLib",
    path=str(FIXTURE_PATH / "SingleClassLib" / "SingleClassLib.py"),
    scope="TEST",
    type="LIBRARY",
    version="1.2.3",
)

EXPECTED_COLLECTION_KEYWORDS_1_1 = KeywordUpdate(
    args="",
    doc="Docstring for single_class_lib_method_1",
    name="Single Class Lib Method 1",
    tags=["tag_1", "tag_2"],
)
EXPECTED_COLLECTION_KEYWORDS_1_2 = KeywordUpdate(
    args="",
    doc="Docstring for single_class_lib_method_2",
    name="Single Class Lib Method 2",
Beispiel #8
0
import responses
import unittest

from rfhub2.cli.api_client import Client
from rfhub2.model import CollectionUpdate, KeywordUpdate

COLLECTION = CollectionUpdate(
    name="Third",
    type="Library",
    version=None,
    scope=None,
    named_args=None,
    path=None,
    doc=None,
    doc_format=None,
)

KEYWORD = KeywordUpdate(name="Some keyword",
                        doc="Perform some check",
                        args=None,
                        tags=[])


class ApiClientTests(unittest.TestCase):
    def setUp(self) -> None:
        self.app_url = "http://localhost:8000"
        self.client = Client(self.app_url, "rfhub", "rfhub")
        self.collection_endpoint = f"{self.client.api_url}/collections/"
        self.keyword_endpoint = f"{self.client.api_url}/keywords/"

    def test_get_collections(self):