Exemplo n.º 1
0
    def test_to_uri_with_request_parameters(self):
        """Tests if the communicator can correctly construct an url using a known base url, a relative url and a list of request parameters"""
        requestParams = [
            RequestParam("amount", "123"),
            RequestParam("source", "USD"),
            RequestParam("target", "EUR"),
            RequestParam("dummy", "é&%=")
        ]
        communicator = Communicator(
            api_endpoint=urlparse("https://example.com"),
            authenticator=DefaultAuthenticator("a_key", "a_secret"),
            meta_data_provider=MetaDataProvider("OnlinePayments"))

        uri1 = communicator._to_absolute_uri("v2/1/testconnection",
                                             requestParams)
        uri2 = communicator._to_absolute_uri("/v2/1/testconnection",
                                             requestParams)

        self.assertEqual(
            "https://example.com/v2/1/testconnection"
            "?amount=123&source=USD&target=EUR&dummy=%C3%A9%26%25%3D",
            uri1.geturl())
        self.assertEqual(
            "https://example.com/v2/1/testconnection"
            "?amount=123&source=USD&target=EUR&dummy=%C3%A9%26%25%3D",
            uri2.geturl())
Exemplo n.º 2
0
    def test_to_uri_without_request_parameters(self):
        """Tests if the communicator can correctly construct an url using a known base url and a relative url"""
        communicator = Communicator(
            api_endpoint=urlparse("https://example.com"),
            authenticator=DefaultAuthenticator("a_key", "a_secret"),
            meta_data_provider=MetaDataProvider("OnlinePayments"))

        uri1 = communicator._to_absolute_uri("v2/merchant/1/testconnection",
                                             [])
        uri2 = communicator._to_absolute_uri("/v2/merchant/1/testconnection",
                                             [])

        self.assertEqual("https://example.com/v2/merchant/1/testconnection",
                         uri1.geturl())
        self.assertEqual("https://example.com/v2/merchant/1/testconnection",
                         uri2.geturl())
Exemplo n.º 3
0
 def setUp(self):
     self.mock_connection = MagicMock(spec=Connection(), autospec=True)
     self.communicator = Communicator(
         api_endpoint="http://localhost",
         authenticator=DefaultAuthenticator("admin", "admin"),
         meta_data_provider=MetaDataProvider("OnlinePayments"),
         connection=self.mock_connection)
Exemplo n.º 4
0
def create_client(
        http_host,
        connect_timeout=0.500,
        socket_timeout=0.500,
        max_connections=EndpointConfiguration.DEFAULT_MAX_CONNECTIONS):
    connection = DefaultConnection(connect_timeout, socket_timeout,
                                   max_connections)
    authenticator = DefaultAuthenticator("apiKey", "secret")
    meta_data_provider = MetaDataProvider("the Online Payments")
    communicator = Communicator(api_endpoint=http_host,
                                authenticator=authenticator,
                                meta_data_provider=meta_data_provider,
                                connection=connection)
    return Factory.create_client_from_communicator(communicator)
Exemplo n.º 5
0
 def create_communicator_from_configuration(
     communicator_configuration,
     meta_data_provider=None,
     connection=None,
     authenticator=None,
     marshaller=DefaultMarshaller.INSTANCE()
 ) -> Communicator:
     """
     Creates a Communicator based on the configuration stored in the CommunicatorConfiguration argument
     """
     # If an authenticator is not given, api_key_id and secret_api_key are
     # used to create a DefaultAuthenticator used to create the communicator.
     if connection is None:
         connection = DefaultConnection(
             connect_timeout=communicator_configuration.connect_timeout,
             socket_timeout=communicator_configuration.socket_timeout,
             max_connections=communicator_configuration.max_connections,
             proxy_configuration=communicator_configuration.
             proxy_configuration)
     if authenticator is None:
         authenticator = DefaultAuthenticator(
             api_key_id=communicator_configuration.api_key_id,
             secret_api_key=communicator_configuration.secret_api_key,
             authorization_type=communicator_configuration.
             authorization_type)
     if meta_data_provider is None:
         meta_data_provider = MetaDataProvider(
             integrator=communicator_configuration.integrator,
             shopping_cart_extension=communicator_configuration.
             shopping_cart_extension)
     return Communicator(
         api_endpoint=communicator_configuration.api_endpoint,
         authenticator=authenticator,
         connection=connection,
         meta_data_provider=meta_data_provider,
         marshaller=marshaller)