How to use test_mydb method in pytest-django

Best Python code snippet using pytest-django_python

weather-upload.py

Source:weather-upload.py Github

copy

Full Screen

...26 data = response.json()27 return data28 except HTTPError as http_err:29 print(http_err)30def test_mydb(client, data, site):31 # Switch to the correct database32 client.switch_database('otherm')33 try:34 # Fields read from the file35 temp_c = round(data['properties']['temperature']['value'], 2)36 pres_kpa = round(data['properties']['barometricPressure']['value'], 2) / 100037 humi_per = round(data['properties']['relativeHumidity']['value'], 2)38 time = data['properties']['timestamp']39 print(f"temp_c: {temp_c}, pres_kpa: {pres_kpa}, humi_per: {humi_per}")40 formatted_data = [41 {42 "measurement": site,43 "fields": {44 "temperature_c": temp_c,45 "pressure_kpa": pres_kpa,46 "humidity_percent": humi_per,47 },48 "time": time49 }50 ]51 try:52 print(f"writing points to influx")53 client.write_points(formatted_data)54 print(f"write succeeded")55 except InfluxDBClientError as e:56 print(e)57 except:58 print("error")59def main():60 # File containing the station ids for the sites we would like to poll61 sites = pd.read_csv('./NWS_stations.csv', header=0)62 # Iterate through the stations and grab the JSON data63 for index, row in sites.iterrows():64 station_id = row['code']65 # Build the url for the request and then create the directory name66 nws_url = "https://api.weather.gov/stations/" + station_id + "/observations/latest?require_qc=true"67 # Get the data from the national weather service and write it to a file68 data = get_data(nws_url, "NWS", station_id)69 client = InfluxDBClient(host='influxdb', port=8086, username=os.environ.get('INFLUXDB_ADMIN_USER'), password=os.environ.get('INFLUXDB_ADMIN_PASSWORD'))70 test_mydb(client, data, station_id)71if __name__ == "__main__":72 main()...

Full Screen

Full Screen

learning(14)_SQL_PYTHON(3).py

Source:learning(14)_SQL_PYTHON(3).py Github

copy

Full Screen

1import cx_Oracle2def Create_Table():3 dsn = cx_Oracle.makedsn("localhost",1521,'xe')4 db = cx_Oracle.connect('SCOTT','TIGER',dsn)5 cur = db.cursor()6 sql_cmd = "CREATE TABLE Test_mydb(id number, name varchar2(20))"7 cur.execute(sql_cmd)8 db.close() # 디비 꺼준다.9def Select_all():10 dsn = cx_Oracle.makedsn("localhost", 1521, 'xe')11 db = cx_Oracle.connect('SCOTT', 'TIGER', dsn)12 cur = db.cursor()13 cur.execute("select * from Test_mydb")14 result = cur.fetchall()15 for row in result:16 print(str(row[0]) + " "+ row[1])17 cur.close()18 db.close()19def Insert_m():20 dsn = cx_Oracle.makedsn("localhost", 1521, 'xe')21 db = cx_Oracle.connect('SCOTT', 'TIGER', dsn)22 cur = db.cursor()23 cur.execute("insert into test_mydb values('1','python1')")24 cur.execute("insert into test_mydb values('2','python2')")25 cur.execute("insert into test_mydb values('3','python3')")26 cur.execute("insert into test_mydb values('4','python4')")27 db.commit()28 db.close()29if __name__ == '__main__':30 #Create_Table()31 Insert_m()...

Full Screen

Full Screen

learning(15)_SQL_PYTHON(4).py

Source:learning(15)_SQL_PYTHON(4).py Github

copy

Full Screen

1import cx_Oracle2class OraDb1:3 def __init__(self): # 연결4 self.dsn = cx_Oracle.makedsn("localhost", 1521, 'xe')5 self.db = cx_Oracle.connect('SCOTT', 'TIGER', self.dsn)6 self.cur = self.db.cursor()7 def Insert_m(self):8 self.cur.execute("insert into test_mydb values('1','python1')") #변수 찾아서 쓸것.9 self.db.commit()10 self.cur.close()11 self.db.close() #창이 닫을때까지 클로즈 안하기때문에 메소드마다 다 DB를 닫게 해준다.12 def Select_all(self):13 self.cur.execute("select * from Test_mydb")14 result = self.cur.fetchall()15 for row in result:16 print(str(row[0]) + " " + row[1])17 self.cur.close()18 self.db.close()19 def __del__(self): # 닫기20 pass21 #self.db.close()22if __name__ == '__main__':23 test = OraDb1()...

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 pytest-django 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