コード例 #1
0
class PRMVerify:
    def __init__(self):
        super().__init__()
        self.asserter = Asserter()
        self.db_logger = DBLoggerFactory.logger
        self.id = TestDetails.test_id
        self.uuid = TestDetails.test_uuid
        self.qhandler = QueryHandler()

    def project_details(self, project_id, dct_expected):
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_invoking_method_name())
        self.step_desc = 'Verifying Project Details after Integration'
        self.step_input = 'Expected values: %s' % dct_expected

        dct_actual = self.qhandler.select_project_details(project_id)

        self.status, remarks = self.asserter.verify(dct_actual,
                                                    expected=dct_expected)
        self.remarks += remarks

        self.db_logger.log_into_steps(self)
        assert self.status

    def verify_lk_ext_id_in_prm(self, project_key):
        scode = helper.get_scode(project_key)
        external_id = self.qhandler.select_external_id(scode)

        self.status = False
        self.step_input = str(external_id)
        self.step_desc = 'Leankit External ID verification in PRM'
        self.remarks = '\n Inside class: %s method: %s \n' % core_helper.get_method_class_names(
        )

        if external_id:
            self.status = True
            self.remarks += 'Leankit External Id is present in PRM'
        else:
            self.remarks += 'Leankit External Id is not present in PRM'

        self.db_logger.log_into_steps(self)
        assert self.status
        return external_id

    def project_description(self, project_id, expected_description):
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_invoking_method_name())
        self.step_desc = 'Verifying Project Description after Integration'
        self.step_input = 'Expected Description: %s' % expected_description
        actual_description = ''

        description = self.qhandler.select_project_description(project_id)
        # Logic to concatenate the work description as they are stored in multiple rows when they are more than 1000 characters
        if description:
            desc_generator = (''.join(row[0]) for row in description)
            actual_description = ''.join(desc_generator)

        self.status, remarks = self.asserter.verify(
            actual_description,
            expected=expected_description,
            condition='is_equal_to_ignoring_case')
        self.remarks += remarks

        self.db_logger.log_into_steps(self)
        assert self.status

    def project_name(self, project_id, expected_name):
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_invoking_method_name())
        self.step_desc = 'Verifying Project Name after Integration'
        self.step_input = 'Expected Name: %s' % expected_name

        if project_id:
            actual_name = self.qhandler.select_project_name(project_id)

            self.status, remarks = self.asserter.verify(
                actual_name,
                expected=expected_name,
                condition='is_equal_to_ignoring_case')
            self.remarks += remarks
        else:
            self.status = False
            self.remarks += 'Invalid Project Id : {}'.format(project_id)

        self.db_logger.log_into_steps(self)
        assert self.status
コード例 #2
0
ファイル: board.py プロジェクト: git4rajesh/python-learnings
class Board:
    def __init__(self):
        self._get_env_details()
        self.db_logger = DBLoggerFactory.logger
        self.req_session = requests.session()
        self.asserter = Asserter()

    def _get_env_details(self):
        env = Environment()
        self.protocol = env.external_env.protocol
        self.host_name = env.external_env.name

        lk_json_const = ConstantsReader.lk_json_const
        self.headers = {"Authorization": lk_json_const['token']}

    def create(self, payload):
        pass

    def update(self, board_id, lane_id, payload):
        update_url = UPDATE_LANE_URL.format(protocol=self.protocol,
                                            host_name=self.host_name,
                                            board_id=board_id,
                                            lane_id=lane_id)
        response = self.req_session.patch(update_url,
                                          json=payload,
                                          headers=self.headers)

        self.verify_update(response, board_id, lane_id, paylaod)

    def read(self, board_id):
        read_url = READ_URL.format(protocol=self.protocol,
                                   host_name=self.host_name,
                                   board_id=board_id)
        resp = self.req_session.get(read_url, headers=self.headers)
        return resp

    def delete(self, artifact_id):
        pass

    def verify_update(self, response, board_id, lane_id, dct_expected):
        self.status = False
        self.step_desc = 'Leankit Board Lane Update verification'
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_invoking_method_name())
        self.step_input = 'Input value board_id: {0}, lane_id: {1}'.format(
            board_id, lane_id)

        if response.status_code == 200:
            read_resp = self.read(board_id)
            if read_resp.status_code == 200:
                dct_actual = objectpath_wrapper.get_dct_containing_condition(
                    'id', lane_id, read_resp)
                self.status, remarks = self.asserter.verify(
                    dct_actual, expected=dct_expected)
                self.remarks += remarks
            else:
                self.remarks += "Read Response failed with status code: {0} and response: {1}".format(
                    read_resp.status_code, read_resp.text)
        else:
            self.remarks += "Board Lane update failed with status code: {0} and response: {1}".format(
                response.status_code, response.text)

        self.db_logger.log_into_steps(self)
        assert self.status

    def verify_delete(self, card_id):
        pass
コード例 #3
0
ファイル: card.py プロジェクト: git4rajesh/python-learnings
class Card:
    tbl_name = 'LK_Card'

    def __init__(self):
        self._get_env_details()
        self.req_session = requests.session()
        self.db_logger = DBLoggerFactory.logger
        self.asserter = Asserter()

        self.id = TestDetails.test_id
        self.uuid = TestDetails.test_uuid
        self.scope = TestDetails.scope

    def _get_env_details(self):
        env = Environment()
        self.protocol = env.external_env.protocol
        self.host_name = env.external_env.name

        lk_json_const = ConstantsReader.lk_json_const
        self.headers = {"Authorization": lk_json_const['token']}

    def create(self, payload):
        create_url = CREATE_URL.format(protocol=self.protocol,
                                       host_name=self.host_name)
        response = self.req_session.post(url=create_url,
                                         json=payload,
                                         headers=self.headers)
        card_id = self.verify_create_update(response, payload)

        DataStore.insert(Card.tbl_name,
                         id=card_id,
                         name=payload['title'],
                         scope=self.scope,
                         test_id=self.id,
                         **payload)
        print("*****LK_CARD TABLE*****\n", DataStore.read_all('LK_Card'))
        return card_id

    def update(self, card_id, payload):
        update_url = UPDATE_READ_DEL_URL.format(protocol=self.protocol,
                                                host_name=self.host_name,
                                                card_id=card_id)
        response = self.req_session.patch(update_url,
                                          json=payload,
                                          headers=self.headers)

        expected_dct = {}
        for dct in payload:
            expected_key = dct['path'].split('/')[-1]
            expected_value = dct['value']
            expected_dct[expected_key] = expected_value

        self.verify_create_update(response, expected_dct)

        if 'title' in expected_dct:
            dct_update_ds = {'name': expected_dct['title']}
            DataStore.update(Card.tbl_name, dct_update_ds, id=card_id)
        else:
            DataStore.update(Card.tbl_name, expected_dct, id=card_id)

        print("*****LK_CARD TABLE*****\n", DataStore.read_all('LK_Card'))

    def move(self, card_id, payload):
        url = MOVE_URL.format(protocol=self.protocol, host_name=self.host_name)
        response = self.req_session.post(url,
                                         json=payload,
                                         headers=self.headers)

        dct_expected = payload['destination']

        self.verify_move(card_id, response, dct_expected)
        DataStore.update(Card.tbl_name, dct_expected, id=card_id)
        print("*****LK_CARD TABLE*****\n", DataStore.read_all('LK_Card'))

    def read(self, artifact_id):
        read_url = UPDATE_READ_DEL_URL.format(protocol=self.protocol,
                                              host_name=self.host_name,
                                              card_id=artifact_id)
        response = self.req_session.get(read_url, headers=self.headers)
        return response

    def delete(self, artifact_id):
        delete_url = UPDATE_READ_DEL_URL.format(protocol=self.protocol,
                                                host_name=self.host_name,
                                                card_id=artifact_id)
        self.req_session.delete(delete_url, headers=self.headers)
        self.verify_delete(artifact_id)
        DataStore.delete(Card.tbl_name, id=artifact_id)
        # On explicit deletion of a card, corresponding external_id column should be removed in PRM_Project Table
        DataStore.delete_column('PRM_Project',
                                'external_id',
                                external_id=artifact_id)
        print("*****LK_CARD TABLE*****\n", DataStore.read_all('LK_Card'))
        print("*****PRM_PROJECT TABLE AFTER EXTERNAL_ID POP UP*****\n",
              DataStore.read_all('PRM_Project'))

    def verify_create_update(self, response, dct_expected):
        self.status = False
        self.step_desc = 'Leankit Card create/update verification'
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_invoking_method_name())
        self.step_input = 'Expected response is {}'.format(dct_expected)

        card_id = None

        if response.status_code in (200, 201):
            card_id = response.json().get('id')
            read_resp = self.read(card_id)
            if read_resp.status_code == 200:
                dct_expected, dct_actual = self.construct_expected_actual_dct(
                    dct_expected, read_resp)
                self.status, remarks = self.asserter.verify(
                    dct_actual, expected=dct_expected)
                self.remarks += remarks
            else:
                self.remarks += "Read Response failed with status code: {0} and response: {1}".format(
                    read_resp.status_code, read_resp.text)
        else:
            self.remarks += "Card Creation/update failed with status code: {0} and response: {1}".format(
                response.status_code, response.text)

        self.db_logger.log_into_steps(self)
        assert self.status, self.remarks
        return card_id

    def verify_move(self, card_id, response, dct_expected):
        self.status = False
        self.step_desc = 'Leankit Card Move verification'
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_invoking_method_name())
        self.step_input = 'Input value card_id: {0}'.format(card_id)

        if response.status_code == 200:
            read_resp = self.read(card_id)
            if read_resp.status_code == 200:
                dct_expected, dct_actual = self.construct_expected_actual_dct(
                    dct_expected, read_resp)
                self.status, remarks = self.asserter.verify(
                    dct_actual, expected=dct_expected)
                self.remarks += remarks
            else:
                self.remarks += "Read Response failed with status code: {0} and response: {1}".format(
                    read_resp.status_code, read_resp.text)
        else:
            self.remarks += "Card Move failed with status code: {0} and response: {1}".format(
                response.status_code, response.text)

        self.db_logger.log_into_steps(self)
        assert self.status, self.remarks
        return card_id

    def verify_delete(self, card_id):
        self.status = False
        self.step_desc = 'Leankit Card delete verification'
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_invoking_method_name())
        self.step_input = 'Input value {}'.format(card_id)

        read_resp = self.read(card_id)

        if read_resp.status_code == 404:
            expected_msg = 'Not found.'
            actual_msg = read_resp.json()['message']

            self.status, remarks = self.asserter.verify(
                actual_msg, expected=expected_msg, condition='is_equal_to')
            self.remarks += remarks
        else:
            self.remarks += 'Card is not deleted'

        self.db_logger.log_into_steps(self)
        assert self.status, self.remarks

    def construct_expected_actual_dct(self, dct_expected, read_resp):
        if 'connections' in dct_expected:
            exp_parent_card_id = dct_expected['connections']['parents'][0]
            dct_expected.pop('connections')

            actual_parent_card_id = objectpath_wrapper.filter_dct_for_key(
                'cardId', exp_parent_card_id, 'cardId', read_resp.json())[0]
            dct_actual = helper.construct_actual(read_resp.json(),
                                                 dct_expected)

            dct_expected.update({'parent_card_id': exp_parent_card_id})
            dct_actual.update({'parent_card_id': actual_parent_card_id})
        else:
            dct_actual = helper.construct_actual(read_resp.json(),
                                                 dct_expected)

        return dct_expected, dct_actual
コード例 #4
0
class LKVerify:
    def __init__(self):
        super().__init__()
        self.asserter = Asserter()
        self.db_logger = DBLoggerFactory.logger
        self.id = TestDetails.test_id
        self.uuid = TestDetails.test_uuid
        self.card = Card()
        self.env = Environment()

    def card_details(self, card_id, dct_expected):
        # card_id = dct_expected['id']

        self.status = False
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_method_class_names())
        self.step_desc = 'Verifying Card Details after Integration'
        self.step_input = 'Expected values: %s' % dct_expected

        response = self.card.read(card_id)
        status_code = response.status_code
        if status_code == 200:
            dct_actual = helper.construct_actual(response.json(), dct_expected)
            self.status, remarks = self.asserter.verify(dct_actual,
                                                        expected=dct_expected)
            self.remarks += remarks
        else:
            self.remarks += 'Card Read API failed with status code: {0} and response: {1}'.format(
                status_code, response.text)
        self.db_logger.log_into_steps(self)
        assert self.status

    def verify_prm_ext_link_in_lk(self, card_id, prm_project_key):

        self.status = False
        self.remarks = '\n Inside feature class: %s method: %s \n' % (
            core_helper.get_method_class_names())
        self.step_desc = 'PRM External Link verification in Leankit'
        self.step_input = 'Expected values: LK Crad ID: {0}, PRM Project Key: {1}'.format(
            card_id, prm_project_key)

        read_resp = self.card.read(card_id)
        status_code = read_resp.status_code
        card_name = None
        if status_code == 200:
            card_name = read_resp.json()['title']

            scode = helper.get_scode(prm_project_key)
            protocol = self.env.pve.protocol
            host_name = self.env.pve.name

            actual_external_url = objectpath_wrapper.filter_dct_for_key(
                'label', 'Enterprise One', 'url', read_resp.json())[0]
            expected_url = '{protocol}://{host_name}/planview/PLP/EntityLandingPage.aspx?pt=PROJECT&scode={scode}'.format(
                protocol=protocol, host_name=host_name, scode=scode)

            self.status, remarks = self.asserter.verify(
                actual_external_url,
                expected=expected_url,
                condition='is_equal_to_ignoring_case')
            self.remarks += remarks
        else:
            self.remarks += 'PRM External link is not Present in Leankit after Integration'

        self.db_logger.log_into_steps(self)
        assert self.status
        return card_name