Example #1
0
    def __init__(self,
                 config_dir="config",
                 config_file="uem.json",
                 debug=False,
                 bulk_query_trigger=50):

        # Sort out logging
        log_level = logging.ERROR
        if debug:
            log_level = logging.INFO

        logging.basicConfig(format='%(levelname)s\t%(funcName)s\t%(message)s',
                            level=log_level)

        # Create logging functions
        self.debug = logging.debug
        self.info = logging.info
        self.warning = logging.warning
        self.error = logging.error
        self.critical = logging.critical

        # Show sensitve info such as auth headers
        self.show_sensitive = False

        # Set max size line to log
        self.max_log = 9000

        # Set a limit of when to swtich to bulk querys
        self.bulk_query_trigger = bulk_query_trigger

        # Get config
        self.config_dir = config_dir
        self.config = Auth(config_dir).read_config(config_file)

        if not self.config:
            self.critical("Unable to get config, run configure.py")
            self.configure()
            self.critical("Run again to use config")
            sys.exit(1)

        self.info("Imported config - %s" % self.info_sensitive(self.config))

        # Create v1 API object
        headers_v1 = self.create_headers(version=1)

        self.rest_v1 = REST(url=self.config['url'],
                            headers=headers_v1,
                            proxy=self.import_proxy(),
                            debug=debug)

        # Create v2 API object
        headers_v2 = self.create_headers(version=2)

        self.rest_v2 = REST(url=self.config['url'],
                            headers=headers_v2,
                            proxy=self.import_proxy(),
                            debug=debug)
Example #2
0
def test_system_info():
    """Test system_info API"""
    info = UEM.system_info()
    assert isinstance(info, dict) is True

    # Get the API version
    version = REST(url=CONFIG['url']).get("/api/system/help/localjson")
    version = json.loads(version.text)

    # Extract the version code
    version = re.search(r'(\d{1,2}.\d{1,2}.\d{1,2}.\d{1,2})',
                        version["apis"][0]['products'][0]).group(1)

    assert info['ProductVersion'] == version
Example #3
0
"""A sample file that will print the API response code and your IP"""
import json
from reqrest import REST

# Set REST URL
RESTAPI = REST('api.ipify.org')

# Create the querystring so we get json data back
QUERYSTRING = {}
QUERYSTRING['format'] = "json"

# Do the API call
RESPONSE = RESTAPI.get("/", QUERYSTRING)

# Get the response body and convert it to a dict
IP = json.loads(RESPONSE.text)

# Print what we got
print("HTTP status code: %i" % RESPONSE.status_code)
print("IP Address: %s " % IP['ip'])
Example #4
0
 def __init__(self, url, auth, debug=False):
     self.rest = REST(url,
                      headers=self.create_headers(auth),
                      protocol='http',
                      debug=debug)
     self.debug = debug
Example #5
0
def test_false_http():
    """Checks good responses are False"""
    demo_api = REST(url='postman-echo.com')
    for code in (400, 401, 403, 404, 406, 422, 500):
        assert UEM.check_http_response(demo_api.get(
            "/status/%i" % code)) is False
Example #6
0
def test_true_http():
    """Checks good responses are True"""
    demo_api = REST(url='postman-echo.com')
    for code in (200, 201, 204):
        assert UEM.check_http_response(demo_api.get(
            "/status/%i" % code)) is True