def prepare_test_suite(): scale_test_suite = [ unittest.TestLoader().loadTestsFromTestCase(PySenseUserTests), unittest.TestLoader().loadTestsFromTestCase(PySenseRuleTests), unittest.TestLoader().loadTestsFromTestCase(PySenseFolderTests), unittest.TestLoader().loadTestsFromTestCase(PySensePluginTests), unittest.TestLoader().loadTestsFromTestCase(PySenseWidgetTests), unittest.TestLoader().loadTestsFromTestCase(PySenseGroupTests), unittest.TestLoader().loadTestsFromTestCase(PySenseElasticubeTests), unittest.TestLoader().loadTestsFromTestCase(PySenseDashboardTests), unittest.TestLoader().loadTestsFromTestCase(PySenseTests) ] linux_tests = [ unittest.TestLoader().loadTestsFromTestCase(PySenseDataSetTests), unittest.TestLoader().loadTestsFromTestCase(PySenseTableTests), unittest.TestLoader().loadTestsFromTestCase(PySenseDataModelTests), unittest.TestLoader().loadTestsFromTestCase(PySenseLinuxTests) ] windows_tests = [ unittest.TestLoader().loadTestsFromTestCase(PySenseWindowsTests) ] if os.path.exists('resources//LinuxConfig.yaml'): does_cube_exist(PySense.authenticate_by_file('resources//LinuxConfig.yaml'), 'PySense', 'LinuxConfig') scale_test_suite = scale_test_suite + linux_tests if os.path.exists('resources//WindowsConfig.yaml'): does_cube_exist(PySense.authenticate_by_file('resources//WindowsConfig.yaml'), 'PySense', 'WindowsConfig') scale_test_suite = scale_test_suite + windows_tests return unittest.TestSuite(scale_test_suite)
def on_locust_init(environment, **_kwargs): global token_array py_client = PySense.authenticate_by_file(admin_config) all_viewers = py_client.get_users(role=SisenseRole.Role.VIEWER) test_users = [] for user in all_viewers: if user_name_key in user.get_email(): test_users.append(user) token_array = LoadTestUtils.generate_tokens(host, test_users, password)
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file( 'resources//TestConfig.yaml') cls.elasticube = cls.py_client.get_elasticube_by_name('PySense') cls.user = cls.py_client.get_user_by_email('*****@*****.**') cls.rule = cls.elasticube.add_data_security_rule('Dim_Dates', 'Business Value', 'numeric', members=['1'], shares=[cls.user])
def test_task(self): py_client = PySense.authenticate_custom_connector( version, LoadTestConnector.LoadTestConnector(host, get_token(), self.client)) for dashboard in dashboards: for query in dashboard: py_client.connector.rest_call( 'post', 'api/datasources/Sample%20ECommerce/jaql', json_payload=query) time.sleep(dashboard_wait_time)
def authenticate_by_token(host, token, version, debug=False, verify=True, param_dict=None): """Do not call directly. Call from PySense""" host = PySenseUtils.format_host(host) token_json = {'authorization': "Bearer " + token} return PySense.PySense(host, token_json, version, debug=debug, verify=verify, param_dict=param_dict)
def authenticate_by_password(host, username, password, version, debug=False, verify=True, param_dict=None): """Do not call directly. Call from PySense""" host = PySenseUtils.format_host(host) token = generate_token(host, username, password, verify=verify) return PySense.PySense(host, token, version, debug=debug, verify=verify, param_dict=param_dict)
def test_scale_suite(): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) result = unittest.TestResult() runner = unittest.TextTestRunner() # Set up linux instance for testing py_client = PySense.authenticate_by_file('resources//TestConfig.yaml') does_cube_exist(py_client, 'PySense', 'TestConfig') dash = py_client.import_dashboards('resources//PySense.dash') user = py_client.get_users(user_name='*****@*****.**') if len(user) == 0: user = py_client.add_user('*****@*****.**', SisenseRole.Role.DESIGNER) else: user = user[0] user2 = py_client.get_users(user_name='*****@*****.**') if len(user2) == 0: user2 = py_client.add_user('*****@*****.**', SisenseRole.Role.DESIGNER) else: user2 = user2[0] group = py_client.get_groups(name='PySense') if len(group) == 0: group = py_client.add_groups('PySense') else: group = group[0] folder = py_client.get_folders(name='PySense') if len(folder) == 0: folder = py_client.add_folder('PySense') else: folder = folder[0] scale_test_suite = prepare_test_suite() print(runner.run(scale_test_suite)) # Remove test assets py_client.delete_dashboards(dash) py_client.delete_users([user, user2]) py_client.delete_groups(group) py_client.delete_folders(folder)
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file( 'resources//TestConfig.yaml') cls.sample_path = 'tmp//' cls.dashboard = cls.py_client.get_dashboards(name='PySense')[0]
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file( 'resources//TestConfig.yaml') cls.user = cls.py_client.get_user_by_email('*****@*****.**') cls.group = cls.py_client.get_groups(name='PySense')[0]
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file( 'resources//LinuxConfig.yaml') cls.data_model = cls.py_client.get_data_models(title='PySense')[0] cls.tmp = 'tmp//' cls.resources = 'resources//'
import csv from PySense import PySense from PySense import SisenseRole py_client = PySense.authenticate_by_file('/Users/nathan.giusti/Documents/PySense/VmConfig.yaml') groups = ['Designers', 'Viewers', 'Data Designers', 'Greendale'] for group in groups: if not py_client.get_groups_by_name(group): py_client.add_groups(group) with open('new_users.csv') as csv_file: reader = csv.DictReader(csv_file) for row in reader: user_groups = py_client.get_groups_by_name(row['groups'].split('|')) py_client.add_user(row['email'], SisenseRole.Role.from_str(row['role']), first_name=row['first_name'], last_name=row['last_name'], groups=user_groups)
import csv from PySense import PySense config_file_location = 'path//SampleConfig.yaml' elasticube_name = 'Data Hierarchy' py_client = PySense.authenticate_by_file(config_file_location) cube = py_client.get_elasticube_by_name(elasticube_name) # Add default security rules for each level for i in range(1, 4): cube.add_data_security_rule('Security_Table.csv', 'level' + str(i), 'text') # This map will track which groups need to get the everything rule for each level. # Remember each group will have a restriction on one column, and everything access to all other columns. everything_rule_map = {'level1': [], 'level2': [], 'level3': []} with open('Security Groups.csv') as csv_file: reader = csv.DictReader(csv_file) for row in reader: group_name = row['group_name'] group = py_client.add_groups(group_name)[ 0] # Not needed if the group already exists. Just get the group. for i in range(1, 4): if i == int( row['level'] ): # If this is the level to apply security at, we set the security rule cube.add_data_security_rule('Security_Table.csv', 'level' + str(i),
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file( 'resources//TestConfig.yaml') cls.plugin = cls.py_client.get_plugins(search='jumpToDashboard')[0]
from PySense import PySense from PySense import SisenseRole py_client = PySense.authenticate_by_password('host', 'username', 'password', 'windows') py_client = PySense.authenticate_by_password('host', 'username', 'password', 'windows', debug=True, verify=False) py_client = PySense.authenticate_by_token( 'host', 'thebearertokenreturnedfromasisenselogincall', 'windows') py_client = PySense.authenticate_by_file('SampleConfig.yaml') print(SisenseRole.Role.from_str('Viewer ')) print(SisenseRole.Role.from_str(' viewer')) print(SisenseRole.Role.from_str('VIEWER')) print(SisenseRole.Role.from_str('cOnSumEr')) role = SisenseRole.Role.from_str('Viewer') print(py_client.get_role_id(role))
- If false, will create a new data model on the server - data_model_to_overwrite - The title of the data model in prod to update. Required if overwrite is true - new_title - The new title of the data model in prod - If overwrite is true, this will not be used - If overwrite is false and this field is left blank, the dev name will be used """ from PySense import PySense dev_config_file_location = 'path//PySenseDev.yaml' prod_config_file_location = 'path//PySenseProd.yaml' dev_client = PySense.authenticate_by_file(dev_config_file_location) prod_client = PySense.authenticate_by_file(prod_config_file_location) data_model_to_migrate = 'Dev Data Model' data_model_to_overwrite = 'Prod Data Model' new_title = None overwrite = True dev_data_model = dev_client.get_data_models(title=data_model_to_migrate) if overwrite: prod_data_model = prod_client.get_data_models( title=data_model_to_overwrite) prod_client.add_data_model(dev_data_model, target_data_model=prod_data_model)
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file( 'resources//TestConfig.yaml') cls.resources = 'resources//' cls.tmp = 'tmp//'
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file('resources//TestConfig.yaml') cls.folder = cls.py_client.get_folders(name='PySense')[0]
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file( 'resources//LinuxConfig.yaml') cls.elasticube = cls.py_client.get_elasticube_by_name('PySense') cls.tmp = 'tmp//'
from PySense import PySense py_client = PySense.authenticate_by_file('SampleConfig.yaml') # Get all groups groups = py_client.get_groups() # Get all groups by name # Can add multiple arguments, see documentation for full list groups = py_client.get_groups(name='MyGroupName') # Create groups by name. group_names = ['Group 1', 'Group 2'] new_groups = py_client.add_groups(groups) # Delete groups py_client.delete_groups(new_groups) # Delete group by name groups_to_delete = py_client.get_groups(name='GroupsToDelete') py_client.delete_groups(groups_to_delete) # Add user py_client.add_user('*****@*****.**', 'Viewer') # Add user with more details. # Can add multiple arguments, see documentation for full list py_client.add_user('*****@*****.**', 'Data Designer', first_name='John', last_name='Doe')
def setUpClass(cls): cls.py_client = PySense.authenticate_by_file('resources//LinuxConfig.yaml') cls.table = cls.py_client.get_data_models(title='PySense')[0].get_data_sets(source='CSV')[0].get_tables()[0]
from PySense import PySense # This is the instantiated PySense class client = PySense.authenticate_by_file('config/sisense.yaml')
from PySense import PySense # Authenticate py_client = PySense.PySense('host', 'username', 'password') # Get the current branding object branding = py_client.get_branding() # Get the JSON for the branding branding_json = branding.get_json() # Set the new branding attribute branding_json['contactUsText'] = 'New contact us text' # Update the branding object branding.set_json(branding_json) # Update PySense with new branding py_client.set_branding(branding)
from PyBluetooth import PyBluetooth from PySense import PySense from network import Bluetooth SERVICE_ID = "8BADF00D-CAFE-8008-1337-BE00DEADBEEF" pySense = PySense() pyBlue = PyBluetooth("BRW-Pycom", SERVICE_ID) pyBlue.startAdvertisement() accelService = pyBlue.addService(SERVICE_ID, 1, True) mode = "roll" rollChar = accelService.characteristic(uuid=b"ab34567890123456", value=str(pySense.getRoll())) def accelServiceHandler(characteristic): global rollChar global mode events = characteristic.events() if events & Bluetooth.CHAR_READ_EVENT: value = None if mode == "roll": value = str(pySense.getRoll()) elif mode == "pitch": value = str(pySense.getPitch()) elif mode == "xyz": value = str(pySense.getAcceleration())
""" Use SQL to query an elasticube and write the results to a csv file. Set the cube_name to the title of the cube to query. Set the query to be your SQL query. Set the path_to_save to the place to save the report. Include a file name. """ from PySense import PySense cube_name = 'My Cube Name' query = "SELECT date, category, sum([Net Revenue]) " \ "FROM [FACT Revenue] f " \ "GROUP BY date, category" path_to_save = 'path//MyQuery.csv' py_client = PySense.authenticate_by_file('C:\\PySense\\PySenseConfig.yaml') cube = py_client.get_elasticube_by_title(cube_name) cube.run_sql(query, "csv", path=path_to_save)