Best Python code snippet using autotest_python
test_db_models_utils_check_index_exists.py
Source:test_db_models_utils_check_index_exists.py
...7 mock_engine = Mock()8 mocker.patch('src.db_models.utils.settings.ENGINE', mock_engine)9 mock_engine.execute.return_value = [('idx', 0)]1011 return_expected = check_index_exists(table_name='tbl1', idx='idx')12 sql = "SELECT indexname FROM pg_indexes WHERE tablename = 'tbl1'"13 mock_engine.execute.assert_called_with(sql)1415 assert return_expected161718def test_db_models_utils_check_index_exists_idx_already_exits_multiple(mocker):19 mock_engine = Mock()20 mocker.patch('src.db_models.utils.settings.ENGINE', mock_engine)21 mock_engine.execute.return_value = [('idx', 0), ('idx2', 0), ('idx3', 0), ('idx4', 0), ]2223 return_expected = check_index_exists(table_name='tbl1', idx='idx4')24 sql = "SELECT indexname FROM pg_indexes WHERE tablename = 'tbl1'"25 mock_engine.execute.assert_called_with(sql)2627 assert return_expected282930def test_db_models_utils_check_index_exists_idx_not_exits(mocker):31 mock_engine = Mock()32 mocker.patch('src.db_models.utils.settings.ENGINE', mock_engine)33 mock_engine.execute.return_value = [('idx', 0)]3435 return_expected = check_index_exists(table_name='tbl1', idx='idx2')36 sql = "SELECT indexname FROM pg_indexes WHERE tablename = 'tbl1'"37 mock_engine.execute.assert_called_with(sql)3839 assert return_expected is False404142def test_db_models_utils_check_index_exists_tbl_not_exits(mocker):43 mock_engine = Mock()44 mocker.patch('src.db_models.utils.settings.ENGINE', mock_engine)45 mock_engine.execute.return_value = []4647 return_expected = check_index_exists(table_name='tbl2', idx='idx')48 sql = "SELECT indexname FROM pg_indexes WHERE tablename = 'tbl2'"49 mock_engine.execute.assert_called_with(sql)50
...
start.py
Source:start.py
...21 if response.code != 200:22 return False23 parsed_response = json.load(response)24 return parsed_response['status'] == 20025def check_index_exists(url, index_name='cloudify_storage'):26 """Check that the cloudify_storage ES index exists."""27 index_url = urlparse.urljoin(url, index_name)28 try:29 return urllib2.urlopen(index_url)30 except urllib2.URLError as e:31 if e.code == 404:32 ctx.abort_operation('The index {0} does not exist in ES'.format(33 index_name))34 else:35 ctx.abort_operation('Invalid ES response: {0}'.format(e))36if not ES_ENDPOINT_IP:37 ctx.logger.info('Starting Elasticsearch Service...')38 utils.start_service(ES_SERVICE_NAME, append_prefix=False)39 ES_ENDPOINT_IP = '127.0.0.1'40 utils.systemd.verify_alive(ES_SERVICE_NAME, append_prefix=False)41elasticsearch_url = 'http://{0}:{1}/'.format(ES_ENDPOINT_IP,42 ES_ENDPOINT_PORT)43utils.verify_service_http(ES_SERVICE_NAME, elasticsearch_url,44 _examine_status_response)...
indexer.py
Source:indexer.py
...6 self.source_file = source_file7 self.source_file_handle = self.check_exists()8 self.index = []9 self.index_file_name = f"{self.source_file}.index"10 self.check_index_exists()11 12 def check_exists(self):13 if os.path.exists(self.source_file):14 return open(self.source_file, errors='ignore')15 return Exception(f"File Not Found, Cannot Index : {self.source_file}")16 17 def check_index_exists(self):18 #print(self.index_file_name,os.path.exists(self.index_file_name))19 if os.path.exists(self.index_file_name):20 print("Index file found.")21 self.index = pickle.load(open(self.index_file_name,'rb'))22 else:23 print("Index file not found, creating now....")24 s = time()25 self.create_index()26 e = time()27 print(f"{e-s} Seconds")28 #return open(self.index_file_name)29 30 31 def __getitem__(self, i):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!