コード例 #1
0
    def setUp(self) -> None:
        super().setUp()
        self.app = init_flask_api().test_client()
        self.company_1 = Company(id=1,
                                 source_id=1,
                                 source_name="dataset_A",
                                 name="1")
        self.company_2 = Company(id=2,
                                 source_id=2,
                                 source_name="dataset_A",
                                 name="2")
        self.company_3 = Company(id=3,
                                 source_id=1,
                                 source_name="dataset_B",
                                 name="3")
        self.company_4 = Company(id=4,
                                 source_id=2,
                                 source_name="dataset_B",
                                 name="4")

        self.match = Match(
            id=1,
            left_company_id=self.company_1.id,
            right_company_id=self.company_3.id,
        )
        self.match_2 = Match(
            id=2,
            left_company_id=self.company_2.id,
            right_company_id=self.company_4.id,
        )
コード例 #2
0
    def get(self, match_id: int):
        session = Match.session_from_engine(self.engine)
        match = Match.fetch_one(session, match_id)

        session.close()

        if not match:
            return {}, 404
        return marshal(match, self.MARSHAL_MATCH), 200
コード例 #3
0
    def delete(self, match_id: int):
        session = Match.session_from_engine(self.engine)
        match = Match.fetch_one(session, match_id)

        if not match:
            session.close()
            return {}, 404

        match.delete(session)
        session.commit()
        return marshal(match, self.MARSHAL_MATCH), 200
コード例 #4
0
    def get(self):
        args = self._index_parser().parse_args()
        page = args.get("page") or 0
        limit = args.get("limit") or 100
        if limit > 100:
            limit = 100

        session = Match.session_from_engine(self.engine)
        matches = Match.fetch_all(session, limit, page * limit,
                                  args.get('company'))
        session.close()

        return marshal(matches, MatchView.MARSHAL_MATCH), 200
コード例 #5
0
    def setUp(self) -> None:
        super().setUp()
        self.session = Company.session_from_path(self.db_path)
        self.company_1 = Company(source_id=1, source_name="testA", name="A")
        self.company_2 = Company(source_id=2, source_name="testB", name="B")

        self.session.add(self.company_1)
        self.session.add(self.company_2)

        self.match = Match(id=1,
                           left_company=self.company_1,
                           right_company=self.company_2)
        self.session.add(self.match)
        self.session.commit()
コード例 #6
0
    def test_fetch_one_match(self):
        returned = Match.fetch_one(self.session, 1)

        self.assertIsNotNone(returned)
        self.assertEqual(self.match.id, returned.id)
        self.assertEqual(self.match.left_company_id, returned.left_company_id)
        self.assertEqual(self.match.right_company_id,
                         returned.right_company_id)
コード例 #7
0
    def test_fetch_all_filter_company(self):
        company_3 = Company(source_id=2, source_name="testB", name="B")
        company_4 = Company(source_id=2, source_name="testB", name="B")
        match_2 = Match(id=2, left_company=company_3, right_company=company_4)
        match_3 = Match(id=3,
                        left_company=company_4,
                        right_company=self.company_2)
        self.session.add(company_3)
        self.session.add(company_4)
        self.session.add(match_2)
        self.session.add(match_3)
        self.session.flush()

        matches = Match.fetch_all(self.session, 5, 0, company_id=company_4.id)

        self.assertEqual(2, len(matches))
        self.assertEqual(sorted([m.id for m in [match_2, match_3]]),
                         sorted([m.id for m in matches]))
コード例 #8
0
    def test_fetch_all(self):
        matches = Match.fetch_all(self.session, 5, 0)

        self.assertEqual(1, len(matches))
        self.assertEqual(self.match.id, matches[0].id)
コード例 #9
0
class MatchTestCase(ModelTestCase):
    def setUp(self) -> None:
        super().setUp()
        self.session = Company.session_from_path(self.db_path)
        self.company_1 = Company(source_id=1, source_name="testA", name="A")
        self.company_2 = Company(source_id=2, source_name="testB", name="B")

        self.session.add(self.company_1)
        self.session.add(self.company_2)

        self.match = Match(id=1,
                           left_company=self.company_1,
                           right_company=self.company_2)
        self.session.add(self.match)
        self.session.commit()

    def tearDown(self) -> None:
        super().tearDown()
        self.session.close()

    def test_fetch_all(self):
        matches = Match.fetch_all(self.session, 5, 0)

        self.assertEqual(1, len(matches))
        self.assertEqual(self.match.id, matches[0].id)

    def test_fetch_all_filter_company(self):
        company_3 = Company(source_id=2, source_name="testB", name="B")
        company_4 = Company(source_id=2, source_name="testB", name="B")
        match_2 = Match(id=2, left_company=company_3, right_company=company_4)
        match_3 = Match(id=3,
                        left_company=company_4,
                        right_company=self.company_2)
        self.session.add(company_3)
        self.session.add(company_4)
        self.session.add(match_2)
        self.session.add(match_3)
        self.session.flush()

        matches = Match.fetch_all(self.session, 5, 0, company_id=company_4.id)

        self.assertEqual(2, len(matches))
        self.assertEqual(sorted([m.id for m in [match_2, match_3]]),
                         sorted([m.id for m in matches]))

    def test_fetch_one_match(self):
        returned = Match.fetch_one(self.session, 1)

        self.assertIsNotNone(returned)
        self.assertEqual(self.match.id, returned.id)
        self.assertEqual(self.match.left_company_id, returned.left_company_id)
        self.assertEqual(self.match.right_company_id,
                         returned.right_company_id)

    def test_fetch_one_not_found(self):
        returned = Match.fetch_one(self.session, 3)

        self.assertIsNone(returned)

    def test_delete(self):
        self.match.delete(self.session)
        self.session.commit()

        self.assertIsNone(Match.fetch_one(self.session, self.match.id))
コード例 #10
0
    def test_delete(self):
        self.match.delete(self.session)
        self.session.commit()

        self.assertIsNone(Match.fetch_one(self.session, self.match.id))
コード例 #11
0
    def test_fetch_one_not_found(self):
        returned = Match.fetch_one(self.session, 3)

        self.assertIsNone(returned)