-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_example.py
43 lines (35 loc) · 1.31 KB
/
test_example.py
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
import json
import pytest
import random
from main import app
list_of_test_1 = ['Москва', 'Астрахань', 'Якутск', 'Мирный', 'Пулково', 'Кемерово']
data_to_post ={
'airport_name': 'Warsaw airport',
"city": "Warsaw",
'coordinates': '(52,123123, 67,1231245)'
}
data_to_fail_post = {}
def test_endpoint():
# Testing is connection successful
responce = app.test_client().get('/')
assert responce.status_code == 200
@pytest.mark.get_requests
def test_get_cli_by_loc():
response = app.test_client().get(f'/loc/{random.choice(list_of_test_1)}')
res = json.loads(response.data.decode('utf-8'))
assert response.status_code == 200
@pytest.mark.post_request
def test_post_db_insert():
response = app.test_client().post('/add-airport', json = data_to_post)
res = json.loads(response.data.decode('utf-8'))
assert response.status_code == 200
@pytest.mark.post_requests
def test_post_fail():
responce = app.test_client().post('/add-airport', json = data_to_fail_post)
res = json.loads(responce.data.decode('utf-8'))
assert responce.status_code == 400
@pytest.mark.get_incor_get
def test_incorrect_get():
responce = app.test_client().get('/loc/dssf')
res = json.loads(responce.data.decode('utf-8'))
assert responce.status_code == 200