How to use cursor method in autotest

Best Python code snippet using autotest_python

test_extras_dictcursor.py

Source:test_extras_dictcursor.py Github

copy

Full Screen

...22class ExtrasDictCursorTests(ConnectingTestCase):23 """Test if DictCursor extension class works."""24 def setUp(self):25 ConnectingTestCase.setUp(self)26 curs = self.conn.cursor()27 curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)")28 curs.execute("INSERT INTO ExtrasDictCursorTests VALUES ('bar')")29 self.conn.commit()30 def testDictConnCursorArgs(self):31 self.conn.close()32 self.conn = self.connect(connection_factory=psycopg2.extras.DictConnection)33 cur = self.conn.cursor()34 self.assertTrue(isinstance(cur, psycopg2.extras.DictCursor))35 self.assertEqual(cur.name, None)36 # overridable37 cur = self.conn.cursor('foo',38 cursor_factory=psycopg2.extras.NamedTupleCursor)39 self.assertEqual(cur.name, 'foo')40 self.assertTrue(isinstance(cur, psycopg2.extras.NamedTupleCursor))41 def testDictCursorWithPlainCursorFetchOne(self):42 self._testWithPlainCursor(lambda curs: curs.fetchone())43 def testDictCursorWithPlainCursorFetchMany(self):44 self._testWithPlainCursor(lambda curs: curs.fetchmany(100)[0])45 def testDictCursorWithPlainCursorFetchManyNoarg(self):46 self._testWithPlainCursor(lambda curs: curs.fetchmany()[0])47 def testDictCursorWithPlainCursorFetchAll(self):48 self._testWithPlainCursor(lambda curs: curs.fetchall()[0])49 def testDictCursorWithPlainCursorIter(self):50 def getter(curs):51 for row in curs:52 return row53 self._testWithPlainCursor(getter)54 def testUpdateRow(self):55 row = self._testWithPlainCursor(lambda curs: curs.fetchone())56 row['foo'] = 'qux'57 self.assertTrue(row['foo'] == 'qux')58 self.assertTrue(row[0] == 'qux')59 @skip_before_postgres(8, 0)60 def testDictCursorWithPlainCursorIterRowNumber(self):61 curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)62 self._testIterRowNumber(curs)63 def _testWithPlainCursor(self, getter):64 curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)65 curs.execute("SELECT * FROM ExtrasDictCursorTests")66 row = getter(curs)67 self.assertTrue(row['foo'] == 'bar')68 self.assertTrue(row[0] == 'bar')69 return row70 def testDictCursorWithPlainCursorRealFetchOne(self):71 self._testWithPlainCursorReal(lambda curs: curs.fetchone())72 def testDictCursorWithPlainCursorRealFetchMany(self):73 self._testWithPlainCursorReal(lambda curs: curs.fetchmany(100)[0])74 def testDictCursorWithPlainCursorRealFetchManyNoarg(self):75 self._testWithPlainCursorReal(lambda curs: curs.fetchmany()[0])76 def testDictCursorWithPlainCursorRealFetchAll(self):77 self._testWithPlainCursorReal(lambda curs: curs.fetchall()[0])78 def testDictCursorWithPlainCursorRealIter(self):79 def getter(curs):80 for row in curs:81 return row82 self._testWithPlainCursorReal(getter)83 @skip_before_postgres(8, 0)84 def testDictCursorWithPlainCursorRealIterRowNumber(self):85 curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)86 self._testIterRowNumber(curs)87 def _testWithPlainCursorReal(self, getter):88 curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)89 curs.execute("SELECT * FROM ExtrasDictCursorTests")90 row = getter(curs)91 self.assertTrue(row['foo'] == 'bar')92 def testDictCursorWithNamedCursorFetchOne(self):93 self._testWithNamedCursor(lambda curs: curs.fetchone())94 def testDictCursorWithNamedCursorFetchMany(self):95 self._testWithNamedCursor(lambda curs: curs.fetchmany(100)[0])96 def testDictCursorWithNamedCursorFetchManyNoarg(self):97 self._testWithNamedCursor(lambda curs: curs.fetchmany()[0])98 def testDictCursorWithNamedCursorFetchAll(self):99 self._testWithNamedCursor(lambda curs: curs.fetchall()[0])100 def testDictCursorWithNamedCursorIter(self):101 def getter(curs):102 for row in curs:103 return row104 self._testWithNamedCursor(getter)105 @skip_before_postgres(8, 2)106 def testDictCursorWithNamedCursorNotGreedy(self):107 curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.DictCursor)108 self._testNamedCursorNotGreedy(curs)109 @skip_before_postgres(8, 0)110 def testDictCursorWithNamedCursorIterRowNumber(self):111 curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.DictCursor)112 self._testIterRowNumber(curs)113 def _testWithNamedCursor(self, getter):114 curs = self.conn.cursor('aname', cursor_factory=psycopg2.extras.DictCursor)115 curs.execute("SELECT * FROM ExtrasDictCursorTests")116 row = getter(curs)117 self.assertTrue(row['foo'] == 'bar')118 self.assertTrue(row[0] == 'bar')119 def testDictCursorRealWithNamedCursorFetchOne(self):120 self._testWithNamedCursorReal(lambda curs: curs.fetchone())121 def testDictCursorRealWithNamedCursorFetchMany(self):122 self._testWithNamedCursorReal(lambda curs: curs.fetchmany(100)[0])123 def testDictCursorRealWithNamedCursorFetchManyNoarg(self):124 self._testWithNamedCursorReal(lambda curs: curs.fetchmany()[0])125 def testDictCursorRealWithNamedCursorFetchAll(self):126 self._testWithNamedCursorReal(lambda curs: curs.fetchall()[0])127 def testDictCursorRealWithNamedCursorIter(self):128 def getter(curs):129 for row in curs:130 return row131 self._testWithNamedCursorReal(getter)132 @skip_before_postgres(8, 2)133 def testDictCursorRealWithNamedCursorNotGreedy(self):134 curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.RealDictCursor)135 self._testNamedCursorNotGreedy(curs)136 @skip_before_postgres(8, 0)137 def testDictCursorRealWithNamedCursorIterRowNumber(self):138 curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.RealDictCursor)139 self._testIterRowNumber(curs)140 def _testWithNamedCursorReal(self, getter):141 curs = self.conn.cursor('aname',142 cursor_factory=psycopg2.extras.RealDictCursor)143 curs.execute("SELECT * FROM ExtrasDictCursorTests")144 row = getter(curs)145 self.assertTrue(row['foo'] == 'bar')146 def _testNamedCursorNotGreedy(self, curs):147 curs.itersize = 2148 curs.execute("""select clock_timestamp() as ts from generate_series(1,3)""")149 recs = []150 for t in curs:151 time.sleep(0.01)152 recs.append(t)153 # check that the dataset was not fetched in a single gulp154 self.assertTrue(recs[1]['ts'] - recs[0]['ts'] < timedelta(seconds=0.005))155 self.assertTrue(recs[2]['ts'] - recs[1]['ts'] > timedelta(seconds=0.0099))156 def _testIterRowNumber(self, curs):157 # Only checking for dataset < itersize:158 # see CursorTests.test_iter_named_cursor_rownumber159 curs.itersize = 20160 curs.execute("""select * from generate_series(1,10)""")161 for i, r in enumerate(curs):162 self.assertEqual(i + 1, curs.rownumber)163 def testPickleDictRow(self):164 import pickle165 curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)166 curs.execute("select 10 as a, 20 as b")167 r = curs.fetchone()168 d = pickle.dumps(r)169 r1 = pickle.loads(d)170 self.assertEqual(r, r1)171 self.assertEqual(r[0], r1[0])172 self.assertEqual(r[1], r1[1])173 self.assertEqual(r['a'], r1['a'])174 self.assertEqual(r['b'], r1['b'])175 self.assertEqual(r._index, r1._index)176 def testPickleRealDictRow(self):177 import pickle178 curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)179 curs.execute("select 10 as a, 20 as b")180 r = curs.fetchone()181 d = pickle.dumps(r)182 r1 = pickle.loads(d)183 self.assertEqual(r, r1)184 self.assertEqual(r['a'], r1['a'])185 self.assertEqual(r['b'], r1['b'])186 self.assertEqual(r._column_mapping, r1._column_mapping)187class NamedTupleCursorTest(ConnectingTestCase):188 def setUp(self):189 ConnectingTestCase.setUp(self)190 from psycopg2.extras import NamedTupleConnection191 try:192 from collections import namedtuple # noqa193 except ImportError:194 return195 self.conn = self.connect(connection_factory=NamedTupleConnection)196 curs = self.conn.cursor()197 curs.execute("CREATE TEMPORARY TABLE nttest (i int, s text)")198 curs.execute("INSERT INTO nttest VALUES (1, 'foo')")199 curs.execute("INSERT INTO nttest VALUES (2, 'bar')")200 curs.execute("INSERT INTO nttest VALUES (3, 'baz')")201 self.conn.commit()202 @skip_if_no_namedtuple203 def test_cursor_args(self):204 cur = self.conn.cursor('foo', cursor_factory=psycopg2.extras.DictCursor)205 self.assertEqual(cur.name, 'foo')206 self.assertTrue(isinstance(cur, psycopg2.extras.DictCursor))207 @skip_if_no_namedtuple208 def test_fetchone(self):209 curs = self.conn.cursor()210 curs.execute("select * from nttest order by 1")211 t = curs.fetchone()212 self.assertEqual(t[0], 1)213 self.assertEqual(t.i, 1)214 self.assertEqual(t[1], 'foo')215 self.assertEqual(t.s, 'foo')216 self.assertEqual(curs.rownumber, 1)217 self.assertEqual(curs.rowcount, 3)218 @skip_if_no_namedtuple219 def test_fetchmany_noarg(self):220 curs = self.conn.cursor()221 curs.arraysize = 2222 curs.execute("select * from nttest order by 1")223 res = curs.fetchmany()224 self.assertEqual(2, len(res))225 self.assertEqual(res[0].i, 1)226 self.assertEqual(res[0].s, 'foo')227 self.assertEqual(res[1].i, 2)228 self.assertEqual(res[1].s, 'bar')229 self.assertEqual(curs.rownumber, 2)230 self.assertEqual(curs.rowcount, 3)231 @skip_if_no_namedtuple232 def test_fetchmany(self):233 curs = self.conn.cursor()234 curs.execute("select * from nttest order by 1")235 res = curs.fetchmany(2)236 self.assertEqual(2, len(res))237 self.assertEqual(res[0].i, 1)238 self.assertEqual(res[0].s, 'foo')239 self.assertEqual(res[1].i, 2)240 self.assertEqual(res[1].s, 'bar')241 self.assertEqual(curs.rownumber, 2)242 self.assertEqual(curs.rowcount, 3)243 @skip_if_no_namedtuple244 def test_fetchall(self):245 curs = self.conn.cursor()246 curs.execute("select * from nttest order by 1")247 res = curs.fetchall()248 self.assertEqual(3, len(res))249 self.assertEqual(res[0].i, 1)250 self.assertEqual(res[0].s, 'foo')251 self.assertEqual(res[1].i, 2)252 self.assertEqual(res[1].s, 'bar')253 self.assertEqual(res[2].i, 3)254 self.assertEqual(res[2].s, 'baz')255 self.assertEqual(curs.rownumber, 3)256 self.assertEqual(curs.rowcount, 3)257 @skip_if_no_namedtuple258 def test_executemany(self):259 curs = self.conn.cursor()260 curs.executemany("delete from nttest where i = %s",261 [(1,), (2,)])262 curs.execute("select * from nttest order by 1")263 res = curs.fetchall()264 self.assertEqual(1, len(res))265 self.assertEqual(res[0].i, 3)266 self.assertEqual(res[0].s, 'baz')267 @skip_if_no_namedtuple268 def test_iter(self):269 curs = self.conn.cursor()270 curs.execute("select * from nttest order by 1")271 i = iter(curs)272 self.assertEqual(curs.rownumber, 0)273 t = next(i)274 self.assertEqual(t.i, 1)275 self.assertEqual(t.s, 'foo')276 self.assertEqual(curs.rownumber, 1)277 self.assertEqual(curs.rowcount, 3)278 t = next(i)279 self.assertEqual(t.i, 2)280 self.assertEqual(t.s, 'bar')281 self.assertEqual(curs.rownumber, 2)282 self.assertEqual(curs.rowcount, 3)283 t = next(i)284 self.assertEqual(t.i, 3)285 self.assertEqual(t.s, 'baz')286 self.assertRaises(StopIteration, i.__next__)287 self.assertEqual(curs.rownumber, 3)288 self.assertEqual(curs.rowcount, 3)289 def test_error_message(self):290 try:291 from collections import namedtuple # noqa292 except ImportError:293 # an import error somewhere294 from psycopg2.extras import NamedTupleConnection295 try:296 self.conn = self.connect(297 connection_factory=NamedTupleConnection)298 curs = self.conn.cursor()299 curs.execute("select 1")300 curs.fetchone()301 except ImportError:302 pass303 else:304 self.fail("expecting ImportError")305 else:306 return self.skipTest("namedtuple available")307 @skip_if_no_namedtuple308 def test_record_updated(self):309 curs = self.conn.cursor()310 curs.execute("select 1 as foo;")311 r = curs.fetchone()312 self.assertEqual(r.foo, 1)313 curs.execute("select 2 as bar;")314 r = curs.fetchone()315 self.assertEqual(r.bar, 2)316 self.assertRaises(AttributeError, getattr, r, 'foo')317 @skip_if_no_namedtuple318 def test_no_result_no_surprise(self):319 curs = self.conn.cursor()320 curs.execute("update nttest set s = s")321 self.assertRaises(psycopg2.ProgrammingError, curs.fetchone)322 curs.execute("update nttest set s = s")323 self.assertRaises(psycopg2.ProgrammingError, curs.fetchall)324 @skip_if_no_namedtuple325 def test_bad_col_names(self):326 curs = self.conn.cursor()327 curs.execute('select 1 as "foo.bar_baz", 2 as "?column?", 3 as "3"')328 rv = curs.fetchone()329 self.assertEqual(rv.foo_bar_baz, 1)330 self.assertEqual(rv.f_column_, 2)331 self.assertEqual(rv.f3, 3)332 @skip_if_no_namedtuple333 def test_minimal_generation(self):334 # Instrument the class to verify it gets called the minimum number of times.335 from psycopg2.extras import NamedTupleCursor336 f_orig = NamedTupleCursor._make_nt337 calls = [0]338 def f_patched(self_):339 calls[0] += 1340 return f_orig(self_)341 NamedTupleCursor._make_nt = f_patched342 try:343 curs = self.conn.cursor()344 curs.execute("select * from nttest order by 1")345 curs.fetchone()346 curs.fetchone()347 curs.fetchone()348 self.assertEqual(1, calls[0])349 curs.execute("select * from nttest order by 1")350 curs.fetchone()351 curs.fetchall()352 self.assertEqual(2, calls[0])353 curs.execute("select * from nttest order by 1")354 curs.fetchone()355 curs.fetchmany(1)356 self.assertEqual(3, calls[0])357 finally:358 NamedTupleCursor._make_nt = f_orig359 @skip_if_no_namedtuple360 @skip_before_postgres(8, 0)361 def test_named(self):362 curs = self.conn.cursor('tmp')363 curs.execute("""select i from generate_series(0,9) i""")364 recs = []365 recs.extend(curs.fetchmany(5))366 recs.append(curs.fetchone())367 recs.extend(curs.fetchall())368 self.assertEqual(list(range(10)), [t.i for t in recs])369 @skip_if_no_namedtuple370 def test_named_fetchone(self):371 curs = self.conn.cursor('tmp')372 curs.execute("""select 42 as i""")373 t = curs.fetchone()374 self.assertEqual(t.i, 42)375 @skip_if_no_namedtuple376 def test_named_fetchmany(self):377 curs = self.conn.cursor('tmp')378 curs.execute("""select 42 as i""")379 recs = curs.fetchmany(10)380 self.assertEqual(recs[0].i, 42)381 @skip_if_no_namedtuple382 def test_named_fetchall(self):383 curs = self.conn.cursor('tmp')384 curs.execute("""select 42 as i""")385 recs = curs.fetchall()386 self.assertEqual(recs[0].i, 42)387 @skip_if_no_namedtuple388 @skip_before_postgres(8, 2)389 def test_not_greedy(self):390 curs = self.conn.cursor('tmp')391 curs.itersize = 2392 curs.execute("""select clock_timestamp() as ts from generate_series(1,3)""")393 recs = []394 for t in curs:395 time.sleep(0.01)396 recs.append(t)397 # check that the dataset was not fetched in a single gulp398 self.assertTrue(recs[1].ts - recs[0].ts < timedelta(seconds=0.005))399 self.assertTrue(recs[2].ts - recs[1].ts > timedelta(seconds=0.0099))400 @skip_if_no_namedtuple401 @skip_before_postgres(8, 0)402 def test_named_rownumber(self):403 curs = self.conn.cursor('tmp')404 # Only checking for dataset < itersize:405 # see CursorTests.test_iter_named_cursor_rownumber406 curs.itersize = 4407 curs.execute("""select * from generate_series(1,3)""")408 for i, t in enumerate(curs):409 self.assertEqual(i + 1, curs.rownumber)410def test_suite():411 return unittest.TestLoader().loadTestsFromName(__name__)412if __name__ == "__main__":...

Full Screen

Full Screen

карта в прект2.py

Source:карта в прект2.py Github

copy

Full Screen

1import pygame2import sys3import os4import requests5import math6import district7import webbrowser8class MapParams(object):9 def __init__(self):10 self.lat = 59.96527811 self.lon = 30.21349212 self.zoom = 913 self.type = "map"14 def coords(self):15 return str(self.lon) + "," + str(self.lat)16 def update(self, event):17 my_step = 0.01018 if event.key == 280 and self.zoom < 19:19 self.zoom += 120 elif event.key == 281 and self.zoom > 2:21 self.zoom -= 122 elif event.key == 276:23 self.lon -= my_step * math.pow(2, 15 - self.zoom)24 elif event.key == 275:25 self.lon += my_step * math.pow(2, 15 - self.zoom)26 elif event.key == 273 and self.lat < 85:27 self.lat += my_step * math.pow(2, 15 - self.zoom)28 elif event.key == 274 and self.lat > -85:29 self.lat -= my_step * math.pow(2, 15 - self.zoom)30def load_map(mp):31 map_request = "http://static-maps.yandex.ru/1.x/?ll={ll}&z={z}&l={type}".format(ll=mp.coords(), z=mp.zoom,32 type=mp.type)33 response = requests.get(map_request)34 if not response:35 print("Ошибка выполнения запроса:")36 print(map_request)37 print("Http статус:", response.status_code, "(", response.reason, ")")38 sys.exit(1)39 map_file = "map.png"40 try:41 with open(map_file, "wb") as file:42 file.write(response.content)43 except IOError as ex:44 print("Ошибка записи файла:", ex)45 sys.exit(2)46 return map_file47def main():48 initialized = False49 screen = None50 mp = MapParams()51 map_file = load_map(mp)52 markers_list = []53 def init_pygame():54 nonlocal initialized55 nonlocal screen56 nonlocal map_file57 pygame.init()58 screen = pygame.display.set_mode((600, 450))59 map_file = load_map(mp)60 markers_list.clear()61 initialized = True62 def finalize(district_caption=None, district_name=None, *, map_file):63 nonlocal initialized64 pygame.quit()65 os.remove(map_file)66 webbrowser.open('http://localhost:5000') # FIXME: this only works due to natural delay when opening the page67 if district_caption and district_name:68 district.main(district_caption, district_name)69 initialized = False70 while True:71 if not initialized:72 init_pygame()73 pygame.display.set_caption('Выберите район')74 event = pygame.event.wait()75 cursor = pygame.mouse.get_pos()76 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:77 print('you clicked {}'.format(cursor))78 markers_list.append(cursor)79 if 225 < cursor[0] and cursor[0] < 420 and 188 < cursor[1] and cursor[1] < 340:80 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:81 finalize('невский район Санкт-Петербурга', 'neva', map_file=map_file)82 if 67 < cursor[0] and cursor[0] < 194 and 145 < cursor[1] and cursor[1] < 227:83 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:84 finalize('кронштадтский район Санкт-Петербурга', 'kronshtadt', map_file=map_file)85 if 70 < cursor[0] and cursor[0] < 169 and 232 < cursor[1] and cursor[1] < 322:86 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:87 finalize('ломоносовский район Санкт-Петербурга', 'lomonosov', map_file=map_file)88 if 169 < cursor[0] and cursor[0] < 226 and 248 < cursor[1] and cursor[1] < 356:89 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:90 finalize('петродворцовый район Санкт-Петербурга', 'petrodvorets', map_file=map_file)91 if 226 < cursor[0] and cursor[0] < 311 and 337 < cursor[1] and cursor[1] < 448:92 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:93 finalize('красносельский район Санкт-Петербурга', 'krasn', map_file=map_file)94 if 312 < cursor[0] and cursor[0] < 411 and 341 < cursor[1] and cursor[1] < 448:95 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:96 finalize('пушкинский район Санкт-Петербурга', 'pushkin', map_file=map_file)97 if 417 < cursor[0] and cursor[0] < 565 and 322 < cursor[1] and cursor[1] < 448:98 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:99 finalize('колпинский район Санкт-Петербурга', 'kolpino', map_file=map_file)100 if 192 < cursor[0] and cursor[0] < 394 and 146 < cursor[1] and cursor[1] < 184:101 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:102 finalize('приморский район Санкт-Петербурга', 'prim', map_file=map_file)103 if 1 < cursor[0] and cursor[0] < 66 and 223 < cursor[1] and cursor[1] < 312:104 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:105 finalize('кингисеппский район Санкт-Петербурга', 'kingisep', map_file=map_file)106 if 1 < cursor[0] and cursor[0] < 166 and 312 < cursor[1] and cursor[1] < 448:107 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:108 finalize('волосовский район Санкт-Петербурга', 'volosovo', map_file=map_file)109 if 263 < cursor[0] and cursor[0] < 416 and 1 < cursor[1] and cursor[1] < 140:110 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:111 finalize('выборгский район Санкт-Петербурга', 'viborg', map_file=map_file)112 if 1 < cursor[0] and cursor[0] < 262 and 1 < cursor[1] and cursor[1] < 145:113 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:114 finalize('курортный район Санкт-Петербурга', 'kurort', map_file=map_file)115 if 416 < cursor[0] and cursor[0] < 494 and 1 < cursor[1] and cursor[1] < 188:116 if event.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]:117 finalize('калининский район Санкт-Петербурга', 'kalin', map_file=map_file)118 elif event.type == pygame.QUIT:119 break120 elif event.type == pygame.KEYUP:121 mp.update(event)122 if initialized:123 image = pygame.image.load(map_file)124 screen.blit(image, (0, 0))125 for m in markers_list:126 pygame.draw.circle(screen, (0, 0, 255), m, 3, 1)127 pygame.display.flip()128 finalize(map_file=map_file)129if __name__ == "__main__":...

Full Screen

Full Screen

db.py

Source:db.py Github

copy

Full Screen

...11 password=self.pswrd,12 db=self.dbnme,13 cursorclass=pymysql.cursors.DictCursor)14 def con_auth(self, mobile, user_pass):15 with self.connection.cursor() as cursor:16 com = "SELECT * FROM users WHERE userid='"+mobile+"'"17 cursor.execute(com)18 check = cursor.fetchone()19 self.connection.commit()20 try:21 userpass = check["password"]22 if genpass.check_password_hash(userpass, user_pass):23 return check24 except:25 return None26 def register_user(self, mobile, user_pass, username):27 with self.connection.cursor() as cursor:28 hash_pass = genpass.User(mobile, user_pass)29 hash_pass = hash_pass.pw_hash30 com = "INSERT INTO users VALUES ('"+mobile+"', '"+hash_pass+"', '"+username+"', 'user')"31 cursor.execute(com)32 check = cursor.fetchone()33 self.connection.commit()34 def getUserPassword(self, mobile):35 with self.connection.cursor() as cursor:36 com = "SELECT * FROM u"+mobile+""37 cursor.execute(com)38 check = cursor.fetchall()39 self.connection.commit()40 return check41 def createUserDB(self, mobile):42 with self.connection.cursor() as cursor:43 com = """CREATE TABLE u"""+mobile+"""44 (website char(50) NOT NULL,45 username char(50) NOT NULL,46 userpass char(250) NOT NULL);"""47 cursor.execute(com)48 49 def createTeamDB(self, team):50 with self.connection.cursor() as cursor:51 com = """CREATE TABLE t_"""+team+"""52 (website char(50) NOT NULL,53 username char(50) NOT NULL,54 userpass char(250) NOT NULL);"""55 cursor.execute(com)56 def addUserPassword(self, website, userID, userPass, mobile):57 with self.connection.cursor() as cursor:58 com = "INSERT into u"+mobile+" VALUES('"+website+"', '"+userID+"', '"+userPass+"')"59 cursor.execute(com)60 self.connection.commit()61 def checkUser(self, userid):62 with self.connection.cursor() as cursor:63 com = "SELECT * FROM users WHERE userid='"+userid+"'"64 cursor.execute(com)65 check = cursor.fetchone()66 self.connection.commit()67 return check68 def checkTeam(self, teamid):69 with self.connection.cursor() as cursor:70 com = "SELECT * FROM teams WHERE teamName='"+teamid+"'"71 cursor.execute(com)72 check = cursor.fetchone()73 self.connection.commit()74 return check75 def addToTeam(self, team, user, userType):76 with self.connection.cursor() as cursor:77 com = "INSERT into teams VALUES('"+team+"', '"+user+"', '"+userType+"')"78 cursor.execute(com)79 self.connection.commit()80 def checkUserTeams(self, userid):81 with self.connection.cursor() as cursor:82 com = "SELECT * from teams WHERE userid='"+userid+"'"83 cursor.execute(com)84 check = cursor.fetchall()85 return check86 def checkTeamAccess(self, userid, teamName):87 with self.connection.cursor() as cursor:88 com = "SELECT * from teams WHERE userid='"+userid+"' and teamName='"+teamName+"'"89 cursor.execute(com)90 check = cursor.fetchone()91 return check92 def getTeamPassword(self, team):93 with self.connection.cursor() as cursor:94 com = "SELECT * FROM t_"+team+""95 cursor.execute(com)96 check = cursor.fetchall()97 self.connection.commit()98 return check99 def removeTeam(self, teamName):100 with self.connection.cursor() as cursor:101 com = "DELETE from teams WHERE teamName='"+teamName+"'"102 cursor.execute(com)103 self.connection.commit() 104 def deleteTeam(self, teamName):105 with self.connection.cursor() as cursor:106 com = "DROP table t_"+teamName107 cursor.execute(com)108 self.connection.commit()109 self.removeTeam(teamName)110 def retrievePassword(self, mobile, website, username):111 with self.connection.cursor() as cursor:112 com = "SELECT userpass from u"+mobile+" WHERE website='"+website+"' and username='"+username+"'"113 cursor.execute(com)114 checkPass = cursor.fetchone()115 return checkPass116 def addTeamPassword(self, team, website, username, password):117 with self.connection.cursor() as cursor:118 com = "INSERT into t_"+team+" VALUES('"+website+"', '"+username+"', '"+password+"')"119 cursor.execute(com)120 self.connection.commit()121 def retrieveTeamPassword(self, team, website, username):122 with self.connection.cursor() as cursor:123 com = "SELECT userpass from t_"+team+" WHERE website='"+website+"' and username='"+username+"'"124 cursor.execute(com)125 checkPass = cursor.fetchone()126 return checkPass127 def deleteTeamPass(self, teamName, website, username):128 with self.connection.cursor() as cursor:129 com = "DELETE from t_"+teamName+" WHERE website='"+website+"' and username='"+username+"'"130 cursor.execute(com)131 self.connection.commit()132 def deleteUserPass(self, mobile, website, username):133 with self.connection.cursor() as cursor:134 com = "DELETE from u"+mobile+" WHERE website='"+website+"' and username='"+username+"'"135 cursor.execute(com)...

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