Пример #1
0
 def assertDefaults(self, communicator_config):
     """Tests commonly used settings for testing url, authorization type, timeouts and max_connections"""
     self.assertEqual("https://example.com",
                      communicator_config.api_endpoint.geturl())
     self.assertEqual(AuthorizationType.V1HMAC,
                      communicator_config.authorization_type)
     self.assertEqual(CommunicatorConfiguration().DEFAULT_CONNECT_TIMEOUT,
                      communicator_config.connect_timeout)
     self.assertEqual(CommunicatorConfiguration().DEFAULT_SOCKET_TIMEOUT,
                      communicator_config.socket_timeout)
     self.assertEqual(CommunicatorConfiguration().DEFAULT_MAX_CONNECTIONS,
                      communicator_config.max_connections)
Пример #2
0
 def test_accept_lowercased_authorization_type_in_config(self):
     """Tests if the default authenticator accepts authorization types with different casing in config."""
     self.config.set("OnlinePaymentsSDK",
                     "onlinePayments.api.authorizationType", "v1hmac")
     communicator_config = CommunicatorConfiguration(self.config)
     self.assertEqual(AuthorizationType.V1HMAC,
                      communicator_config.authorization_type)
Пример #3
0
    def test_construct_from_properties_with_host_and_scheme(self):
        """Tests that constructing a communicator configuration from a host and port correctly processes this info"""
        self.config.set("OnlinePaymentsSDK",
                        "onlinePayments.api.endpoint.scheme", "http")

        communicator_config = CommunicatorConfiguration(self.config)

        self.assertEqual("http://example.com",
                         communicator_config.api_endpoint.geturl())
Пример #4
0
    def test_construct_from_properties_without_proxy(self):
        """Test if a CommunicatorConfiguration can be constructed correctly from a list of properties"""

        communicator_config = CommunicatorConfiguration(self.config)

        self.assertDefaults(communicator_config)
        self.assertIsNone(communicator_config.api_key_id)
        self.assertIsNone(communicator_config.secret_api_key)
        self.assertIsNone(communicator_config.proxy_configuration)
        self.assertIsNone(communicator_config.integrator)
        self.assertIsNone(communicator_config.shopping_cart_extension)
Пример #5
0
def create_communicator_configuration(properties_url=PROPERTIES_URL,
                                      max_connections=False):
    """Convenience method to create a communicator configuration that connects to a host stored in system variables"""
    try:
        parser = ConfigParser()
        parser.read(properties_url)
        with open(properties_url) as f:
            parser.read_file(f)
        configuration = CommunicatorConfiguration(
            parser,
            api_key_id=API_KEY_ID,
            secret_api_key=SECRET_API_KEY,
            max_connections=max_connections)
    except IOError as e:
        raise RuntimeError("Unable to read configuration", e)
    host = os.getenv("onlinePayments.api.endpoint.host")
    if host is not None:
        scheme = os.getenv("onlinePayments.api.endpoint.scheme", "https")
        port = int(os.getenv("onlinePayments.api.endpoint.port", 443))
        configuration.api_endpoint = "{2}://{0}:{1}".format(host, port, scheme)
    return configuration
Пример #6
0
    def test_construct_from_properties_with_proxy_without_authentication(self):
        """Tests if a CommunicatorConfiguration can be constructed correctly from settings including a proxy"""
        self.config.set('OnlinePaymentsSDK', "onlinePayments.api.proxy.uri",
                        "http://proxy.example.org:3128")

        communicator_config = CommunicatorConfiguration(self.config)

        self.assertDefaults(communicator_config)
        self.assertIsNone(communicator_config.api_key_id)
        self.assertIsNone(communicator_config.secret_api_key)
        proxy_config = communicator_config.proxy_configuration
        self.assertIsNotNone(proxy_config)
        self.assertEqual("http", proxy_config.scheme)
        self.assertEqual("proxy.example.org", proxy_config.host)
        self.assertEqual(3128, proxy_config.port)
        self.assertIsNone(proxy_config.username)
        self.assertIsNone(proxy_config.password)
Пример #7
0
 def create_configuration(configuration_file_name, api_key_id,
                          secret_api_key) -> CommunicatorConfiguration:
     """
     Creates a CommunicatorConfiguration based on the configuration
     values in configuration_file_name, api_key_id and secret_api_key.
     """
     parser = ConfigParser()
     try:
         parser.read(configuration_file_name)
         with open(configuration_file_name) as f:
             parser.read_file(f)
         return CommunicatorConfiguration(properties=parser,
                                          api_key_id=api_key_id,
                                          secret_api_key=secret_api_key)
     except IOError as e:
         raise RuntimeError(
             "Unable to read configuration located at {}".format(
                 e.filename), e)
Пример #8
0
    def test_construct_from_properties_with_defaults_overridden(self):
        """Tests if a CommunicatorConfiguration can be constructed correctly from settings that contain a different number for defaults"""
        self.config.set('OnlinePaymentsSDK',
                        'onlinePayments.api.connectTimeout', '100')
        self.config.set('OnlinePaymentsSDK',
                        'onlinePayments.api.socketTimeout', '200')
        self.config.set("OnlinePaymentsSDK",
                        "onlinePayments.api.maxConnections", "300")

        communicator_config = CommunicatorConfiguration(self.config)
        self.assertEqual("https://example.com",
                         communicator_config.api_endpoint.geturl())
        self.assertEqual(AuthorizationType.V1HMAC,
                         communicator_config.authorization_type)
        self.assertEqual(100, communicator_config.connect_timeout)
        self.assertEqual(200, communicator_config.socket_timeout)
        self.assertEqual(300, communicator_config.max_connections)
        self.assertIsNone(communicator_config.api_key_id)
        self.assertIsNone(communicator_config.secret_api_key)
        self.assertIsNone(communicator_config.proxy_configuration)
Пример #9
0
    def test_construct_from_properties_with_metadata(self):
        """Tests that constructing a communicator configuration using integrator and shopping cart data constructs properly"""
        self.config.set("OnlinePaymentsSDK", "onlinePayments.api.integrator",
                        "OnlinePayments.Integrator")
        self.config.set("OnlinePaymentsSDK",
                        "onlinePayments.api.shoppingCartExtension.creator",
                        "OnlinePayments.Creator")
        self.config.set("OnlinePaymentsSDK",
                        "onlinePayments.api.shoppingCartExtension.name",
                        "OnlinePayments.ShoppingCarts")
        self.config.set("OnlinePaymentsSDK",
                        "onlinePayments.api.shoppingCartExtension.version",
                        "1.0")
        self.config.set(
            "OnlinePaymentsSDK",
            "onlinePayments.api.shoppingCartExtension.extensionId",
            "ExtensionId")

        communicator_config = CommunicatorConfiguration(self.config)

        self.assertDefaults(communicator_config)
        self.assertIsNone(communicator_config.api_key_id)
        self.assertIsNone(communicator_config.secret_api_key)
        self.assertIsNone(communicator_config.proxy_configuration)
        self.assertEqual("OnlinePayments.Integrator",
                         communicator_config.integrator)
        self.assertIsNotNone(communicator_config.shopping_cart_extension)
        self.assertEqual("OnlinePayments.Creator",
                         communicator_config.shopping_cart_extension.creator)
        self.assertEqual("OnlinePayments.ShoppingCarts",
                         communicator_config.shopping_cart_extension.name)
        self.assertEqual("1.0",
                         communicator_config.shopping_cart_extension.version)
        self.assertEqual(
            "ExtensionId",
            communicator_config.shopping_cart_extension.extension_id)
Пример #10
0
 def test_accept_uppercased_authorization_type_in_param(self):
     """Tests if the default authenticator accepts authorization types with different casing as parameter."""
     communicator_config = CommunicatorConfiguration(
         self.config, authorization_type="V1HMAC")
     self.assertEqual(AuthorizationType.V1HMAC,
                      communicator_config.authorization_type)