Example #1
0
    def __init__(self, protocol='PROTOCOL', host='DATAPLATFORM_HOST',
                 port='DATAPLATFORM_PORT', basepath='GO_AUTH_BASEPATH',
                 client_header='GO_CLIENT_HEADER',
                 timeout='PLATFORM_API_TIMEOUT'):
        ''' usage:
                __dirname = os.path.dirname(os.path.abspath(__file__))
                sys.path.append(os.path.join(__dirname, '../../lib'))
                from _init_ import _init_
                self.init = _init_()

            Note:
                - default host is `DATAPLATFORM_HOST` and basepath is `/go-platform/v1`
                - if need to use other host, please follow below example:
                    `self.init = _init_('Other_URL', '/api/v1')`
        '''
        self.LibAppCipher = LibAppCipher()
        self.LibVar = LibVar()
        self.PROTOCOL = self.LibVar.get_var(protocol)
        self.PORT = self.LibVar.get_var(port)
        self._BASEPATH = self.LibVar.get_var(basepath)
        self.GO_CLIENT_HEADER = self.LibVar.get_var(client_header)
        self.TIMEOUT = self.LibVar.get_var(timeout)
        self.HOST = self.LibVar.get_var(host)
        self.HOST = '{}://{}:{}{}'.format(self.PROTOCOL,
                                          self.HOST, self.PORT, self._BASEPATH)
        self.SESSION = requests.Session()
        self.TOKEN = None
        self.SESSION.headers.update({
            'content-type': 'application/json',
            'Go-client': '{}'.format(self.GO_CLIENT_HEADER)
        })
Example #2
0
 def __init__(self, password='******'):
     rf_string = String()  # RF Library
     self.user_id = None
     self.contract_owner_id = None
     self.birthday = time.strftime("%Y-%m-%d")
     self.company_code = 1300
     self.contact_address = '長安東路二段225號C棟11樓'
     self.contact_city = '臺北市'
     self.contact_district = '松山區'
     self.contact_zip = '10552'
     self.country_code = 'TW'
     self.enable_e_carrier = 1
     self.encode_password = LibAppCipher().encode_password_get(
         password).text
     self.first_name = rf_string.generate_random_string(5, '[UPPER]')
     self.last_name = rf_string.generate_random_string(5, '[UPPER]')
     self.gender = 'M'
     self.gogoro_guid = str(uuid.uuid4())
     self.invoice_address = '長安東路二段225號C棟11樓'
     self.invoice_city = '臺北市'
     self.invoice_district = '松山區'
     self.invoice_zip = '10552'
     self.mobile = '09' + rf_string.generate_random_string(8, '[NUMBERS]')
     self.occupation = '1'
     self.phone = self.mobile
     self.login_phone = self.mobile
     self.status = 1
     self.time = int(time.time() * 1000)
     self.display_name = self.last_name + self.first_name
     self.email = 'pasw.verify+{}@gogoro.com'.format(self.time)
     self.profile_id = 'E1' + \
         rf_string.generate_random_string(8, '[NUMBERS]')
Example #3
0
    def get_credit_card_and_delete(user_id, wallet_id, credit_card_number):
        credit_card_id = None
        auth = LibAppCipher().app_cipher_get(account=None)
        response = Wallet()
        get_json = response.get_credit_cards(wallet_id, auth).json()

        for i in get_json['data']:
            if i['credit_card_number'] == credit_card_number:
                credit_card_id = i['credit_card_id']

        if credit_card_id is None:
            raise Exception('The credit card is not activate')

        delete_json = response.delete_credit_cards(wallet_id, user_id, credit_card_id, auth).json()
        if delete_json['code'] != 0:
            raise Exception('Delete user_id: {} wallet_id:{} credit_card_number:{} is failure'
                            .format(user_id, wallet_id, credit_card_number))
Example #4
0
 def __init__(self, password='******'):
     rf_string = String()  # RF Library
     self.time = int(time.time() * 1000)
     self.emp_code = 'SWQA_{}'.format(self.time)
     self.contact_address = '長安東路二段225號C棟11樓'
     self.contact_zip = '10552'
     self.encode_password = LibAppCipher().encode_password_get(
         password).text
     self.first_name = rf_string.generate_random_string(5, '[UPPER]')
     self.middle_name = rf_string.generate_random_string(5, '[UPPER]')
     self.last_name = rf_string.generate_random_string(5, '[UPPER]')
     self.legal_first_name = rf_string.generate_random_string(5, '[UPPER]')
     self.legal_middle_name = rf_string.generate_random_string(5, '[UPPER]')
     self.legal_last_name = rf_string.generate_random_string(5, '[UPPER]')
     self.gender = 'M'
     self.mobile = '09' + rf_string.generate_random_string(8, '[NUMBERS]')
     self.phone = self.mobile
     self.email = 'sw.verify+{}@gogoro.com'.format(self.time)
     self.profile_id = 'E1' + \
         rf_string.generate_random_string(8, '[NUMBERS]')
Example #5
0
class _init_(object):

    def __init__(self, protocol='PROTOCOL', host='DATAPLATFORM_HOST',
                 port='DATAPLATFORM_PORT', basepath='GO_AUTH_BASEPATH',
                 client_header='GO_CLIENT_HEADER',
                 timeout='PLATFORM_API_TIMEOUT'):
        ''' usage:
                __dirname = os.path.dirname(os.path.abspath(__file__))
                sys.path.append(os.path.join(__dirname, '../../lib'))
                from _init_ import _init_
                self.init = _init_()

            Note:
                - default host is `DATAPLATFORM_HOST` and basepath is `/go-platform/v1`
                - if need to use other host, please follow below example:
                    `self.init = _init_('Other_URL', '/api/v1')`
        '''
        self.LibAppCipher = LibAppCipher()
        self.LibVar = LibVar()
        self.PROTOCOL = self.LibVar.get_var(protocol)
        self.PORT = self.LibVar.get_var(port)
        self._BASEPATH = self.LibVar.get_var(basepath)
        self.GO_CLIENT_HEADER = self.LibVar.get_var(client_header)
        self.TIMEOUT = self.LibVar.get_var(timeout)
        self.HOST = self.LibVar.get_var(host)
        self.HOST = '{}://{}:{}{}'.format(self.PROTOCOL,
                                          self.HOST, self.PORT, self._BASEPATH)
        self.SESSION = requests.Session()
        self.TOKEN = None
        self.SESSION.headers.update({
            'content-type': 'application/json',
            'Go-client': '{}'.format(self.GO_CLIENT_HEADER)
        })

    def auth_header(self, account):
        self.TOKEN = self.LibAppCipher.app_cipher_get(account)
        authorization = '{}'.format(self.TOKEN)
        self.SESSION.headers.update(
            {'Authorization': 'Bearer {}'.format(authorization)})

    def request(self, method, append='', **kwargs):
        ''' method:
                e.g.: get post patch delete
            append:
                e.g.: /scooter
            **kwargs:
                e.g.: data={"scooter":"qa"}
        '''
        url = self.HOST + append
        resp = self.SESSION.request(
            method, url, **kwargs, timeout=self.TIMEOUT)

        try:
            tags = BuiltIn().get_variable_value("${TEST_TAGS}")
        except:
            tags = []
            pass

        body = json.loads(resp.request.body.decode())
        body = json.dumps(body, indent=4)

        resp_msg = json.loads(resp.text)
        resp_msg = json.dumps(resp_msg, indent=4)

        request_msg = (
            "Response message: {resp_status_code}\n"
            "Body: {resp_msg}\n"
            "CURL:\n"
            "   curl -i --request {method} --url {url} \\\n"
            "   --header 'Authorization: {token}' \\\n"
            "   --header 'content-type: {content_type}' --header 'go-client: {go_client}' \\\n"
            "   --data '{body}'"
        ).format(
            resp_status_code=resp.status_code,
            resp_msg=resp_msg,
            method=resp.request.method,
            url=(self.HOST + append),
            token=resp.request.headers['Authorization'],
            content_type=resp.request.headers['Content-Type'],
            go_client=resp.request.headers['Go-client'],
            body=body
        )

        if ('code' not in resp.json().keys() or resp.json()['code'] != 0) and 'FET' not in tags:
            raise AssertionError(
                "FYI: If the API request is failed, please refer to the following information \n{}".format(
                    request_msg)
            )
        else:
            logger.write(request_msg)
        return resp