def test_get_server_metadata_headers_no_additional_headers(self):
        """Tests that the MetaDataProvider functions correctly without any additional headers as arguments"""
        meta_data_provider = MetaDataProvider("Ingenico")

        request_headers = meta_data_provider.meta_data_headers
        self.assertEqual(1, len(request_headers))
        self.assertServerMetaInfo(meta_data_provider, "Ingenico", None,
                                  request_headers[0])
 def test_constructor_with_prohibited_headers(self):
     """Tests that the MetaDataProvider constructor does not accept any headers marked as prohibited"""
     for name in MetaDataProvider.prohibited_headers:
         additional_headers = [
             RequestHeader("Header1", "Value1"),
             RequestHeader(name, "should be slashed and burnt"),
             RequestHeader("Header3", "Value3")
         ]
         with self.assertRaises(Exception) as error:
             MetaDataProvider("Ingenico", None, additional_headers)
         self.assertIn(name, str(error.exception))
    def test_server_meta_data_headers_full_no_shopping_cart_extension_id(self):
        """Tests that the MetaDataProvider can construct meta_data_headers when supplied with a full shopping cart"""
        shopping_cart_extension = ShoppingCartExtension(
            "Ingenico.creator", "Extension", "1.0")
        meta_data_provider = MetaDataProvider("Ingenico",
                                              shopping_cart_extension)

        request_headers = meta_data_provider.meta_data_headers
        self.assertEqual(1, len(request_headers))
        self.assertServerMetaInfo(meta_data_provider, "Ingenico",
                                  shopping_cart_extension, request_headers[0])
def create_client(
        httphost,
        connect_timeout=0.500,
        socket_timeout=0.500,
        max_connections=EndpointConfiguration.DEFAULT_MAX_CONNECTIONS):
    connection = DefaultConnection(connect_timeout, socket_timeout,
                                   max_connections)
    authenticator = DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey",
                                         "secret")
    meta_data_provider = MetaDataProvider("Ingenico")
    session = Session(httphost, connection, authenticator, meta_data_provider)
    communicator = Factory.create_communicator_from_session(session)
    return Factory.create_client_from_communicator(communicator)
Esempio n. 5
0
def create_session():
    host = os.getenv("connect.api.endpoint.host")
    scheme = os.getenv("connect.api.endpoint.scheme", "https")
    port = int(os.getenv("connect.api.endpoint.port", -1))
    if not host:
        raise RuntimeError(
            "unable to read environment variables to find api_endpoint")
    api_endpoint = "{2}://{0}:{1}".format(host, port, scheme)
    authenticator = DefaultAuthenticator(
        api_id_key=API_KEY_ID,
        secret_api_key=SECRET_API_KEY,
        authorization_type=AuthorizationType.V1HMAC)
    return Session(api_endpoint=api_endpoint,
                   authenticator=authenticator,
                   connection=DefaultConnection(3, 3),
                   meta_data_provider=MetaDataProvider("Ingenico"))
    def test_get_server_metadata_headers_additional_headers(self):
        """Tests that the MetaDataProvider can handle multiple additional headers"""
        additional_headers = [
            RequestHeader("Header1", "&=$%"),
            RequestHeader("Header2", "blah blah"),
            RequestHeader("Header3", "foo")
        ]
        meta_data_provider = MetaDataProvider("Ingenico", None,
                                              additional_headers)
        request_headers = meta_data_provider.meta_data_headers

        self.assertEqual(4, len(request_headers))

        for index in range(1, 4):
            self.assertEqual(additional_headers[index - 1],
                             request_headers[index])
    def test_multiline_header(self):
        """Test if the products service can function with a multiline header"""
        multi_line_header = " some value  \r\n \n with        a liberal amount     of \r\n  spaces    "
        configuration = init_utils.create_communicator_configuration()
        meta_data_provider = MetaDataProvider(
            integrator="Ingenico",
            additional_request_headers=(RequestHeader("X-GCS-MultiLineHeader",
                                                      multi_line_header), ))
        params = DirectoryParams()
        params.country_code = "NL"
        params.currency_code = "EUR"
        session = Factory.create_session_from_configuration(
            configuration, meta_data_provider=meta_data_provider)

        with Factory.create_client_from_session(session) as client:
            response = client.merchant(MERCHANT_ID).products().directory(
                809, params)

        self.assertGreater(len(response.entries), 0)
Esempio n. 8
0
 def setUp(self):
     self.mock_connection = MagicMock(spec=Connection(), autospec=True)
     self.session = Session(
         "http://localhost", self.mock_connection,
         DefaultAuthenticator(AuthorizationType.V1HMAC, "admin", "admin"),
         MetaDataProvider("Ingenico"))