-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_api_test.py
More file actions
48 lines (32 loc) · 1.08 KB
/
demo_api_test.py
File metadata and controls
48 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sqlite3, os
from dotenv import load_dotenv
from playwright.sync_api import Playwright, expect
load_dotenv()
API_KEY = os.getenv("API_KEY")
def test_api_get_req(playwright: Playwright):
api_request_context = playwright.request.new_context(
base_url="https://api.openweathermap.org"
)
# yield api_request_context
response = api_request_context.get("/data/2.5/weather",
params={
"q": "London",
"appid": API_KEY,
"units": "metric"
}
)
assert response.ok
data = response.json()
# assert data["name"] == "London"
# assert isinstance(data["main"]["temp"], (int, float))
temp = data["main"]["temp"]
city = data["name"]
db_path = os.path.join(os.getcwd(), "Database", "demo.db")
conn = sqlite3.connect(db_path)
curr = conn.cursor()
curr.execute("CREATE TABLE IF NOT EXISTS weather_info (city TEXT, temp REAL)")
curr.execute("INSERT INTO weather_info VALUES (?, ?)", (city, temp))
conn.commit()
conn.close()
# teardown
api_request_context.dispose()