예제 #1
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)
예제 #2
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)
예제 #3
0
 def test_should_add_keyword_with_collection_id(self) -> None:
     name_to_add = "test_keyword"
     keyword = Keyword(name=name_to_add,
                       collection_id=self.collections[-1].id)
     self.keyword_repo.add(keyword)
     results: List[Keyword] = db_session.query(Keyword).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(results[0].collection, self.collections[-1])
예제 #4
0
 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"]
     )
예제 #5
0
 def test_should_delete_collection_without_keywords(self) -> None:
     result: int = self.collection_repo.delete(self.collections[2].id)
     self.assertEqual(result, 1)
     self.assertEqual(db_session.query(Collection).count(), 2)
     self.assertEqual(db_session.query(Keyword).count(), 4)
예제 #6
0
    def setUp(self) -> None:
        db_session.rollback()
        db_session.query(TestCase).delete()
        db_session.query(SuiteRel).delete()
        db_session.query(Suite).delete()
        self.suite_repo = SuiteRepository(db_session)

        self.keyword_refs = [
            KeywordRef(name="Login", args=["admin"], kw_type=KeywordType.SETUP)
        ]
        self.keyword_refs_json = (
            '[{"name": "Login", "args": ["admin"], "kw_type": "SETUP"}]')
        self.empty_keywords = KeywordRefList.of([])
        self.metadata_items = [MetadataItem(key="version", value="1.0")]
        self.metadata_items_json = '[{"key": "version", "value": "1.0"}]'
        self.empty_metadata = SuiteMetadata.of([])
        self.suite_1 = Suite(
            name="Suite 1",
            longname="Suite 1",
            keywords=self.keyword_refs_json,
            metadata_items=self.metadata_items_json,
            is_root=True,
            rpa=False,
        )
        self.suite_2 = Suite(
            name="Suite 2",
            longname="Suite 2",
            keywords="[]",
            metadata_items="[]",
            is_root=True,
            rpa=False,
        )
        self.suite_3 = Suite(
            name="Suite 3",
            longname="Suite 3",
            keywords="[]",
            metadata_items="[]",
            is_root=True,
            rpa=False,
        )
        self.suite_11 = Suite(
            name="Suite 1-1",
            longname="Suite 1.Suite 1-1",
            keywords="[]",
            metadata_items="[]",
            is_root=False,
            rpa=False,
        )
        self.suite_12 = Suite(
            name="Suite 1-2",
            longname="Suite 1.Suite 1-2",
            keywords="[]",
            metadata_items="[]",
            is_root=False,
            rpa=False,
        )
        self.suite_111 = Suite(
            name="Suite 1-1-1",
            longname="Suite 1.Suite 1-1.Suite 1-1-1",
            keywords="[]",
            metadata_items="[]",
            is_root=False,
            rpa=False,
        )
        self.suite_112 = Suite(
            name="Suite 1-1-2",
            longname="Suite 1.Suite 1-1.Suite 1-1-2",
            keywords="[]",
            metadata_items="[]",
            is_root=False,
            rpa=False,
        )
        self.suite_121 = Suite(
            name="Suite 1-2-1",
            longname="Suite 1.Suite 1-2.Suite 1-2-1",
            keywords="[]",
            metadata_items="[]",
            is_root=False,
            rpa=False,
        )
        self.suites = [
            self.suite_1,
            self.suite_2,
            self.suite_3,
            self.suite_11,
            self.suite_12,
            self.suite_111,
            self.suite_112,
            self.suite_121,
        ]

        db_session.add_all(self.suites)
        db_session.flush()
        for item in self.suites:
            db_session.refresh(item)

        self.suite_rels = [
            SuiteRel(parent_id=self.suite_1.id,
                     child_id=self.suite_1.id,
                     degree=0),
            SuiteRel(parent_id=self.suite_1.id,
                     child_id=self.suite_11.id,
                     degree=1),
            SuiteRel(parent_id=self.suite_1.id,
                     child_id=self.suite_12.id,
                     degree=1),
            SuiteRel(parent_id=self.suite_1.id,
                     child_id=self.suite_111.id,
                     degree=2),
            SuiteRel(parent_id=self.suite_1.id,
                     child_id=self.suite_112.id,
                     degree=2),
            SuiteRel(parent_id=self.suite_1.id,
                     child_id=self.suite_121.id,
                     degree=2),
            SuiteRel(parent_id=self.suite_11.id,
                     child_id=self.suite_11.id,
                     degree=0),
            SuiteRel(parent_id=self.suite_11.id,
                     child_id=self.suite_111.id,
                     degree=1),
            SuiteRel(parent_id=self.suite_11.id,
                     child_id=self.suite_112.id,
                     degree=1),
            SuiteRel(parent_id=self.suite_12.id,
                     child_id=self.suite_12.id,
                     degree=0),
            SuiteRel(parent_id=self.suite_12.id,
                     child_id=self.suite_121.id,
                     degree=1),
            SuiteRel(parent_id=self.suite_111.id,
                     child_id=self.suite_111.id,
                     degree=0),
            SuiteRel(parent_id=self.suite_112.id,
                     child_id=self.suite_112.id,
                     degree=0),
            SuiteRel(parent_id=self.suite_121.id,
                     child_id=self.suite_121.id,
                     degree=0),
            SuiteRel(parent_id=self.suite_2.id,
                     child_id=self.suite_2.id,
                     degree=0),
            SuiteRel(parent_id=self.suite_3.id,
                     child_id=self.suite_3.id,
                     degree=0),
        ]
        self.test_cases = [
            TestCase(suite_id=self.suite_2.id,
                     name="TC2",
                     line=1,
                     tags="[]",
                     keywords="[]"),
            TestCase(suite_id=self.suite_111.id,
                     name="TC1",
                     line=1,
                     tags="[]",
                     keywords="[]"),
            TestCase(suite_id=self.suite_111.id,
                     name="TC3",
                     line=1,
                     tags="[]",
                     keywords="[]"),
            TestCase(suite_id=self.suite_112.id,
                     name="TC4",
                     line=1,
                     tags="[]",
                     keywords="[]"),
            TestCase(suite_id=self.suite_121.id,
                     name="TC5",
                     line=1,
                     tags="[]",
                     keywords="[]"),
        ]
        db_session.add_all(self.suite_rels)
        db_session.add_all(self.test_cases)
        db_session.commit()

        # model instances
        self.model_suite_1 = SuiteRepository.from_row((self.suite_1, None, 4))
        self.model_suite_11 = SuiteRepository.from_row(
            (self.suite_11, self.suite_1.id, 3))
        self.model_suite_111 = SuiteRepository.from_row(
            (self.suite_111, self.suite_11.id, 2))
        self.model_suite_112 = SuiteRepository.from_row(
            (self.suite_112, self.suite_11.id, 1))
        self.model_suite_12 = SuiteRepository.from_row(
            (self.suite_12, self.suite_1.id, 1))
        self.model_suite_121 = SuiteRepository.from_row(
            (self.suite_121, self.suite_12.id, 1))
        self.model_suite_2 = SuiteRepository.from_row((self.suite_2, None, 1))
        self.model_suite_3 = SuiteRepository.from_row((self.suite_3, None, 0))

        self.model_suites = [
            self.model_suite_1,
            self.model_suite_11,
            self.model_suite_111,
            self.model_suite_112,
            self.model_suite_12,
            self.model_suite_121,
            self.model_suite_2,
            self.model_suite_3,
        ]

        self.hierarchy_d = SuiteHierarchy(
            name="d",
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
            suites=[],
        )
        self.hierarchy_e = SuiteHierarchy(
            name="e",
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
            suites=[],
        )
        self.hierarchy_b = SuiteHierarchy(
            name="b",
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
            suites=[self.hierarchy_d, self.hierarchy_e],
        )
        self.hierarchy_c = SuiteHierarchy(
            name="c",
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
            suites=[],
        )
        self.hierarchy_a = SuiteHierarchy(
            name="a",
            doc="doc",
            source="/path",
            keywords=KeywordRefList.of(self.keyword_refs),
            metadata=self.empty_metadata,
            suites=[self.hierarchy_b, self.hierarchy_c],
            rpa=True,
        )

        self.model_suite_a = ModelSuite(
            id=9,
            name="a",
            longname="a",
            doc="doc",
            source="/path",
            is_root=True,
            rpa=True,
            test_count=0,
            keywords=KeywordRefList.of(self.keyword_refs),
            metadata=self.empty_metadata,
        )
        self.model_suite_b = ModelSuite(
            id=10,
            name="b",
            longname="a.b",
            is_root=False,
            parent_id=9,
            test_count=0,
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
        )
        self.model_suite_c = ModelSuite(
            id=11,
            name="c",
            longname="a.c",
            is_root=False,
            parent_id=9,
            test_count=0,
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
        )
        self.model_suite_d = ModelSuite(
            id=12,
            name="d",
            longname="a.b.d",
            is_root=False,
            parent_id=10,
            test_count=0,
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
        )
        self.model_suite_e = ModelSuite(
            id=13,
            name="e",
            longname="a.b.e",
            is_root=False,
            parent_id=10,
            test_count=0,
            keywords=self.empty_keywords,
            metadata=self.empty_metadata,
        )
        self.model_suites_added = [
            self.model_suite_a,
            self.model_suite_b,
            self.model_suite_d,
            self.model_suite_e,
            self.model_suite_c,
        ]
예제 #7
0
    def setUp(self) -> None:
        db_session.rollback()
        db_session.query(TestCase).delete()
        db_session.query(Suite).delete()
        self.tc_repo = TestCaseRepository(db_session)

        self.keyword_refs = [
            KeywordRef(name="Login", args=["admin"], kw_type=KeywordType.SETUP)
        ]
        self.keyword_refs_json = (
            '[{"name": "Login", "args": ["admin"], "kw_type": "SETUP"}]')
        self.empty_keywords = KeywordRefList.of([])
        self.suite_1 = Suite(
            name="Suite 1",
            longname="Suite 1",
            keywords=self.keyword_refs_json,
            metadata_items="[]",
            is_root=True,
            rpa=False,
        )
        self.suite_2 = Suite(
            name="Suite 2",
            longname="Suite 2",
            keywords="[]",
            metadata_items="[]",
            is_root=True,
            rpa=False,
        )
        self.suites = [self.suite_1, self.suite_2]

        db_session.add_all(self.suites)
        db_session.flush()
        for item in self.suites:
            db_session.refresh(item)

        self.tc_1 = TestCase(
            suite_id=self.suite_1.id,
            name="TC1",
            line=1,
            doc="doc",
            source="source",
            template="template",
            timeout="timeout",
            tags="[]",
            keywords="[]",
        )
        self.tc_2 = TestCase(suite_id=self.suite_2.id,
                             name="TC2",
                             line=1,
                             tags="[]",
                             keywords="[]")
        self.tc_3 = TestCase(suite_id=self.suite_1.id,
                             name="TC3",
                             line=10,
                             tags="[]",
                             keywords="[]")
        self.tc_4 = TestCase(suite_id=self.suite_1.id,
                             name="TC4",
                             line=30,
                             tags="[]",
                             keywords="[]")
        self.tc_5 = TestCase(suite_id=self.suite_1.id,
                             name="TC5",
                             line=20,
                             tags="[]",
                             keywords="[]")
        self.test_cases = [
            self.tc_1, self.tc_2, self.tc_3, self.tc_4, self.tc_5
        ]
        db_session.add_all(self.test_cases)
        db_session.commit()

        self.model_tc_1 = TestCaseRepository.from_row(
            (self.tc_1, self.suite_1))
        self.model_tc_2 = TestCaseRepository.from_row(
            (self.tc_2, self.suite_2))
        self.model_tc_3 = TestCaseRepository.from_row(
            (self.tc_3, self.suite_1))
        self.model_tc_4 = TestCaseRepository.from_row(
            (self.tc_4, self.suite_1))
        self.model_tc_5 = TestCaseRepository.from_row(
            (self.tc_5, self.suite_1))
        self.model_tcs = [
            self.model_tc_1,
            self.model_tc_2,
            self.model_tc_3,
            self.model_tc_4,
            self.model_tc_5,
        ]

        self.tc_to_add = TestCase(suite_id=self.suite_2.id,
                                  name="TC_NEW",
                                  line=10,
                                  tags="[]",
                                  keywords="[]")
        self.tc_added = TestCase(
            id=6,
            suite_id=self.suite_2.id,
            name="TC_NEW",
            line=10,
            tags="[]",
            keywords="[]",
        )
        self.model_tc_to_add = TestCaseRepository.from_row(
            (self.tc_added, self.suite_2))

        self.model_tc_update = TestCaseUpdate(
            name="updated",
            line=1,
            suite_id=self.suite_2.id,
            keywords=KeywordRefList.of(self.keyword_refs),
            tags=TagList.of(["disabled"]),
        )
        self.model_tc_updated = self.model_tc_2.copy(
            update={
                "name": "updated",
                "longname": "Suite 2.updated",
                "keywords": KeywordRefList.of(self.keyword_refs),
                "tags": TagList.of(["disabled"]),
            })