def test_can_read_all_files(self):
     j = JsonConfig('staging.ini')
     config = j.read_config()
     self.assertEqual(config['kafka']['host'], '5.7.36.26')
     self.assertEqual(config['kafka']['port'], '200')
     self.assertEqual(config['marketplace_service']['host_port'], 'marketplace-lb:80')
     self.assertEqual(config['marketplace_service']['endpoint'], '/rest/marketplace/seller_listings')
Beispiel #2
0
 def test_can_read_all_files(self):
     j = JsonConfig('staging.ini')
     config = j.read_config()
     self.assertEqual(config['kafka']['host'], '5.7.36.26')
     self.assertEqual(config['kafka']['port'], '200')
     self.assertEqual(config['marketplace_service']['host_port'],
                      'marketplace-lb:80')
     self.assertEqual(config['marketplace_service']['endpoint'],
                      '/rest/marketplace/seller_listings')
Beispiel #3
0
 def __init__(self, **kwargs):
     self.logger = kwargs['logger'] if 'logger' in kwargs else standard_logger.get_logger('prolix_api')
     self.conf = JsonConfig.conf(logger=self.logger, package_name='prolix')
     self.conf.config_name = 'prolix_conf.json'
     self.conf_data = self.conf.get_data()
     self.default_store_expiration_secs = self.conf_data['default_store_expiration_secs']
     self.steno = steno.Steno(logger=self.logger)
 def test_can_parse_lines(self):
     j = JsonConfig()
     expected_dict = {
         'config class': {
             'this': 'something',
             'is': 'something',
             'a': 'something',
             'bunch': 'something',
             'of': 'something',
             'lines': 'something'
         },
         'cool_hey': {
             'yes': 'something'
         }
     }
     self.assertEqual(j._parse_config_lines(self.lines), expected_dict)
Beispiel #5
0
 def __init__(self, logger=None):
     self.logger = logger if logger else standard_logger.get_logger("Store")
     self.conf = JsonConfig.conf(logger=self.logger, package_name='prolix')
     self.conf.config_name = 'prolix_conf.json'
     self.conf_data = self.conf.get_data()
     self.default_expiration_seconds = self.conf_data['default_store_expiration_secs']
     self.expiration_seconds = self.default_expiration_seconds
Beispiel #6
0
    def test_002_load_multiple_config_files(self):
        self.logger.debug("TestConfig: test_002_load_multiple_config_files")
        # Always use an explicit new conf object
        conf = JsonConfig.new_conf(logger=self.logger, package_name='tests')

        test_conf_file_name = "conf.json"
        test_data = {"key1": "val2.1", "key5": "val2.5"}
        test_config_file_contents = json.dumps(test_data)
        test_conf_file_path = self.write_file_to_tmp_dir(
            test_conf_file_name, test_config_file_contents)

        # Set up conf object - search paths are ordered
        conf.use_default_sym_names = False
        conf.add_sym_name('package')
        conf.add_sym_name('unknown_sym_name')
        conf.add_search_path(test_conf_file_path)
        conf.add_search_path(
            paths.get_data_path(file_name='conf.json', package_name='tests'))

        conf.expand_search_paths()

        full_search_paths = conf.full_search_paths
        self.assertEqual(len(full_search_paths), 4)
        # Only search path that can be tested here is the test_conf_file_path
        self.assertEqual(test_conf_file_path, full_search_paths[2])

        loaded_data = conf.get_data()
        # Clean up
        os.remove(test_conf_file_path)
        self.assertEqual(loaded_data["key1"], "val3.1")
        self.assertEqual(loaded_data["key2"], "val3.2")
        self.assertEqual(loaded_data["key4"], "val1.4")
        self.assertEqual(loaded_data["key5"], "val2.5")
        self.assertEqual(loaded_data["key6"], "val3.6")
Beispiel #7
0
    def test_001_load_single_config_file(self):
        self.logger.debug("TestConfig: test_001_load_single_config_file")
        # Always use an explicit new conf object
        conf = JsonConfig.new_conf(logger=self.logger, package_name='tests')

        test_conf_file_name = "config.json"
        test_data = {"key1": "value1"}
        test_config_file_contents = json.dumps(test_data)
        test_conf_file_path = self.write_file_to_tmp_dir(
            test_conf_file_name, test_config_file_contents)

        # Set up conf object
        conf.use_default_sym_names = False
        conf.set_conf_name(test_conf_file_name)
        conf.add_search_path(test_conf_file_path)
        conf.expand_search_paths()

        full_search_paths = conf.full_search_paths
        # Only search path should be the one we added
        self.assertEqual(test_conf_file_path, full_search_paths[0])

        loaded_data = conf.get_data()
        # Clean up
        os.remove(test_conf_file_path)
        self.assertEqual(loaded_data, test_data)
Beispiel #8
0
    def test_003_load_config_file_from_env(self):
        self.logger.debug("TestConfig: test_003_load_config_file_from_env")
        # Always use an explicit new conf object
        conf = JsonConfig.new_conf(logger=self.logger, package_name='tests')

        test_conf_file_name = "conf.json"
        test_data = {"key1": "val2.1", "key5": "val2.5"}
        test_config_file_contents = json.dumps(test_data)
        test_conf_file_path = self.write_file_to_tmp_dir(
            test_conf_file_name, test_config_file_contents)

        # Set up conf object - search paths are ordered
        conf.use_default_sym_names = False
        os.environ['JSON_CONF_DIR'] = path.dirname(test_conf_file_path)
        os.environ['JSON_CONF'] = test_conf_file_name
        conf.add_sym_name('env')
        conf.expand_search_paths()

        full_search_paths = conf.full_search_paths
        self.assertEqual(len(full_search_paths), 1)
        # Only search path that can be tested here is the test_conf_file_path
        self.assertEqual(test_conf_file_path, full_search_paths[0])

        loaded_data = conf.get_data()
        # Clean up
        del os.environ['JSON_CONF_DIR']
        del os.environ['JSON_CONF']
        os.remove(test_conf_file_path)
        self.assertEqual(loaded_data["key1"], "val2.1")
        self.assertEqual(loaded_data["key5"], "val2.5")
Beispiel #9
0
 def test_can_parse_lines(self):
     j = JsonConfig()
     expected_dict = {
         'config class': {
             'this': 'something',
             'is': 'something',
             'a': 'something',
             'bunch': 'something',
             'of': 'something',
             'lines': 'something'
         },
         'cool_hey': {
             'yes': 'something'
         }
     }
     self.assertEqual(j._parse_config_lines(self.lines), expected_dict)
Beispiel #10
0
 def __init__(self):
     if not BaseTestClass.TEST_LOGGER:
         BaseTestClass.TEST_LOGGER = standard_logger.get_logger('tests', level_str='DEBUG')
     self.logger = BaseTestClass.TEST_LOGGER
     self.conf = JsonConfig.conf(logger=self.logger, package_name='prolix')
     self.conf.config_name = 'prolix_conf.json'
     self.conf_data = self.conf.get_data()
Beispiel #11
0
 def __init__(self, logger=None):
     self.logger = logger if logger else standard_logger.get_logger("Store")
     self.conf = JsonConfig.conf(logger=self.logger, package_name='prolix')
     self.conf.config_name = 'prolix_conf.json'
     self.conf_data = self.conf.get_data()
     self.default_expiration_seconds = self.conf_data[
         'default_store_expiration_secs']
     self.redis_store = store.RedisStore(logger=self.logger)
     # Initialize RandomAsciiStringByFrequency because of file loads needed
     self.rasbf = rand.RandomAsciiStringByFrequency(
         logger=self.logger).dispatch()
"""
A simple test of serial communication with a BT510.
"""

import time
import serial
import serial.threaded
import logging
import log_wrapper
from json_serial_reader import JsonSerialReader
from json_config import JsonConfig

if __name__ == "__main__":
    log_wrapper.setup(__file__)
    isBle = False
    jc = JsonConfig(isBle)
    ser = serial.serial_for_url(
        url=jc.get_port(), baudrate=jc.get_baudrate(), timeout=1.0)
    with serial.threaded.ReaderThread(ser, JsonSerialReader) as reader_thread:
        rt = reader_thread
        rt.set_protocol(reader_thread)
        rt.Unlock()
        rt.GetAttribute("sensorName")
        rt.GetAttribute("location")
        rt.GetAttribute("firmwareVersion")
        rt.GetAttribute("hwVersion")
        rt.GetAttribute("bluetoothAddress")
        rt.LedTest()
        rt.EpochTest(int(time.time()))
        rt.LogResults()
When using the AT command set addresses are prefixed with 01.
"""

import time
import serial
import serial.threaded
import logging
import log_wrapper
from dongle import BL65x
from json_config import JsonConfig
from json_commander import jtester

if __name__ == "__main__":
    log_wrapper.setup(__file__, console_level=logging.DEBUG)
    isBle = True
    jc = JsonConfig(isBle)
    ser = serial.serial_for_url(url=jc.get_port(),
                                baudrate=jc.get_baudrate(),
                                timeout=1,
                                rtscts=True)
    with serial.threaded.ReaderThread(ser, BL65x) as bt_module:
        jt = jtester()
        jt.set_protocol(bt_module)
        bt_module.secondary_initialization()
        input("Press sensor button (advertise) and then press enter...")
        bt_module.connect(bt_module.current_addr, bt_module.connection_timeout)
        if bt_module.vspConnection:
            jt.Unlock()
            jt.GetAttribute("sensorName")
            jt.GetAttribute("location")
            jt.GetAttribute("firmwareVersion")
        '%d %b %y %H:%M:%S', time.localtime(time.time()))
    s += f"{ap.name:>23}, 0x{ap.bd_addr}, {local_time:>18}, "
    s += f"{build_version_string(ap.rsp.firmware_major_version, ap.rsp.firmware_minor_version, ap.rsp.firmware_build_version):>11}, "
    s += f"{build_version_string(ap.rsp.bootloader_major_version, ap.rsp.bootloader_minor_version, ap.rsp.bootloader_build_version):>11}, "
    s += f"{ap.unpack_hardware_version():>4}, "  # 12.4
    s += f"{ap.adv.reset_count:>12}, "
    s += f"{ap.rsp.config_version:>14}, "
    s += f"{ap.adv.network_id:>10}"
    s += '\n'
    return s


if __name__ == "__main__":
    log_wrapper.setup(__file__, console_level=logging.INFO)
    isBle = True
    jc = JsonConfig(isBle, "config.json")
    ser = serial.Serial(jc.get_port(), baudrate=jc.get_baudrate(),
                        timeout=1,  rtscts=True)
    with serial.threaded.ReaderThread(ser, BL65x) as bt_module:
        jt = jtester()
        jt.set_protocol(bt_module)
        bt_module.secondary_initialization()

        name_to_look_for = jc.get("system_name_to_look_for")
        ofile = "logs/" + name_to_look_for + ".system_report.log"
        append_report(ofile, COLUMN_LIST)
        bt_module.scan(nameMatch=name_to_look_for)
        device_list = list()
        stop_time = time.time() + jc.get("system_report_scan_duration_seconds")
        while time.time() < stop_time:
            ad = bt_module.get_scan(timeout=None)
import time
import serial
import serial.threaded
import logging
import log_wrapper
from json_config import JsonConfig
from sensor_config import sensor_config
from dongle import BL65x
from json_commander import jtester
from adv_parser import AdvParser

if __name__ == "__main__":
    log_wrapper.setup(__file__, console_level=logging.DEBUG)
    isBle = True
    jc = JsonConfig(isBle, "config.json")
    ser = serial.Serial(jc.get_port(),
                        baudrate=jc.get_baudrate(),
                        timeout=1,
                        rtscts=True)
    with serial.threaded.ReaderThread(ser, BL65x) as bt_module:
        jt = jtester()
        jt.set_protocol(bt_module)
        bt_module.secondary_initialization()
        name_to_look_for = "BT510"
        bt_module.scan(nameMatch=name_to_look_for)
        configured_devices = dict()
        while True:
            ad = bt_module.get_scan(timeout=None)
            ap = None
            try:
import serial
import serial.threaded
from dongle import BL65x
from json_commander import jtester
from json_config import JsonConfig
from sensor_event import SensorEvent
from adv_parser import AdvParser
import metrics
import boto3

NAMESPACE = "Client/Application"

if __name__ == "__main__":
    log_wrapper.setup(__file__, console_level=logging.INFO, file_mode='a')
    isBle = True
    jc = JsonConfig(isBle)
    ser = serial.Serial(jc.get_port(), baudrate=jc.get_baudrate(),
                        timeout=1,  rtscts=True)
    with serial.threaded.ReaderThread(ser, BL65x) as bt_module:
        cloudwatch = boto3.client('cloudwatch')
        jt = jtester()
        jt.set_protocol(bt_module)
        bt_module.secondary_initialization()
        name_to_look_for = jc.get("system_name_to_look_for")
        bt_module.scan(nameMatch=name_to_look_for)
        event_dict = dict()
        while True:
            ad = bt_module.get_scan(timeout=None)
            ap = None
            try:
                junk, address, rssi, ad_rsp = ad.split(' ')
 def test_can_read_file(self):
     j = JsonConfig()
     self.assertEqual(j._fetch_config_lines_from_file("lines.ini"), self.lines)
""" Connect to a BLE sensor using the advertised name """

import serial
import serial.threaded
import logging
import log_wrapper
from json_config import JsonConfig
from dongle import BL65x
from json_commander import jtester
from adv_parser import AdvParser

if __name__ == "__main__":
    log_wrapper.setup(__file__, console_level=logging.DEBUG)
    isBle = True
    jc = JsonConfig(isBle, "config.json")
    ser = serial.Serial(jc.get_port(),
                        baudrate=jc.get_baudrate(),
                        timeout=1,
                        rtscts=True)
    with serial.threaded.ReaderThread(ser, BL65x) as bt_module:
        jt = jtester()
        jt.set_protocol(bt_module)
        bt_module.secondary_initialization()
        name_to_look_for = jc.get("name_to_look_for")
        number_of_devices_to_look_for = jc.get("number_of_devices_to_look_for")
        bt_module.scan(nameMatch=name_to_look_for)
        configured_devices = dict()
        while number_of_devices_to_look_for > 0:
            ad = bt_module.get_scan(timeout=None)
            ap = None
            try:
Beispiel #19
0
 def test_can_read_file(self):
     j = JsonConfig()
     self.assertEqual(j._fetch_config_lines_from_file("lines.ini"),
                      self.lines)