Example #1
0
    def test_header_override(self):
        api_client = ApiClient(self.local_config,
                               header_name="x-aspose-client",
                               header_value="some custom sdk")
        api_client.rest_client = self.rest_client_mock

        BarcodeApi(api_client).get_barcode_generate(EncodeBarcodeType.CODE128,
                                                    "Test")

        self.assertEqual(1, self.rest_client_mock.GET.call_count)
        headers = self.rest_client_mock.GET.call_args[1]["headers"]
        self.assertEqual("some custom sdk", headers["x-aspose-client"])
Example #2
0
    def test_default_headers(self):
        api_client = ApiClient(self.local_config)
        api_client.rest_client = self.rest_client_mock

        BarcodeApi(api_client).get_barcode_generate(EncodeBarcodeType.CODE128,
                                                    "Test")

        self.assertEqual(1, self.rest_client_mock.GET.call_count)
        headers = self.rest_client_mock.GET.call_args[1]["headers"]
        self.assertEqual("Aspose-Barcode-SDK/21.6.0/python",
                         headers["User-Agent"])
        self.assertEqual("python sdk", headers["x-aspose-client"])
        self.assertEqual("21.6.0", headers["x-aspose-client-version"])
Example #3
0
    def setUpClass(cls):
        cls.test_filename = os.path.join("testdata", "pdf417Sample.png")

        cls.api_client = ApiClient(configuration=TEST_CONFIGURATION)

        cls.api = BarcodeApi(api_client=cls.api_client)
        cls.temp_folder_path = "BarcodeTests/%s" % uuid.uuid4()
Example #4
0
    def test_unauthorized_raises(self):
        api = BarcodeApi(ApiClient(Configuration(access_token="incorrect token", host=TEST_CONFIGURATION.host)))

        with self.assertRaises(Exception) as context:
            api.get_barcode_generate(EncodeBarcodeType.QR, "Testing")

        self.assertEqual(400, context.exception.status)
Example #5
0
from __future__ import division, print_function

import os
from pprint import pprint

from aspose_barcode_cloud import BarcodeApi, ApiClient, Configuration, EncodeBarcodeType, PresetType

config = Configuration(
    client_id="Client Id from https://dashboard.aspose.cloud/applications",
    client_secret=
    "Client Secret from https://dashboard.aspose.cloud/applications",
    access_token=os.environ.get("TEST_CONFIGURATION_ACCESS_TOKEN"
                                )  # Only for testing in CI, remove this line
)

api = BarcodeApi(ApiClient(config))

# Generate barcode
response = api.get_barcode_generate(EncodeBarcodeType.QR, "Example")
with open('example.png', 'wb') as f:
    f.write(response.data)
print("Barcode saved to file 'example.png'")

# Recognize barcode
response = api.post_barcode_recognize_from_url_or_content(
    image='example.png', preset=PresetType.HIGHPERFORMANCE)
pprint(response)
Example #6
0
 def test_works_with_access_token(self):
     api = BarcodeApi(
         ApiClient(Configuration(access_token=TEST_CONFIGURATION.access_token, host=TEST_CONFIGURATION.host))
     )
     response = api.get_barcode_generate(EncodeBarcodeType.QR, "Testing")
     self.assertEqual(200, response.status)
Example #7
0
 def setUpClass(cls):
     cls.api_client = ApiClient(TEST_CONFIGURATION)
     cls.api = BarcodeApi(cls.api_client)