Ejemplo n.º 1
0
    def post_method(self):
        try:
            util_obj = PropertiesUtil()
            util_obj.cybs_path = os.path.join(
                os.getcwd(), "samples/authentication/Resources", "cybs.json")
            details_dict1 = util_obj.properties_util()

            mconfig = MerchantConfiguration()
            mconfig.set_merchantconfig(details_dict1)

            mconfig.validate_merchant_details(details_dict1, mconfig)

            mconfig.request_json_path_data = request_data.json_file_data(
                self.request_json_path, mconfig)

            mconfig.request_type_method = self.request_type
            mconfig.request_target = self.request_target
            mconfig.url = self.url + mconfig.request_host + mconfig.request_target

            self.process(mconfig)
        except ApiException as e:
            print(e)
        except IOError as e:
            print(GlobalLabelParameters.FILE_NOT_FOUND + str(e.filename))
        except KeyError as e:
            print(GlobalLabelParameters.NOT_ENTERED + str(e))
        except Exception as e:
            print((e))
Ejemplo n.º 2
0
    def setUp(self):
        self.func = ApiController()

        self.url = GlobalLabelParameters.HTTP_URL_PREFIX

        self.merchant_config = MerchantConfiguration()
        self.date = self.merchant_config.get_time()
        logging.disable(logging.CRITICAL)
Ejemplo n.º 3
0
    def get_generate_header(self):
        try:
            util_obj = PropertiesUtil()
            util_obj.cybs_path = os.path.join(os.getcwd(), "samples/authentication/Resources", "cybs.json")
            details_dict1 = util_obj.properties_util()
            
            mconfig = MerchantConfiguration()
            mconfig.set_merchantconfig(details_dict1)
            
            mconfig.validate_merchant_details(details_dict1, mconfig)

            self.merchant_config = mconfig
            self.merchant_config.request_host = mconfig.request_host
            self.merchant_config.request_type_method = self.request_type
            mconfig.request_target = self.request_target
            self.date = mconfig.get_time()
            self.get_method_headers()
        except ApiException as e:
            print(e)
        except KeyError as e:
            print(GlobalLabelParameters.NOT_ENTERED + str(e))
        except IOError as e:
            print(GlobalLabelParameters.FILE_NOT_FOUND + str(e.filename))
        except Exception as e:
            print(repr(e))
Ejemplo n.º 4
0
 def set_configuration(self,config):
     global mconfig
     mconfig = MerchantConfiguration()
     mconfig.set_merchantconfig(config)
     # This implements the fall back logic for JWT parameters key alias,key password,json file path
     mconfig.validate_merchant_details(config, mconfig)
     # Setting the Host by reading the Environment(SANDBOX/PRODUCTION) from Merchant Config
     self.host = mconfig.request_host
    def set_configuration(self,config):
        global mconfig
        mconfig = MerchantConfiguration()
        mconfig.set_merchantconfig(config)

        # The below two lines are to set proxy details and if present reinitialize the REST object as a proxy manager
        if Configuration().set_merchantproxyconfig(config):
            self.rest_client = RESTClientObject() # Reinitialising REST object as a proxy manager instead of pool manager

        # This implements the fall back logic for JWT parameters key alias,key password,json file path
        mconfig.validate_merchant_details(config, mconfig)
        # Setting the Host by reading the Environment(SANDBOX/PRODUCTION) from Merchant Config
        self.host = mconfig.request_host
class TestBasicFunction(unittest.TestCase):
    def setUp(self):
        self.func = Authorization()
        self.merchant_config = MerchantConfiguration()
        self.date = self.merchant_config.get_time()
        logging.disable(logging.CRITICAL)

    def tearDown(self):
        logging.disable(logging.NOTSET)

    # This method checks the HTTP_Get token  Generation Unit Testing
    def test_token_for_get_http(self):
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.merchant_config.request_type_method = "GET"
        self.get_id = "5246387105766473203529"
        self.merchant_config.request_target = "/pts/v2/payments/" + self.get_id

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the HTTP_Get token  Generation when enable_log,Log_Maximum_Size,Log_Directory  is None/Empty
    def test_get_http_enable_log(self):
        self.merchant_config.set_merchantconfig(MockData.HTTP_DEFAULT_VALUES)

        self.merchant_config.request_type_method = "GET"
        self.get_id = "5246387105766473203529"
        self.merchant_config.request_target = "/pts/v2/payments/" + self.get_id
        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.validate_merchant_details(
            MockData.HTTP_DEFAULT_VALUES, self.merchant_config)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the HTTP_Get token  Generation when the run_environment="CyberSource.Environment.PRODUCTION"
    def test_get_jwt_production_url(self):
        self.merchant_config.set_merchantconfig(
            MockData.JWT_VALUES_FOR_PRODUCTION)

        self.merchant_config.request_type_method = "GET"
        self.get_id = "5246387105766473203529"
        self.merchant_config.request_target = "/pts/v2/payments/" + self.get_id
        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.validate_merchant_details(
            MockData.JWT_VALUES_FOR_PRODUCTION, self.merchant_config)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the HTTP_Post token  Generation Unit Testing
    def test_token_for_post_http(self):
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.merchant_config.request_type_method = "POST"
        self.merchant_config.request_target = "/pts/v2/payments"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.merchant_config.request_json_path_data = json.dumps(
            MockData.REQUEST_DATA)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the HTTP_Put token  Generation Unit Testing
    def test_token_for_put_http(self):
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.merchant_config.request_type_method = "PUT"

        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.merchant_config.request_json_path_data = json.dumps(
            MockData.TRR_DATA)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the HTTP_Delete token  Generation Unit Testing
    def test_token_for_delete_http(self):
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.merchant_config.request_type_method = "DELETE"

        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest/5246387105766473203529"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the JWT_Get token  Generation Unit Testing
    def test_token_for_get_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "GET"
        self.get_id = "5246387105766473203529"
        self.merchant_config.request_target = "/pts/v2/payments/" + self.get_id

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the JWT_Post token  Generation Unit Testing
    def test_token_for_post_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "POST"
        self.merchant_config.request_target = "/pts/v2/payments/5246387105766473203529"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.merchant_config.request_json_path_data = json.dumps(
            MockData.REQUEST_DATA)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the JWT_Put token  Generation Unit Testing
    def test_token_for_put_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "PUT"

        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.merchant_config.request_json_path_data = json.dumps(
            MockData.TRR_DATA)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))

    # This method checks the JWT_Delete token  Generation Unit Testing
    def test_token_for_delete_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "DELETE"
        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest/5246387105766473203529"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)

        self.assertIsNotNone(
            self.func.get_token(self.merchant_config, self.date, self.logger))
 def setUp(self):
     self.func = Authorization()
     self.merchant_config = MerchantConfiguration()
     self.date = self.merchant_config.get_time()
     logging.disable(logging.CRITICAL)
Ejemplo n.º 8
0
class TestBasicFunction(unittest.TestCase):
    def setUp(self):
        self.func = ApiController()

        self.url = GlobalLabelParameters.HTTP_URL_PREFIX

        self.merchant_config = MerchantConfiguration()
        self.date = self.merchant_config.get_time()
        logging.disable(logging.CRITICAL)

    def tearDown(self):
        logging.disable(logging.NOTSET)

    # This Method checks Http get UnitTesting
    def test_for_get_http(self):
        self.merchant_config.request_type_method = "GET"
        self.merchant_config.authentication_type = "http_signature"
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.get_id = "5246387105766473203529"
        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger
        self.merchant_config.request_target = "/pts/v2/payments/" + self.get_id
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_get(self.merchant_config))
        self.assertEqual(self.merchant_config.response_code, 200)

    # This Method checks Http post UnitTesting
    def test_for_post_http(self):
        self.merchant_config.request_type_method = "POST"
        self.merchant_config.authentication_type = "http_signature"
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger
        self.request_json_path = "../../cybersource_authentication_sdk_python/Resources/request.json"
        self.merchant_config.request_json_path_data = cybersource_authentication_sdk_python.data.RequestData.sample_payment_data(
        )

        self.merchant_config.request_target = "/pts/v2/payments"
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_post(self.merchant_config))
        self.assertEqual(self.merchant_config.response_code, 201)

    # This Method checks Http put UnitTesting
    def test_for_put_http(self):
        self.merchant_config.request_type_method = "PUT"
        self.merchant_config.authentication_type = "http_signature"
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger
        self.request_json_path = "../../cybersource_authentication_sdk_python/Resources/trr_report.json"
        self.merchant_config.request_json_path_data = cybersource_authentication_sdk_python.data.RequestData.json_file_data(
            self.request_json_path, self.merchant_config)

        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_put(self.merchant_config))

    # This Method checks Http Delete UnitTesting
    def test_for_delete_http(self):
        self.merchant_config.request_type_method = "DELETE"
        self.merchant_config.authentication_type = "http_signature"
        self.merchant_config.set_merchantconfig(MockData.HTTP_VALUES)
        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger

        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest/5246387105766473203529"
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_delete(self.merchant_config))

    # This Method checks Jwt get UnitTesting
    def test_for_get_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "GET"
        self.merchant_config.authentication_type = "jwt"
        self.get_id = "5246387105766473203529"
        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger

        self.merchant_config.request_target = "/pts/v2/payments/" + self.get_id
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_get(self.merchant_config))
        self.assertEqual(self.merchant_config.response_code, 200)

    # This Method checks Jwt Post UnitTesting
    def test_for_post_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "POST"
        self.merchant_config.authentication_type = "jwt"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger
        self.request_json_path = "../../cybersource_authentication_sdk_python/Resources/request.json"
        self.merchant_config.request_json_path_data = cybersource_authentication_sdk_python.data.RequestData.sample_payment_data(
        )

        self.merchant_config.request_target = "/pts/v2/payments"
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_post(self.merchant_config))
        self.assertEqual(self.merchant_config.response_code, 201)

    # This Method checks Jwt Put UnitTesting
    def test_for_put_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "PUT"
        self.merchant_config.authentication_type = "jwt"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger
        self.request_json_path = "../../cybersource_authentication_sdk_python/Resources/trr_report.json"
        self.merchant_config.request_json_path_data = cybersource_authentication_sdk_python.data.RequestData.json_file_data(
            self.request_json_path, self.merchant_config)

        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest"
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_put(self.merchant_config))

    # This Method checks Jwt Delete UnitTesting
    def test_for_delete_jwt(self):
        self.merchant_config.set_merchantconfig(MockData.JWT_VALUES)
        self.merchant_config.request_type_method = "DELETE"
        self.merchant_config.authentication_type = "jwt"

        self.logger = authenticationsdk.logger.Log.setup_logger(
            self.merchant_config)
        self.merchant_config.log = self.logger

        self.merchant_config.request_target = "/reporting/v2/reportSubscriptions/TRRReport?organizationId=testrest/5246387105766473203529"
        self.merchant_config.url = self.url + self.merchant_config.request_host + self.merchant_config.request_target

        self.assertIsNone(self.func.payment_delete(self.merchant_config))