コード例 #1
0
 def test_should_fail_to_update_test_case_to_invalid_suite_id(self) -> None:
     to_update = self.model_tc_update.copy(update={"suite_id": 999})
     with self.assertRaises(IntegrityError):
         self.tc_repo.update(self.tc_2, dict(to_update))
     db_session.rollback()
     result = self.tc_repo.get_all()
     self.assertEqual(result, self.model_tcs)
コード例 #2
0
ファイル: base_repo_tests.py プロジェクト: mbrzozowski/rfhub2
    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)
コード例 #3
0
 def test_should_fail_to_add_duplicated_test_case_to_suite(self) -> None:
     self.tc_to_add.name = "TC2"
     with self.assertRaises(IntegrityError):
         self.tc_repo.add(self.tc_to_add)
     db_session.rollback()
     result = self.tc_repo.get_all()
     self.assertEqual(result, self.model_tcs)
コード例 #4
0
 def test_should_fail_to_add_test_case_with_invalid_suite_id(self) -> None:
     self.tc_to_add.suite_id = 999
     with self.assertRaises(IntegrityError):
         self.tc_repo.add(self.tc_to_add)
     db_session.rollback()
     result = self.tc_repo.get_all()
     self.assertEqual(result, self.model_tcs)
コード例 #5
0
 def setUp(self) -> None:
     self.app = create_app()
     db_session.rollback()
     recreate_data(db_session)
     self.client: TestClient = TestClient(self.app)
     self.auth_client: TestClient = TestClient(self.app)
     self.auth_client.auth = (config.BASIC_AUTH_USER,
                              config.BASIC_AUTH_PASSWORD)
コード例 #6
0
 def test_should_fail_to_update_test_case_to_duplicate(self) -> None:
     to_update = self.model_tc_update.copy(update={
         "name": "TC1",
         "suite_id": self.suite_1.id
     })
     with self.assertRaises(IntegrityError):
         self.tc_repo.update(self.tc_2, dict(to_update))
     db_session.rollback()
     result = self.tc_repo.get_all()
     self.assertEqual(result, self.model_tcs)
コード例 #7
0
ファイル: suite_repo_tests.py プロジェクト: pbylicki/rfhub2
    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,
        ]
コード例 #8
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"]),
            })