def test_should_get_all_collections_ordered_by_name(self) -> None:
     collection_a = Collection(name="A collection")
     collection_z = Collection(name="Z collection")
     self.collection_repo.add(collection_a)
     self.collection_repo.add(collection_z)
     result: List[Collection] = self.collection_repo.get_all()
     self.assertEqual(result, [collection_a] + self.collections + [collection_z])
Example #2
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)
Example #3
0
 def setUpClass(cls):
     cls.collection = Collection(
         name="My collection",
         doc="Collection description\n\nFurther description"
     )
     cls.empty_collection = Collection(
         name="Empty collection"
     )
Example #4
0
def recreate_data(session: Session) -> None:
    session.query(Keyword).delete()
    session.query(Collection).delete()
    keywords = [
        Keyword(name="Test setup",
                doc="Prepare test environment, use teardown after this one"),
        Keyword(name="Some keyword", doc="Perform some check"),
        Keyword(name="Teardown", doc="Clean up environment")
    ]
    collections = [
        Collection(name="First collection", type="robot", keywords=keywords),
        Collection(name="Second collection", type="Robot"),
        Collection(name="Third", type="Library")
    ]
    session.add_all(collections)
    session.commit()
Example #5
0
 def test_should_add_collection(self) -> None:
     name_to_add = "test_collection"
     collection = Collection(name=name_to_add)
     self.collection_repo.add(collection)
     results: List[Collection] = db_session.query(Collection).filter_by(
         name=name_to_add).all()
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].name, name_to_add)
     self.assertIsNotNone(results[0].id)
Example #6
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()
 def test_should_add_collection_with_keywords(self) -> None:
     name_to_add = "test_collection"
     collection = Collection(name=name_to_add)
     collection.keywords = [Keyword(name="Keyword1"), Keyword(name="Keyword2")]
     self.collection_repo.add(collection)
     results: List[Collection] = db_session.query(Collection).filter_by(
         name=name_to_add
     ).all()
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].name, name_to_add)
     self.assertIsNotNone(results[0].id)
     self.assertEqual(len(results[0].keywords), 2)
     self.assertEqual(
         [k.name for k in results[0].keywords], ["Keyword1", "Keyword2"]
     )
Example #8
0
 def get_all_with_stats(
     self,
     *,
     pattern: Optional[str] = None,
     libtype: Optional[str] = None,
     skip: int = 0,
     limit: int = 100,
     ordering: List[OrderingItem] = None,
 ) -> List[CollectionWithStats]:
     return [
         self.from_stats_row(row) for row in (self._items_with_stats.filter(
             *self.filter_criteria(pattern, libtype)).order_by(
                 *Collection.ordering_criteria(ordering)).offset(
                     skip).limit(limit).all())
     ]
Example #9
0
 def get_all(
     self,
     *,
     pattern: Optional[str] = None,
     libtype: Optional[str] = None,
     skip: int = 0,
     limit: int = 100,
     ordering: List[OrderingItem] = None,
 ) -> List[ModelCollection]:
     return [
         collection.to_model() for collection in (self._items.filter(
             *self.filter_criteria(pattern, libtype)).order_by(
                 *Collection.ordering_criteria(ordering)).offset(
                     skip).limit(limit).all())
     ]
Example #10
0
def recreate_data(session: Session) -> None:
    session.query(Keyword).delete()
    session.query(Collection).delete()
    session.query(KeywordStatistics).delete()
    keywords = [
        Keyword(
            name="Test setup",
            doc="Prepare test environment, use teardown after this one",
        ),
        Keyword(name="Some keyword", doc="Perform some check"),
        Keyword(name="Teardown", doc="Clean up environment"),
    ]
    keywords_2 = [Keyword(name="zzz", doc="zzzzzz")]
    collections = [
        Collection(name="First collection", type="robot", keywords=keywords),
        Collection(name="Second collection", type="Robot",
                   keywords=keywords_2),
        Collection(name="Third", type="Library"),
    ]
    statistics = [
        KeywordStatistics(
            collection="First collection",
            keyword="Test setup",
            execution_time=datetime(2019,
                                    12,
                                    21,
                                    2,
                                    30,
                                    0,
                                    tzinfo=timezone.utc),
            times_used=10,
            total_elapsed=1000,
            min_elapsed=10,
            max_elapsed=100,
        ),
        KeywordStatistics(
            collection="First collection",
            keyword="Some keyword",
            execution_time=datetime(2019,
                                    12,
                                    21,
                                    2,
                                    30,
                                    0,
                                    tzinfo=timezone.utc),
            times_used=5,
            total_elapsed=3000,
            min_elapsed=300,
            max_elapsed=1500,
        ),
        KeywordStatistics(
            collection="First collection",
            keyword="Some keyword",
            execution_time=datetime(2019,
                                    12,
                                    20,
                                    1,
                                    30,
                                    0,
                                    tzinfo=timezone.utc),
            times_used=5,
            total_elapsed=2000,
            min_elapsed=200,
            max_elapsed=1000,
        ),
        KeywordStatistics(
            collection="Second collection",
            keyword="Old keyword",
            execution_time=datetime(2019,
                                    12,
                                    21,
                                    1,
                                    30,
                                    0,
                                    tzinfo=timezone.utc),
            times_used=5,
            total_elapsed=2500,
            min_elapsed=200,
            max_elapsed=1000,
        ),
        KeywordStatistics(
            collection="Second collection",
            keyword="Old keyword",
            execution_time=datetime(2019,
                                    12,
                                    21,
                                    2,
                                    30,
                                    0,
                                    tzinfo=timezone.utc),
            times_used=5,
            total_elapsed=2500,
            min_elapsed=100,
            max_elapsed=1000,
        ),
        KeywordStatistics(
            collection="Second collection",
            keyword="Old keyword",
            execution_time=datetime(2019,
                                    12,
                                    21,
                                    3,
                                    30,
                                    0,
                                    tzinfo=timezone.utc),
            times_used=5,
            total_elapsed=2500,
            min_elapsed=200,
            max_elapsed=1100,
        ),
    ]
    session.add_all(collections)
    session.add_all(statistics)
    session.commit()