Exemplo n.º 1
0
    def test_find_nonexistent_data(self):
        """
        The GET interface queries data that does not exist
        :return:
        """
        with app.app_context():

            resp = self.client.get("/tracking?repo=aa&branch=aa")

            resp_dict = json.loads(resp.data)

            self.assertIn("code", resp_dict, msg="Error in data format return")
            self.assertEqual(ResponseCode.SUCCESS,
                             resp_dict.get("code"),
                             msg="Error in status code return")

            self.assertIn("msg", resp_dict, msg="Error in data format return")
            self.assertEqual(ResponseCode.CODE_MSG_MAP.get(
                ResponseCode.SUCCESS),
                             resp_dict.get("msg"),
                             msg="Error in status code return")

            self.assertIn("data", resp_dict, msg="Error in data format return")
            self.assertIsNotNone(resp_dict.get("data"),
                                 msg="Error in data information return")
            self.assertEqual(resp_dict.get("data"), [],
                             msg="Error in data information return")
Exemplo n.º 2
0
    def test_find_all_data(self):
        '''
        The GET interface queries all the data
        :return:
        '''
        with app.app_context():
            data_insert_c = {"issue": "C", "repo": "C", "branch": "C"}
            data_insert_d = {"issue": "D", "repo": "D", "branch": "D"}
            create_issue(data_insert_c)
            create_issue(data_insert_d)
            resp = self.client.get("/issue")

            resp_dict = json.loads(resp.data)

            self.assertIn("code", resp_dict, msg="Error in data format return")
            self.assertEqual(ResponseCode.SUCCESS, resp_dict.get("code"), msg="Error in status code return")

            self.assertIn("msg", resp_dict, msg="Error in data format return")
            self.assertEqual(
                ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS),
                resp_dict.get("msg"),
                msg="Error in status code return"
            )

            self.assertIn("data", resp_dict, msg="Error in data format return")
            self.assertIsNotNone(resp_dict.get("data"), msg="Error in data information return")
            self.assertIn(data_insert_c, resp_dict.get("data"), msg="Error in data information return")
            self.assertIn(data_insert_d, resp_dict.get("data"), msg="Error in data information return")
Exemplo n.º 3
0
    def test_none_data(self):
        """
        In the absence of data, the GET interface queries all the data
        :return:
        """
        with app.app_context():

            resp = self.client.get("/tracking")

            resp_dict = json.loads(resp.data)

            self.assertIn("code", resp_dict, msg="Error in data format return")
            self.assertEqual(ResponseCode.SUCCESS,
                             resp_dict.get("code"),
                             msg="Error in status code return")

            self.assertIn("msg", resp_dict, msg="Error in data format return")
            self.assertEqual(ResponseCode.CODE_MSG_MAP.get(
                ResponseCode.SUCCESS),
                             resp_dict.get("msg"),
                             msg="Error in status code return")

            self.assertIn("data", resp_dict, msg="Error in data format return")
            self.assertIsNotNone(resp_dict.get("data"),
                                 msg="Error in data information return")
            self.assertEqual(resp_dict.get("data"), [],
                             msg="Error in data information return")
Exemplo n.º 4
0
    def test_query_inserted_data(self):
        '''
        The GET interface queries existing data
        :return:
        '''
        with app.app_context():
            data_insert = {"issue": "A", "repo": "A", "branch": "A"}

            create_issue(data_insert)

            resp = self.client.get("/issue?repo=A&branch=A")

            resp_dict = json.loads(resp.data)

            self.assertIn("code", resp_dict, msg="Error in data format return")
            self.assertEqual(ResponseCode.SUCCESS, resp_dict.get("code"), msg="Error in status code return")

            self.assertIn("msg", resp_dict, msg="Error in data format return")
            self.assertEqual(
                ResponseCode.CODE_MSG_MAP.get(ResponseCode.SUCCESS),
                resp_dict.get("msg"),
                msg="Error in status code return"
            )

            self.assertIn("data", resp_dict, msg="Error in data format return")
            self.assertIsNotNone(resp_dict.get("data"), msg="Error in data information return")
            self.assertIn(data_insert, resp_dict.get("data"), msg="Error in data information return")
Exemplo n.º 5
0
    def test_get_interface_uppercase(self):
        '''
        The get interface uppercase
        :return:
        '''
        with app.app_context():
            data_insert = {"issue": "CCC", "repo": "CCC", "branch": "CCC"}

            create_issue(data_insert)

            resp = self.client.get("/issue?RrPo=CCC&brANch=CCC")

            resp_dict = json.loads(resp.data)

            self.assertIn("code", resp_dict, msg="Error in data format return")
            self.assertEqual(
                ResponseCode.INPUT_PARAMETERS_ERROR, resp_dict.get("code"), msg="Error in status code return"
            )

            self.assertIn("msg", resp_dict, msg="Error in data format return")
            self.assertEqual(
                ResponseCode.CODE_MSG_MAP.get(ResponseCode.INPUT_PARAMETERS_ERROR),
                resp_dict.get("msg"),
                msg="Error in status code return"
            )

            self.assertIn("data", resp_dict, msg="Error in data format return")
            self.assertEqual(resp_dict.get("data"), None, msg="Error in data information return")
Exemplo n.º 6
0
    def test_get_error_parameters(self):
        '''
        The get interface passes in the wrong parameter
        :return:
        '''
        with app.app_context():
            data_insert = {"issue": "BB", "repo": "BB", "branch": "BB"}

            create_issue(data_insert)

            resp = self.client.get("/issue?oper=BB&chcnsrb=BB")

            resp_dict = json.loads(resp.data)
            self.assertIn("code", resp_dict, msg="Error in data format return")
            self.assertEqual(
                ResponseCode.INPUT_PARAMETERS_ERROR, resp_dict.get("code"), msg="Error in status code return"
            )

            self.assertIn("msg", resp_dict, msg="Error in data format return")
            self.assertEqual(
                ResponseCode.CODE_MSG_MAP.get(ResponseCode.INPUT_PARAMETERS_ERROR),
                resp_dict.get("msg"),
                msg="Error in status code return"
            )

            self.assertIn("data", resp_dict, msg="Error in data format return")
            self.assertEqual(resp_dict.get("data"), None, msg="Error in data information return")
Exemplo n.º 7
0
    def test_query_inserted_data(self):
        """
        The GET interface queries existing data
        :return:
        """
        with app.app_context():
            data_github = {
                "version_control": "github",
                "scm_repo": "B",
                "scm_branch": "B",
                "scm_commit": "B",
                "repo": "B1",
                "branch": "B1",
                "enabled": False
            }

            data_git = {
                "version_control": "git",
                "scm_repo": "B",
                "scm_branch": "B",
                "scm_commit": "B",
                "repo": "B2",
                "branch": "B2",
                "enabled": False
            }

            for data_insert in [data_github, data_git]:
                create_tracking(data_insert)

                resp = self.client.get("/tracking?repo={}&branch={}".format(
                    data_insert["repo"], data_insert["branch"]))

                resp_dict = json.loads(resp.data)
                self.assertIn("code",
                              resp_dict,
                              msg="Error in data format return")
                self.assertEqual(ResponseCode.SUCCESS,
                                 resp_dict.get("code"),
                                 msg="Error in status code return")

                self.assertIn("msg",
                              resp_dict,
                              msg="Error in data format return")
                self.assertEqual(ResponseCode.CODE_MSG_MAP.get(
                    ResponseCode.SUCCESS),
                                 resp_dict.get("msg"),
                                 msg="Error in status code return")

                self.assertIn("data",
                              resp_dict,
                              msg="Error in data format return")
                self.assertIsNotNone(resp_dict.get("data"),
                                     msg="Error in data information return")
                self.assertIn(data_insert,
                              resp_dict.get("data"),
                              msg="Error in data information return")
Exemplo n.º 8
0
    def test_get_interface_uppercase(self):
        """
        The get interface uppercase
        :return:
        """
        with app.app_context():
            data_github = {
                "version_control": "github",
                "scm_repo": "BBB",
                "scm_branch": "BBB",
                "scm_commit": "BBB",
                "repo": "BBB1",
                "branch": "BBB1",
                "enabled": False
            }

            data_git = {
                "version_control": "github",
                "scm_repo": "BBB",
                "scm_branch": "BBB",
                "scm_commit": "BBB",
                "repo": "BBB2",
                "branch": "BBB2",
                "enabled": False
            }

            for data_insert in [data_github, data_git]:
                create_tracking(data_insert)

                resp = self.client.get("/tracking?rep=BBB&BRAnch=BBB")

                resp_dict = json.loads(resp.data)
                self.assertIn("code",
                              resp_dict,
                              msg="Error in data format return")
                self.assertEqual(ResponseCode.INPUT_PARAMETERS_ERROR,
                                 resp_dict.get("code"),
                                 msg="Error in status code return")

                self.assertIn("msg",
                              resp_dict,
                              msg="Error in data format return")
                self.assertEqual(ResponseCode.CODE_MSG_MAP.get(
                    ResponseCode.INPUT_PARAMETERS_ERROR),
                                 resp_dict.get("msg"),
                                 msg="Error in status code return")

                self.assertIn("data",
                              resp_dict,
                              msg="Error in data format return")
                self.assertEqual(resp_dict.get("data"),
                                 None,
                                 msg="Error in data information return")
Exemplo n.º 9
0
    def test_update_data(self):
        """
        update data
        :return:
        """
        with app.app_context():
            data_old_list = [{
                "version_control": "github",
                "scm_repo": "str",
                "scm_branch": "str",
                "scm_commit": "str",
                "repo": "string",
                "branch": "string",
                "enabled": False
            }, {
                "version_control": "git",
                "scm_repo": "str",
                "scm_branch": "str",
                "scm_commit": "str",
                "repo": "string",
                "branch": "string",
                "enabled": False
            }]
            data_new_list = [{
                "version_control": "github",
                "scm_repo": "string",
                "scm_branch": "string",
                "scm_commit": "string",
                "repo": "string",
                "branch": "string",
                "enabled": False
            }, {
                "branch": "string",
                "enabled": True,
                "repo": "string",
                "scm_branch": "string",
                "scm_commit": "string",
                "scm_repo": "string",
                "version_control": "git",
            }]

            for data_old, data_new in zip(data_old_list, data_new_list):
                self.client.post("/tracking",
                                 json=data_old,
                                 content_type="application/json",
                                 headers=self.auth)
                self.client.post("/tracking",
                                 json=data_new,
                                 content_type="application/json")

                resp = self.client.get("/tracking?repo=string&branch=string")

                resp_dict = json.loads(resp.data)
                self.assertIn("code",
                              resp_dict,
                              msg="Error in data format return")
                self.assertEqual(ResponseCode.SUCCESS,
                                 resp_dict.get("code"),
                                 msg="Error in status code return")

                self.assertIn("msg",
                              resp_dict,
                              msg="Error in data format return")
                self.assertEqual(ResponseCode.CODE_MSG_MAP.get(
                    ResponseCode.SUCCESS),
                                 resp_dict.get("msg"),
                                 msg="Error in status code return")

                self.assertIn("data",
                              resp_dict,
                              msg="Error in data format return")
                self.assertIsNotNone(resp_dict.get("data"),
                                     msg="Error in data information return")
Exemplo n.º 10
0
def reset():
    """
    reset database
    """
    with app.app_context():
        reset_database()