Ejemplo n.º 1
0
    def test_build_collection_ok(self, f_users, f_coprs, f_builds, f_db,
                           f_users_api, f_mock_chroots):

        href = "/api_2/builds"
        self.db.session.commit()
        r = self.tc.get(href)
        assert r.status_code == 200
        obj = json.loads(r.data.decode("utf-8"))

        # not a pure test, but we test API here
        builds = BuildsLogic.get_multiple().all()
        expected_ids = set([b.id for b in builds])

        assert expected_ids == self.extract_build_ids(obj)
Ejemplo n.º 2
0
    def test_build_collection_ok(self, f_users, f_coprs, f_builds, f_db,
                                 f_users_api, f_mock_chroots):

        href = "/api_2/builds"
        self.db.session.commit()
        r = self.tc.get(href)
        assert r.status_code == 200
        obj = json.loads(r.data.decode("utf-8"))

        # not a pure test, but we test API here
        builds = BuildsLogic.get_multiple().all()
        expected_ids = set([b.id for b in builds])

        assert expected_ids == self.extract_build_ids(obj)
Ejemplo n.º 3
0
    def test_build_collection_by_project_id(self, f_users, f_mock_chroots,
                                            f_coprs, f_builds, f_db):

        project_id_list = [copr.id for copr in self.basic_coprs_list]
        for id_ in project_id_list:
            href = "/api_2/builds?project_id={}".format(id_)
            self.db.session.commit()
            r = self.tc.get(href)
            assert r.status_code == 200
            obj = json.loads(r.data.decode("utf-8"))

            # not a pure test, but we test API here
            builds = [
                b for b in BuildsLogic.get_multiple().all() if b.copr.id == id_
            ]
            expected_ids = set([b.id for b in builds])
            assert expected_ids == self.extract_build_ids(obj)
Ejemplo n.º 4
0
    def test_build_collection_by_project_id(
            self, f_users, f_mock_chroots, f_coprs,  f_builds, f_db):

        project_id_list = [copr.id for copr in self.basic_coprs_list]
        for id_ in project_id_list:
            href = "/api_2/builds?project_id={}".format(id_)
            self.db.session.commit()
            r = self.tc.get(href)
            assert r.status_code == 200
            obj = json.loads(r.data.decode("utf-8"))

            # not a pure test, but we test API here
            builds = [
                b for b in BuildsLogic.get_multiple().all()
                if b.copr.id == id_
            ]
            expected_ids = set([b.id for b in builds])
            assert expected_ids == self.extract_build_ids(obj)
Ejemplo n.º 5
0
    def test_build_collection_by_owner(self, f_users, f_coprs, f_builds, f_db,
                           f_users_api, f_mock_chroots):

        names_list = [user.username for user in self.basic_user_list]
        for user_name in names_list:
            href = "/api_2/builds?owner={}".format(user_name)
            self.db.session.commit()
            r = self.tc.get(href)
            assert r.status_code == 200
            obj = json.loads(r.data.decode("utf-8"))

            # not a pure test, but we test API here
            builds = [
                b for b in BuildsLogic.get_multiple().all()
                if b.copr.owner.username == user_name
            ]
            expected_ids = set([b.id for b in builds])
            assert expected_ids == self.extract_build_ids(obj)
Ejemplo n.º 6
0
    def test_build_collection_by_owner(self, f_users, f_coprs, f_builds, f_db,
                                       f_users_api, f_mock_chroots):

        names_list = [user.username for user in self.basic_user_list]
        for user_name in names_list:
            href = "/api_2/builds?owner={}".format(user_name)
            self.db.session.commit()
            r = self.tc.get(href)
            assert r.status_code == 200
            obj = json.loads(r.data.decode("utf-8"))

            # not a pure test, but we test API here
            builds = [
                b for b in BuildsLogic.get_multiple().all()
                if b.copr.owner.username == user_name
            ]
            expected_ids = set([b.id for b in builds])
            assert expected_ids == self.extract_build_ids(obj)
Ejemplo n.º 7
0
    def test_build_collection_ok_finished(
            self, f_users, f_coprs, f_mock_chroots,  f_builds, f_db):

        self.db.session.commit()

        href_a = "/api_2/builds?is_finished=True"
        href_b = "/api_2/builds?is_finished=False"

        r_a = self.tc.get(href_a)
        r_b = self.tc.get(href_b)

        assert r_a.status_code == 200
        assert r_b.status_code == 200
        obj_a = json.loads(r_a.data.decode("utf-8"))
        obj_b = json.loads(r_b.data.decode("utf-8"))

        builds = BuildsLogic.get_multiple().all()
        expected_ids_a = set([b.id for b in builds if b.max_ended_on is not None])
        expected_ids_b = set([b.id for b in builds if b.max_ended_on is None])

        assert expected_ids_a == self.extract_build_ids(obj_a)
        assert expected_ids_b == self.extract_build_ids(obj_b)
Ejemplo n.º 8
0
    def test_build_collection_ok_finished(self, f_users, f_coprs,
                                          f_mock_chroots, f_builds, f_db):

        self.db.session.commit()

        href_a = "/api_2/builds?is_finished=True"
        href_b = "/api_2/builds?is_finished=False"

        r_a = self.tc.get(href_a)
        r_b = self.tc.get(href_b)

        assert r_a.status_code == 200
        assert r_b.status_code == 200
        obj_a = json.loads(r_a.data.decode("utf-8"))
        obj_b = json.loads(r_b.data.decode("utf-8"))

        builds = BuildsLogic.get_multiple().all()
        expected_ids_a = set([b.id for b in builds if b.ended_on is not None])
        expected_ids_b = set([b.id for b in builds if b.ended_on is None])

        assert expected_ids_a == self.extract_build_ids(obj_a)
        assert expected_ids_b == self.extract_build_ids(obj_b)
Ejemplo n.º 9
0
    def test_build_collection_limit_offset(
            self, f_users, f_mock_chroots, f_coprs, f_builds, f_db):

        self.db.session.commit()
        builds = BuildsLogic.get_multiple().all()
        total = len(builds)

        # test limit
        for lim in range(1, total + 1):
            href = "/api_2/builds?limit={}".format(lim)
            r = self.tc.get(href)
            assert r.status_code == 200
            obj = json.loads(r.data.decode("utf-8"))
            builds = obj["builds"]
            assert len(builds) == lim

            if lim > 2:
                delta = int(math.floor(lim / 2))
                href1 = "/api_2/builds?limit={}".format(delta)
                href2 = "/api_2/builds?limit={0}&offset={0}".format(delta)

                r1 = self.tc.get(href1)
                r2 = self.tc.get(href2)

                assert r1.status_code == 200
                assert r2.status_code == 200

                obj1 = json.loads(r1.data.decode("utf-8"))
                obj2 = json.loads(r2.data.decode("utf-8"))

                assert builds[:delta] == obj1["builds"]
                assert builds[delta:2 * delta] == obj2["builds"]

        # for coverage
        href = "/api_2/builds?limit={}".format(1000000)
        r = self.tc.get(href)
        assert r.status_code == 200
Ejemplo n.º 10
0
    def test_build_collection_limit_offset(self, f_users, f_mock_chroots,
                                           f_coprs, f_builds, f_db):

        self.db.session.commit()
        builds = BuildsLogic.get_multiple().all()
        total = len(builds)

        # test limit
        for lim in range(1, total + 1):
            href = "/api_2/builds?limit={}".format(lim)
            r = self.tc.get(href)
            assert r.status_code == 200
            obj = json.loads(r.data.decode("utf-8"))
            builds = obj["builds"]
            assert len(builds) == lim

            if lim > 2:
                delta = int(math.floor(lim / 2))
                href1 = "/api_2/builds?limit={}".format(delta)
                href2 = "/api_2/builds?limit={0}&offset={0}".format(delta)

                r1 = self.tc.get(href1)
                r2 = self.tc.get(href2)

                assert r1.status_code == 200
                assert r2.status_code == 200

                obj1 = json.loads(r1.data.decode("utf-8"))
                obj2 = json.loads(r2.data.decode("utf-8"))

                assert builds[:delta] == obj1["builds"]
                assert builds[delta:2 * delta] == obj2["builds"]

        # for coverage
        href = "/api_2/builds?limit={}".format(1000000)
        r = self.tc.get(href)
        assert r.status_code == 200