How to use property_value method in Selene

Best Python code snippet using selene_python

TestAmbariClient.py

Source:TestAmbariClient.py Github

copy

Full Screen

1#!/usr/bin/env python2'''3Licensed to the Apache Software Foundation (ASF) under one4or more contributor license agreements. See the NOTICE file5distributed with this work for additional information6regarding copyright ownership. The ASF licenses this file7to you under the Apache License, Version 2.0 (the8"License"); you may not use this file except in compliance9with the License. You may obtain a copy of the License at10 http://www.apache.org/licenses/LICENSE-2.011Unless required by applicable law or agreed to in writing, software12distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions and15limitations under the License.16'''17from mock.mock import MagicMock, patch18from ambari_client.ambari_api import AmbariClient19from HttpClientInvoker import HttpClientInvoker20from ambari_client.model.stack import StackConfigModel, StackComponentModel21import unittest22import logging23class TestAmbariClient(unittest.TestCase):24 def setUp(self):25 http_client_logger = logging.getLogger()26 http_client_logger.info('Running test:' + self.id())27 def create_client(self, http_client_mock = MagicMock()):28 http_client_mock.invoke.side_effect = HttpClientInvoker.http_client_invoke_side_effects29 client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)30 return client31 def test_init(self):32 """33 AmbariClient is the top-level root resources.34 This testcase checks if when the init method was called &35 the httpclient was initialized36 """37 client = AmbariClient("localhost", 8080, "admin", "admin", version=1)38 self.assertEqual(client.version, 1, "version should be 1")39 self.assertEqual(client.host_url, "http://localhost:8080/api/v1",40 "host_url should be http://localhost:8080/api/v1")41 client = AmbariClient(host_name="localhost", user_name="admin", password="admin")42 self.assertEqual(client.version, 1, "version should be 1")43 self.assertEqual(client.host_url, "http://localhost:8080/api/v1",44 "host_url should be http://localhost:8080/api/v1")45 client = AmbariClient(host_name="localhost")46 self.assertEqual(client.version, 1, "version should be 1")47 self.assertEqual(client.host_url, "http://localhost:8080/api/v1",48 "host_url should be http://localhost:8080/api/v1")49 client = AmbariClient("localhost", 8443, "admin", "admin", use_https=True)50 self.assertEqual(client.version, 1, "version should be 1")51 self.assertEqual(client.host_url, "https://localhost:8443/api/v1",52 "host_url should be https://localhost:8443/api/v1")53 def test_get_all_clusters(self):54 """55 Get all clusters.56 This testcase checks if get_all_clusters returns a list of ModelList.57 """58 expected_output = {'items': [{'cluster_name': u'test1', 'version': u'HDP-1.2.1'}]}59 client = self.create_client()60 all_clusters = client.get_all_clusters()61 self.assertEqual(len(all_clusters), 1)62 self.assertEqual(all_clusters.to_json_dict(), expected_output)63 def test_get_cluster(self):64 """65 Get all clusters.66 This testcase checks if get_all_clusters returns a list of ModelList.67 """68 expected_dict_output = {'cluster_name': u'test1', 'version': u'HDP-1.2.1'}69 client = self.create_client()70 cluster = client.get_cluster('test1')71 self.assertEqual(cluster.cluster_name, "test1", "cluster_name should be test1 ")72 self.assertEqual(cluster.to_json_dict(), expected_dict_output, "to_json_dict should convert ClusterModel")73 def test_get_host(self):74 """75 Get host76 This testcase checks if client.get_host returns a correct host77 """78 expected_dict_output = {'ip': '10.0.2.15', 'host_name': 'dev06.hortonworks.com', 'rack_info': '/default-rack'}79 client = self.create_client()80 host = client.get_host('dev06.hortonworks.com')81 self.assertEqual(host.to_json_dict(), expected_dict_output)82 self.assertEqual(host.host_state, "HEARTBEAT_LOST")83 def test_get_all_hosts(self):84 """85 Get all hosts.86 This testcase checks if get_all_hosts returns a list of ModelList.87 """88 expected_hosts_dict = {'items': [{'ip': None, 'host_name': u'apspal44-83', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'apspal44-84', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'apspal44-85', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'apspal44-86', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'apspal44-87', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'apspal44-88', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'apspal44-89', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'r01hn01', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'r01mgt', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'r01wn01', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'r01wn02', 'rack_info': '/default-rack'}, {'ip': None, 'host_name': u'r01wn03', 'rack_info': '/default-rack'}]}89 client = self.create_client()90 all_hosts = client.get_all_hosts()91 self.assertEqual(len(all_hosts), 12, "There should be 12 hosts from the response")92 self.assertEqual(all_hosts.to_json_dict(), expected_hosts_dict)93 def ADisabledtest_bootstrap_hosts(self):94 """95 Test Bootstrap96 """97 http_client_mock = MagicMock()98 ssh_key = 'abc!@#$%^&*()_:"|<>?[];\'\\./'99 host_list = ['dev05.hortonworks.com', 'dev06.hortonworks.com']100 ssh_user = 'root'101 expected_path = '//bootstrap'102 expected_headers = {'Content-Type': 'application/json'}103 expected_request = {'user': ssh_user, 'hosts': str(host_list), 'verbose': True, 'sshKey': ssh_key}104 expected_response = {'status': 201, 'message': u'Running Bootstrap now.', 'requestId': 5}105 client = self.create_client(http_client_mock)106 resp = client.bootstrap_hosts(host_list, ssh_key, ssh_user)107 self.assertEqual(resp.to_json_dict(), expected_response)108 http_client_mock.invoke.assert_called_with('POST', expected_path, headers=expected_headers, payload=expected_request)109 def test_create_cluster(self):110 """111 Test create cluster112 """113 http_client_mock = MagicMock()114 expected_path = '//clusters/c1'115 expected_request = {'Clusters': {'version': 'HDP-2.0.5'}}116 client = self.create_client(http_client_mock)117 resp = client.create_cluster('c1', 'HDP-2.0.5')118 http_client_mock.invoke.assert_called_with('POST', expected_path, headers=None, payload=expected_request)119 def test_delete_cluster(self):120 """121 Test create cluster122 """123 http_client_mock = MagicMock()124 expected_path = '//clusters/c1'125 expected_request = None126 client = self.create_client(http_client_mock)127 resp = client.delete_cluster('c1')128 http_client_mock.invoke.assert_called_with('DELETE', expected_path, headers=None, payload=expected_request)129 def test_delete_host(self):130 """131 Test delete host132 """133 http_client_mock = MagicMock()134 expected_path = '//hosts/abc.abc.abc'135 expected_request = None136 client = self.create_client(http_client_mock)137 resp = client.delete_host('abc.abc.abc')138 http_client_mock.invoke.assert_called_with('DELETE', expected_path, headers=None, payload=expected_request)139 def test_get_config(self):140 """141 Test get config142 """143 expected_dict = {'items': [{'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'datanode_du_reserved', 'property_value': u'1'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.access.time.precision', 'property_value': u'0'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.balance.bandwidthPerSec', 'property_value': u'6250000'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.block.access.token.enable', 'property_value': u'true'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.block.size', 'property_value': u'134217728'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.blockreport.initialDelay', 'property_value': u'120'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.cluster.administrators', 'property_value': u' hdfs'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.datanode.du.pct', 'property_value': u'0.85f'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.datanode.failed.volumes.tolerated', 'property_value': u'0'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.datanode.ipc.address', 'property_value': u'0.0.0.0:8010'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.datanode.max.xcievers', 'property_value': u'4096'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.datanode.socket.write.timeout', 'property_value': u'0'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.heartbeat.interval', 'property_value': u'3'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.https.port', 'property_value': u'50470'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.namenode.avoid.read.stale.datanode', 'property_value': u'true'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.namenode.avoid.write.stale.datanode', 'property_value': u'true'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.namenode.handler.count', 'property_value': u'100'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.namenode.handler.count', 'property_value': u'40'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.namenode.stale.datanode.interval', 'property_value': u'30000'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.namenode.write.stale.datanode.ratio', 'property_value': u'1.0f'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.permissions', 'property_value': u'true'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.permissions.supergroup', 'property_value': u'hdfs'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.replication.max', 'property_value': u'50'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.safemode.threshold.pct', 'property_value': u'1.0f'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.secondary.https.port', 'property_value': u'50490'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.umaskmode', 'property_value': u'077'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs.web.ugi', 'property_value': u'gopher,gopher'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_block_local_path_access_user', 'property_value': u'hbase'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_data_dir', 'property_value': u'/hadoop/hdfs/data'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_datanode_address', 'property_value': u'50010'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_datanode_data_dir_perm', 'property_value': u'750'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_datanode_failed_volume_tolerated', 'property_value': u'0'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_datanode_http_address', 'property_value': u'50075'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_name_dir', 'property_value': u'/hadoop/hdfs/namenode'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_replication', 'property_value': u'3'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dfs_webhdfs_enabled', 'property_value': u'true'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'dtnode_heapsize', 'property_value': u'1024'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'fs.checkpoint.edits.dir', 'property_value': u'${fs.checkpoint.dir}'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'fs.checkpoint.period', 'property_value': u'21600'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'fs.checkpoint.size', 'property_value': u'536870912'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'fs.trash.interval', 'property_value': u'360'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'fs_checkpoint_dir', 'property_value': u'/hadoop/hdfs/namesecondary'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'fs_checkpoint_period', 'property_value': u'21600'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'fs_checkpoint_size', 'property_value': u'0.5'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'hadoop.security.authentication', 'property_value': u'simple'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'hadoop_heapsize', 'property_value': u'1024'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'hadoop_pid_dir_prefix', 'property_value': u'/var/run/hadoop'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'hdfs_log_dir_prefix', 'property_value': u'/var/log/hadoop'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'hdfs_user', 'property_value': u'hdfs'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'io.compression.codec.lzo.class', 'property_value': u'com.hadoop.compression.lzo.LzoCodec'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'io.compression.codecs', 'property_value': u'org.apache.hadoop.io.compress.GzipCodec,org.apache.hadoop.io.compress.DefaultCodec,com.hadoop.compression.lzo.LzoCodec,com.hadoop.compression.lzo.LzopCodec,org.apache.hadoop.io.compress.SnappyCodec'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'io.file.buffer.size', 'property_value': u'131072'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'io.serializations', 'property_value': u'org.apache.hadoop.io.serializer.WritableSerialization'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'ipc.client.connect.max.retries', 'property_value': u'50'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'ipc.client.connection.maxidletime', 'property_value': u'30000'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'ipc.client.idlethreshold', 'property_value': u'8000'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'ipc.server.max.response.size', 'property_value': u'5242880'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'ipc.server.read.threadpool.size', 'property_value': u'5'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'kerberos_domain', 'property_value': u'EXAMPLE.COM'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'keytab_path', 'property_value': u'/etc/security/keytabs'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'namenode_formatted_mark_dir', 'property_value': u'/var/run/hadoop/hdfs/namenode/formatted/'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'namenode_heapsize', 'property_value': u'1024'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'namenode_opt_maxnewsize', 'property_value': u'640'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'namenode_opt_newsize', 'property_value': u'200'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'namenode_opt_maxpermsize', 'property_value': u'256'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'namenode_opt_permsize', 'property_value': u'128'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'proxyuser_group', 'property_value': u'users'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.client.datanode.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.client.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.datanode.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.inter.datanode.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.inter.tracker.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.job.submission.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.namenode.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security.task.umbilical.protocol.acl', 'property_value': u'*'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'security_enabled', 'property_value': u'false'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'property_name': u'webinterface.private.actions', 'property_value': u'false'}]}144 expected_first_item = StackConfigModel(None, property_name='datanode_du_reserved' , property_value='1' , service_name='HDFS' , stack_version='1.3.0')145 expected_request = None146 client = self.create_client()147 configs = client.get_config('1.3.0','HDFS')148 self.assertEquals(len(configs), 77)149 self.assertEquals(str(configs[0]),str(expected_first_item))150 self.assertEquals(configs.to_json_dict(), expected_dict)151 def test_get_components(self):152 """153 Test get components154 """155 expected_dict = {'items': [{'stack_version': u'1.3.0', 'service_name': u'HDFS', 'component_name': u'DATANODE'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'component_name': u'HDFS_CLIENT'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'component_name': u'NAMENODE'}, {'stack_version': u'1.3.0', 'service_name': u'HDFS', 'component_name': u'SECONDARY_NAMENODE'}]}156 expected_first_item = StackComponentModel(None, component_name='DATANODE', service_name='HDFS' , stack_version='1.3.0')157 expected_request = None158 client = self.create_client()159 components = client.get_components('1.3.0','HDFS')160 self.assertEquals(len(components), 4)161 self.assertEquals(str(components[0]),str(expected_first_item))...

Full Screen

Full Screen

Q_filter.py

Source:Q_filter.py Github

copy

Full Screen

1from bulb.utils.log import bulb_logger2import datetime3class BULBQError(Exception):4 pass5class Qstr(str):6 """7 :param complex_query: A simple query is when the search is done on the self instance properties (example:8 "user__name='John'". And a complex query is when the search is focused on the instances9 related (with a relationship) to the self instance (example: user__friends__name="John", we10 search all the friends with name="John")11 """12 def __or__(self, other):13 self_statement = Qstr(self)14 if isinstance(other, Qstr):15 return Qstr(self_statement + " OR " + other)16 elif isinstance(other, Q):17 other_statement = other.filter18 if not other.complex_query:19 return Qstr(self_statement + " OR " + other_statement)20 else:21 bulb_logger.error('BULBQError("Q queries must contains only Q instances.")')22 raise BULBQError("Q queries must contains only Q instances.")23 def __and__(self, other):24 self_statement = Qstr(self)25 if isinstance(other, Qstr):26 return Qstr(self_statement + " AND " + other)27 elif isinstance(other, Q):28 other_statement = other.filter29 return Qstr(self_statement + " AND " + other_statement)30 else:31 bulb_logger.error('BULBQError("Q queries must contains only Q instances.")')32 raise BULBQError("Q queries must contains only Q instances.")33class Q:34 def __init__(self, complex_query=False):35 self.complex_query = complex_query36 def __new__(cls, **kwargs):37 instance = super().__new__(cls)38 instance.filter = kwargs39 instance.build_filter()40 return instance.filter41 def __or__(self, other):42 self_statement = Qstr(self.filter)43 if isinstance(other, Qstr):44 return Qstr(self_statement + " OR " + other)45 elif isinstance(other, Q):46 other_statement = other.filter47 return Qstr(self_statement + " OR " + other_statement)48 else:49 bulb_logger.error('BULBQError("Q queries must contains only Q instances.")')50 raise BULBQError("Q queries must contains only Q instances.")51 def __and__(self, other):52 self_statement = Qstr(self.filter)53 if isinstance(other, Qstr):54 return Qstr(self_statement + " AND " + other)55 elif isinstance(other, Q):56 other_statement = other.filter57 return Qstr(self_statement + " AND " + other_statement)58 else:59 bulb_logger.error('BULBQError("Q queries must contains only Q instances.")')60 raise BULBQError("Q queries must contains only Q instances.")61 def build_filter(self):62 for property_name, property_value in self.filter.items():63 filter_list = property_name.split("__")64 if len(filter_list) == 2:65 parameter_name = filter_list[0]66 action = filter_list[1]67 # Structure filters.68 if action == "startswith":69 self.filter = Qstr(f"n.{parameter_name} STARTS WITH '{property_value}'")70 if action == "not_startswith":71 self.filter = Qstr(f"NOT n.{parameter_name} STARTS WITH '{property_value}'")72 elif action == "endswith":73 self.filter = Qstr(f"n.{parameter_name} ENDS WITH '{property_value}'")74 elif action == "not_endswith":75 self.filter = Qstr(f"NOT n.{parameter_name} ENDS WITH '{property_value}'")76 elif action == "contains":77 self.filter = Qstr(f"n.{parameter_name} CONTAINS '{property_value}'")78 elif action == "not_contains":79 self.filter = Qstr(f"NOT n.{parameter_name} CONTAINS '{property_value}'")80 elif action == "regex":81 self.filter = Qstr(f"n.{parameter_name} =~ '{property_value}'")82 elif action == "not_regex":83 self.filter = Qstr(f"NOT n.{parameter_name} =~ '{property_value}'")84 elif action == "exact":85 if isinstance(property_value, bool) or isinstance(property_value, int) or isinstance(property_value, list):86 self.filter = Qstr(f"n.{parameter_name} = {property_value}")87 elif isinstance(property_value, datetime.datetime):88 self.filter = Qstr(f"n.{parameter_name} = datetime('{str(property_value).replace(' ', 'T')}')")89 elif isinstance(property_value, datetime.date):90 self.filter = Qstr(f"n.{parameter_name} = date('{property_value}')")91 elif isinstance(property_value, datetime.time):92 self.filter = Qstr(f"n.{parameter_name} = time('{property_value}')")93 elif isinstance(property_value, str):94 self.filter = Qstr(f"n.{parameter_name} = '{property_value}'")95 else:96 self.filter = Qstr(f"n.{parameter_name} = '{property_value}'")97 elif action == "not_exact":98 if isinstance(property_value, bool) or isinstance(property_value, int) or isinstance(property_value, list):99 self.filter = Qstr(f"NOT n.{parameter_name} = {property_value}")100 elif isinstance(property_value, datetime.datetime):101 self.filter = Qstr(f"NOT n.{parameter_name} = datetime('{str(property_value).replace(' ', 'T')}')")102 elif isinstance(property_value, datetime.date):103 self.filter = Qstr(f"NOT n.{parameter_name} = date('{property_value}')")104 elif isinstance(property_value, datetime.time):105 self.filter = Qstr(f"NOT n.{parameter_name} = time('{property_value}')")106 elif isinstance(property_value, str):107 self.filter = Qstr(f"NOT n.{parameter_name} = '{property_value}'")108 else:109 self.filter = Qstr(f"NOT n.{parameter_name} = '{property_value}'")110 # Case insensitive structure filters.111 elif action == "istartswith":112 self.filter = Qstr(f"n.{parameter_name} =~ '(?i){property_value}(.*)'")113 elif action == "not_istartswith":114 self.filter = Qstr(f"NOT n.{parameter_name} =~ '(?i){property_value}(.*)'")115 elif action == "iendswith":116 self.filter = Qstr(f"n.{parameter_name} =~ '(?i)(.*){property_value}'")117 elif action == "not_iendswith":118 self.filter = Qstr(f"NOT n.{parameter_name} =~ '(?i)(.*){property_value}'")119 elif action == "icontains":120 self.filter = Qstr(f"n.{parameter_name} =~ '(?i)(.*){property_value}(.*)'")121 elif action == "not_icontains":122 self.filter = Qstr(f"NOT n.{parameter_name} =~ '(?i)(.*){property_value}(.*)'")123 elif action == "iregex":124 self.filter = Qstr(f"n.{parameter_name} =~ '(?i){property_value}'")125 elif action == "not_iregex":126 self.filter = Qstr(f"NOT n.{parameter_name} =~ '(?i){property_value}'")127 elif action == "iexact":128 if isinstance(property_value, bool) or isinstance(property_value, int) or isinstance(property_value, list):129 self.filter = Qstr(f"n.{parameter_name} = {property_value}")130 elif isinstance(property_value, datetime.datetime):131 self.filter = Qstr(f"n.{parameter_name} = datetime('{str(property_value).replace(' ', 'T')}')")132 elif isinstance(property_value, datetime.date):133 self.filter = Qstr(f"n.{parameter_name} = date('{property_value}')")134 elif isinstance(property_value, datetime.time):135 self.filter = Qstr(f"n.{parameter_name} = time('{property_value}')")136 elif isinstance(property_value, str):137 self.filter = Qstr(f"n.{parameter_name} =~ '(?i){property_value}'")138 else:139 self.filter = Qstr(f"n.{parameter_name} =~ '(?i){property_value}'")140 elif action == "not_iexact":141 if isinstance(property_value, bool) or isinstance(property_value, int) or isinstance(property_value, list):142 self.filter = Qstr(f"NOT n.{parameter_name} = {property_value}")143 elif isinstance(property_value, datetime.datetime):144 self.filter = Qstr(f"NOT n.{parameter_name} = datetime('{str(property_value).replace(' ', 'T')}')")145 elif isinstance(property_value, datetime.date):146 self.filter = Qstr(f"NOT n.{parameter_name} = date('{property_value}')")147 elif isinstance(property_value, datetime.time):148 self.filter = Qstr(f"NOT n.{parameter_name} = time('{property_value}')")149 elif isinstance(property_value, str):150 self.filter = Qstr(f"NOT n.{parameter_name} =~ '(?i){property_value}'")151 else:152 self.filter = Qstr(f"n.{parameter_name} =~ '(?i){property_value}'")153 # Quantity and datetime filters.154 elif action == "lt":155 if isinstance(property_value, int):156 self.filter = Qstr(f"n.{parameter_name} < {property_value}")157 elif isinstance(property_value, datetime.datetime):158 self.filter = Qstr(f"n.{parameter_name} < datetime('{str(property_value).replace(' ', 'T')}')")159 elif isinstance(property_value, datetime.date):160 self.filter = Qstr(f"n.{parameter_name} < date('{property_value}')")161 elif isinstance(property_value, datetime.time):162 self.filter = Qstr(f"n.{parameter_name} < time('{property_value}')")163 elif action == "gt":164 if isinstance(property_value, int):165 self.filter = Qstr(f"n.{parameter_name} > {property_value}")166 elif isinstance(property_value, datetime.datetime):167 self.filter = Qstr(f"n.{parameter_name} > datetime('{str(property_value).replace(' ', 'T')}')")168 elif isinstance(property_value, datetime.date):169 self.filter = Qstr(f"n.{parameter_name} > date('{property_value}')")170 elif isinstance(property_value, datetime.time):171 self.filter = Qstr(f"n.{parameter_name} > time('{property_value}')")172 elif action == "lte":173 if isinstance(property_value, int):174 self.filter = Qstr(f"n.{parameter_name} <= {property_value}")175 elif isinstance(property_value, datetime.datetime):176 self.filter = Qstr(f"n.{parameter_name} <= datetime('{str(property_value).replace(' ', 'T')}')")177 elif isinstance(property_value, datetime.date):178 self.filter = Qstr(f"n.{parameter_name} <= date('{property_value}')")179 elif isinstance(property_value, datetime.time):180 self.filter = Qstr(f"n.{parameter_name} <= time('{property_value}')")181 elif action == "gte":182 if isinstance(property_value, int):183 self.filter = Qstr(f"n.{parameter_name} >= {property_value}")184 elif isinstance(property_value, datetime.datetime):185 self.filter = Qstr(f"n.{parameter_name} >= datetime('{str(property_value).replace(' ', 'T')}')")186 elif isinstance(property_value, datetime.date):187 self.filter = Qstr(f"n.{parameter_name} >= date('{property_value}')")188 elif isinstance(property_value, datetime.time):189 self.filter = Qstr(f"n.{parameter_name} >= time('{property_value}')")190 # Year.191 elif action == "year" or action == "year_exact":192 self.filter = Qstr(f"date(n.{parameter_name}).year = {property_value}")193 elif action == "year_lt":194 self.filter = Qstr(f"date(n.{parameter_name}).year < {property_value}")195 elif action == "year_gt":196 self.filter = Qstr(f"date(n.{parameter_name}).year > {property_value}")197 elif action == "year_lte":198 self.filter = Qstr(f"date(n.{parameter_name}).year <= {property_value}")199 elif action == "year_gte":200 self.filter = Qstr(f"date(n.{parameter_name}).year >= {property_value}")201 # Month.202 elif action == "month" or action == "month_exact":203 self.filter = Qstr(f"date(n.{parameter_name}).month = {property_value}")204 elif action == "month_lt":205 self.filter = Qstr(f"date(n.{parameter_name}).month < {property_value}")206 elif action == "month_gt":207 self.filter = Qstr(f"date(n.{parameter_name}).month > {property_value}")208 elif action == "month_lte":209 self.filter = Qstr(f"date(n.{parameter_name}).month <= {property_value}")210 elif action == "month_gte":211 self.filter = Qstr(f"date(n.{parameter_name}).month >= {property_value}")212 # Day.213 elif action == "day" or action == "day_exact":214 self.filter = Qstr(f"date(n.{parameter_name}).day = {property_value}")215 elif action == "day_lt":216 self.filter = Qstr(f"date(n.{parameter_name}).day < {property_value}")217 elif action == "day_gt":218 self.filter = Qstr(f"date(n.{parameter_name}).day > {property_value}")219 elif action == "day_lte":220 self.filter = Qstr(f"date(n.{parameter_name}).day <= {property_value}")221 elif action == "day_gte":222 self.filter = Qstr(f"date(n.{parameter_name}).day >= {property_value}")223 # Hour.224 elif action == "hour" or action == "hour_exact":225 self.filter = Qstr(f"time(n.{parameter_name}).hour = {property_value}")226 elif action == "hour_lt":227 self.filter = Qstr(f"time(n.{parameter_name}).hour < {property_value}")228 elif action == "hour_gt":229 self.filter = Qstr(f"time(n.{parameter_name}).hour > {property_value}")230 elif action == "hour_lte":231 self.filter = Qstr(f"time(n.{parameter_name}).hour <= {property_value}")232 elif action == "hour_gte":233 self.filter = Qstr(f"time(n.{parameter_name}).hour >= {property_value}")234 # Minute.235 elif action == "minute" or action == "minute_exact":236 self.filter = Qstr(f"time(n.{parameter_name}).minute = {property_value}")237 elif action == "minute_lt":238 self.filter = Qstr(f"time(n.{parameter_name}).minute < {property_value}")239 elif action == "minute_gt":240 self.filter = Qstr(f"time(n.{parameter_name}).minute > {property_value}")241 elif action == "minute_lte":242 self.filter = Qstr(f"time(n.{parameter_name}).minute <= {property_value}")243 elif action == "minute_gte":244 self.filter = Qstr(f"time(n.{parameter_name}).minute >= {property_value}")245 # Second.246 elif action == "second" or action == "second_exact":247 self.filter = Qstr(f"time(n.{parameter_name}).second = {property_value}")248 elif action == "second_lt":249 self.filter = Qstr(f"time(n.{parameter_name}).second < {property_value}")250 elif action == "second_gt":251 self.filter = Qstr(f"time(n.{parameter_name}).second > {property_value}")252 elif action == "second_lte":253 self.filter = Qstr(f"time(n.{parameter_name}).second <= {property_value}")254 elif action == "second_gte":255 self.filter = Qstr(f"time(n.{parameter_name}).second >= {property_value}")256 else:257 bulb_logger.error(258 'BULBQError("Q queries must respect the syntax : \'param__action=property_value\'")')...

Full Screen

Full Screen

ciaparser.py

Source:ciaparser.py Github

copy

Full Screen

1#!/usr/bin/env python2import json3import os4from collections import Counter5import pycountry6import bs47NUMERIC_PROPS = {8 'Labor force',9 'Population',10 'Area',11 'Crude oil - proved reserves',12 'Railways',13 'HIV/AIDS - people living with HIV/AIDS',14}15PERCENTAGE_PROPS = {'Land use': 'Area'}16def strip_brackets(value):17 p = value.find('(')18 if p > -1:19 value = value[:p].strip()20 return value21def parse_number(property_value):22 value = strip_brackets(property_value)23 value = value.replace(',', '')24 value = value.lower()25 multipliers = {'thousand': 3, 'million': 6, 'billion': 9, 'trillion': 12}26 words = [x.strip() for x in value.split()]27 words = [28 word for word in words if word and not word in ('approximately', 'km')29 ]30 if words[0] == 'na':31 return 032 try:33 value = float(words[0])34 except ValueError:35 return 036 for word in words[1:]:37 zeroes = multipliers.get(word, 0)38 value *= 10 ** zeroes39 return value40def make_dollars(property_value):41 return parse_number(property_value[1:])42def parse_country(html):43 res = {}44 soup = bs4.BeautifulSoup(html, 'html.parser')45 property_name = None46 for tr in soup.find_all('tr'):47 div_1 = tr.find('div', class_='category')48 if div_1:49 note = div_1.find('em')50 if note:51 if note.get_text().strip(' :') == 'note':52 div_1 = None53 if div_1:54 anchor = div_1.find('a')55 if anchor:56 property_name = str(anchor.contents[0]).strip(' :')57 property_value = None58 else:59 span = div_1.find('span', class_='category_data')60 if span:61 property_value = span.get_text().strip()62 else:63 div_2 = tr.find('div', class_='category_data')64 if div_2:65 if property_name:66 property_value = div_2.get_text().strip()67 if property_name and property_value:68 if property_name == 'Area':69 property_value = property_value.replace('sq km', '').strip()70 if property_name == 'Crude oil - proved reserves':71 property_value = property_value.replace('bbl', '').strip()72 if property_value.startswith('$'):73 property_value = make_dollars(property_value)74 elif property_name in NUMERIC_PROPS:75 if property_value.strip().lower() == 'uninhabited':76 property_value = 077 else:78 property_value = parse_number(property_value)79 elif property_name in PERCENTAGE_PROPS:80 property_value = property_value.strip(' %')81 property_value = parse_number(property_value)82 elif len(property_value) > 50:83 continue84 res[property_name] = property_value85 property_name = None86 for k, v in PERCENTAGE_PROPS.items():87 if k in res:88 if v in res:89 res[k] = res[v] * res[k]90 else:91 del res[k]92 return res93def parse_id_table(html):94 res = {}95 soup = bs4.BeautifulSoup(html, 'html.parser')96 for li in soup.find_all('li', class_='category'):97 td_texts = [td.get_text().strip() for td in li.find_all('td')]98 res[td_texts[1].lower()] = td_texts[3].lower()99 return res100def main():101 with open('data/appendix-d.html', 'rb') as fin:102 id_table = parse_id_table(fin.read())103 counts = Counter()104 countries = {}105 for fn in os.listdir('data/geos'):106 if fn.endswith('.html'):107 cia_id = fn[:2]108 if cia_id in ('ee', 'oo', 'sk', 'um', 'xo', 'xq', 'xx', 'zh', 'zn'):109 # various oceans and other entities110 continue111 if cia_id == 'cc': # huh?112 cia_id = 'uc'113 cc = id_table[cia_id]114 #print(cia_id, cc)115 if cc == '-':116 continue117 with open(os.path.join('data/geos', fn), 'rb') as fin:118 countries[cc] = parse_country(fin.read())119 for k in countries[cc]:120 counts[k] += 1121 with open('data/cia_data.js', 'w') as fout:122 fout.write(json.dumps(countries, indent=2))123 print('Countries:', len(countries))124 for k, v in counts.most_common():125 print(k, 100 * v / len(countries))126if __name__ == '__main__':...

Full Screen

Full Screen

briar.py

Source:briar.py Github

copy

Full Screen

...24 continue25 if not property_value.get('type'):26 continue27 prop_value_name, prop_value = \28 get_attachment_property_value(property_value)29 if not prop_value:30 continue31 if not property_value['type'].endswith('PropertyValue'):32 continue33 property_value[prop_value_name] = prop_value.strip()34 if len(property_value[prop_value_name]) < 50:35 continue36 if not property_value[prop_value_name].startswith('briar://'):37 continue38 if property_value[prop_value_name].lower() != \39 property_value[prop_value_name]:40 continue41 if '"' in property_value[prop_value_name]:42 continue43 if ' ' in property_value[prop_value_name]:44 continue45 if ',' in property_value[prop_value_name]:46 continue47 if '.' in property_value[prop_value_name]:48 continue49 return property_value[prop_value_name]50 return ''51def set_briar_address(actor_json: {}, briar_address: str) -> None:52 """Sets an briar address for the given actor53 """54 not_briar_address = False55 if len(briar_address) < 50:56 not_briar_address = True57 if not briar_address.startswith('briar://'):58 not_briar_address = True59 if briar_address.lower() != briar_address:60 not_briar_address = True61 if '"' in briar_address:62 not_briar_address = True63 if ' ' in briar_address:64 not_briar_address = True65 if '.' in briar_address:66 not_briar_address = True67 if ',' in briar_address:68 not_briar_address = True69 if '<' in briar_address:70 not_briar_address = True71 if not actor_json.get('attachment'):72 actor_json['attachment'] = []73 # remove any existing value74 property_found = None75 for property_value in actor_json['attachment']:76 name_value = None77 if property_value.get('name'):78 name_value = property_value['name']79 elif property_value.get('schema:name'):80 name_value = property_value['schema:name']81 if not name_value:82 continue83 if not property_value.get('type'):84 continue85 if not name_value.lower().startswith('briar'):86 continue87 property_found = property_value88 break89 if property_found:90 actor_json['attachment'].remove(property_found)91 if not_briar_address:92 return93 for property_value in actor_json['attachment']:94 name_value = None95 if property_value.get('name'):96 name_value = property_value['name']97 elif property_value.get('schema:name'):98 name_value = property_value['schema:name']99 if not name_value:100 continue101 if not property_value.get('type'):102 continue103 if not name_value.lower().startswith('briar'):104 continue105 if not property_value['type'].endswith('PropertyValue'):106 continue107 prop_value_name, _ = \108 get_attachment_property_value(property_value)109 if not prop_value_name:110 continue111 property_value[prop_value_name] = briar_address112 return113 new_briar_address = {114 "name": "Briar",115 "type": "PropertyValue",116 "value": briar_address117 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful